1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package io.netty.handler.codec.quic;
18
19 import java.util.Arrays;
20
21
22
23
24 public final class SslSessionTicketKey {
25
26
27
28 public static final int NAME_SIZE = 16;
29
30
31
32 public static final int HMAC_KEY_SIZE = 16;
33
34
35
36 public static final int AES_KEY_SIZE = 16;
37
38
39
40 public static final int TICKET_KEY_SIZE = NAME_SIZE + HMAC_KEY_SIZE + AES_KEY_SIZE;
41
42
43 final byte[] name;
44 final byte[] hmacKey;
45 final byte[] aesKey;
46
47
48
49
50
51
52
53 public SslSessionTicketKey(byte[] name, byte[] hmacKey, byte[] aesKey) {
54 if (name == null || name.length != NAME_SIZE) {
55 throw new IllegalArgumentException("Length of name must be " + NAME_SIZE);
56 }
57 if (hmacKey == null || hmacKey.length != HMAC_KEY_SIZE) {
58 throw new IllegalArgumentException("Length of hmacKey must be " + HMAC_KEY_SIZE);
59 }
60 if (aesKey == null || aesKey.length != AES_KEY_SIZE) {
61 throw new IllegalArgumentException("Length of aesKey must be " + AES_KEY_SIZE);
62 }
63 this.name = name.clone();
64 this.hmacKey = hmacKey.clone();
65 this.aesKey = aesKey.clone();
66 }
67
68
69
70
71
72
73 public byte[] name() {
74 return name.clone();
75 }
76
77
78
79
80
81 public byte[] hmacKey() {
82 return hmacKey.clone();
83 }
84
85
86
87
88
89 public byte[] aesKey() {
90 return aesKey.clone();
91 }
92
93 @Override
94 public boolean equals(Object o) {
95 if (this == o) {
96 return true;
97 }
98 if (o == null || getClass() != o.getClass()) {
99 return false;
100 }
101
102 SslSessionTicketKey that = (SslSessionTicketKey) o;
103
104 if (!Arrays.equals(name, that.name)) {
105 return false;
106 }
107 if (!Arrays.equals(hmacKey, that.hmacKey)) {
108 return false;
109 }
110 return Arrays.equals(aesKey, that.aesKey);
111 }
112
113 @Override
114 public int hashCode() {
115 int result = Arrays.hashCode(name);
116 result = 31 * result + Arrays.hashCode(hmacKey);
117 result = 31 * result + Arrays.hashCode(aesKey);
118 return result;
119 }
120
121 @Override
122 public String toString() {
123 return "SessionTicketKey{" +
124 "name=" + Arrays.toString(name) +
125 ", hmacKey=" + Arrays.toString(hmacKey) +
126 ", aesKey=" + Arrays.toString(aesKey) +
127 '}';
128 }
129 }