@@ -51,6 +51,8 @@ public class CiphertextHeadersTest {
51
51
52
52
@ Test
53
53
public void serializeDeserialize () {
54
+ int maxEncryptedDataKeys = 42 ;
55
+
54
56
Map <String , String > encryptionContext = new HashMap <String , String >(1 );
55
57
encryptionContext .put ("ENC" , "CiphertextHeader Test" );
56
58
@@ -59,10 +61,30 @@ public void serializeDeserialize() {
59
61
60
62
final byte [] headerBytes = ciphertextHeaders .toByteArray ();
61
63
final CiphertextHeaders reconstructedHeaders = new CiphertextHeaders ();
62
- reconstructedHeaders .deserialize (
63
- headerBytes , 0 , CiphertextHeaders .NO_MAX_ENCRYPTED_DATA_KEYS );
64
+ reconstructedHeaders .deserialize (headerBytes , 0 , maxEncryptedDataKeys );
65
+ final byte [] reconstructedHeaderBytes = reconstructedHeaders .toByteArray ();
66
+
67
+ assertEquals (reconstructedHeaders .getMaxEncryptedDataKeys (), maxEncryptedDataKeys );
68
+ assertArrayEquals (headerBytes , reconstructedHeaderBytes );
69
+ }
70
+ }
71
+
72
+ @ Test
73
+ public void serializeDeserializeDefaultMaxEncryptedDataKeys () {
74
+ Map <String , String > encryptionContext = new HashMap <String , String >(1 );
75
+ encryptionContext .put ("ENC" , "CiphertextHeader Test" );
76
+
77
+ for (CryptoAlgorithm alg : testAlgs ) {
78
+ final CiphertextHeaders ciphertextHeaders = createCiphertextHeaders (encryptionContext , alg );
79
+
80
+ final byte [] headerBytes = ciphertextHeaders .toByteArray ();
81
+ final CiphertextHeaders reconstructedHeaders = new CiphertextHeaders ();
82
+ reconstructedHeaders .deserialize (headerBytes , 0 );
64
83
final byte [] reconstructedHeaderBytes = reconstructedHeaders .toByteArray ();
65
84
85
+ assertEquals (
86
+ reconstructedHeaders .getMaxEncryptedDataKeys (),
87
+ CiphertextHeaders .NO_MAX_ENCRYPTED_DATA_KEYS );
66
88
assertArrayEquals (headerBytes , reconstructedHeaderBytes );
67
89
}
68
90
}
0 commit comments