|
29 | 29 | import java.nio.ByteBuffer; |
30 | 30 | import java.security.GeneralSecurityException; |
31 | 31 | import java.security.ProviderException; |
32 | | -import java.security.spec.AlgorithmParameterSpec; |
33 | 32 | import javax.crypto.KDF; |
34 | 33 | import javax.crypto.KeyGenerator; |
35 | 34 | import javax.crypto.SecretKey; |
36 | 35 | import javax.crypto.spec.HKDFParameterSpec; |
37 | 36 | import javax.crypto.spec.IvParameterSpec; |
38 | | -import javax.crypto.spec.SecretKeySpec; |
39 | 37 | import javax.net.ssl.SSLHandshakeException; |
40 | 38 | import sun.security.internal.spec.TlsKeyMaterialParameterSpec; |
41 | 39 | import sun.security.internal.spec.TlsKeyMaterialSpec; |
@@ -191,26 +189,26 @@ private static byte[] createHkdfInfo( |
191 | 189 |
|
192 | 190 | private enum KeySchedule { |
193 | 191 | // Note that we use enum name as the key name. |
194 | | - TlsKey ("key", false), |
195 | | - TlsIv ("iv", true), |
196 | | - TlsUpdateNplus1 ("traffic upd", false); |
| 192 | + TlsKey ("key"), |
| 193 | + TlsIv ("iv"), |
| 194 | + TlsUpdateNplus1 ("traffic upd"); |
197 | 195 |
|
198 | 196 | private final byte[] label; |
199 | | - private final boolean isIv; |
200 | 197 |
|
201 | | - KeySchedule(String label, boolean isIv) { |
| 198 | + KeySchedule(String label) { |
202 | 199 | this.label = ("tls13 " + label).getBytes(); |
203 | | - this.isIv = isIv; |
204 | 200 | } |
205 | 201 |
|
206 | 202 | int getKeyLength(CipherSuite cs) { |
207 | | - if (this == KeySchedule.TlsUpdateNplus1) |
208 | | - return cs.hashAlg.hashLength; |
209 | | - return isIv ? cs.bulkCipher.ivSize : cs.bulkCipher.keySize; |
| 203 | + return switch (this) { |
| 204 | + case TlsUpdateNplus1 -> cs.hashAlg.hashLength; |
| 205 | + case TlsIv -> cs.bulkCipher.ivSize; |
| 206 | + case TlsKey -> cs.bulkCipher.keySize; |
| 207 | + }; |
210 | 208 | } |
211 | 209 |
|
212 | 210 | String getAlgorithm(CipherSuite cs, String algorithm) { |
213 | | - return isIv ? algorithm : cs.bulkCipher.algorithm; |
| 211 | + return this == TlsKey ? cs.bulkCipher.algorithm : algorithm; |
214 | 212 | } |
215 | 213 | } |
216 | 214 |
|
|
0 commit comments