@@ -45,31 +45,35 @@ public class DefaultCryptoMaterialsManagerTest {
45
45
private static final MasterKey <?> mk1 = new StaticMasterKey ("mk1" );
46
46
private static final MasterKey <?> mk2 = new StaticMasterKey ("mk2" );
47
47
private static final Keyring keyring1 = new StaticKeyring ("keyring1" );
48
- private static final Keyring keyring2 = new StaticKeyring ("keyring2" );
49
48
50
49
@ Test
51
- public void encrypt_testBasicFunctionality () {
50
+ public void encrypt_testBasicFunctionalityWithMkp () {
52
51
EncryptionMaterialsRequest req = EncryptionMaterialsRequest .newBuilder ().build ();
53
- EncryptionMaterials resultMkp = new DefaultCryptoMaterialsManager (mk1 ).getMaterialsForEncrypt (req );
54
- EncryptionMaterials resultKeyring = new DefaultCryptoMaterialsManager (keyring1 ).getMaterialsForEncrypt (req );
55
-
56
- assertNotNull (resultMkp .getAlgorithm ());
57
- assertNotNull (resultMkp .getCleartextDataKey ());
58
- assertNotNull (resultMkp .getEncryptionContext ());
59
- assertEquals (1 , resultMkp .getEncryptedDataKeys ().size ());
60
- assertEquals (1 , resultMkp .getMasterKeys ().size ());
61
- assertEquals (mk1 , resultMkp .getMasterKeys ().get (0 ));
62
-
63
- assertNotNull (resultKeyring .getAlgorithm ());
64
- assertNotNull (resultKeyring .getCleartextDataKey ());
65
- assertNotNull (resultKeyring .getEncryptionContext ());
66
- assertNotNull (resultKeyring .getKeyringTrace ());
67
- assertEquals (1 , resultKeyring .getEncryptedDataKeys ().size ());
68
- assertEquals (0 , resultKeyring .getMasterKeys ().size ());
52
+ EncryptionMaterials result = new DefaultCryptoMaterialsManager (mk1 ).getMaterialsForEncrypt (req );
53
+
54
+ assertNotNull (result .getAlgorithm ());
55
+ assertNotNull (result .getCleartextDataKey ());
56
+ assertNotNull (result .getEncryptionContext ());
57
+ assertEquals (1 , result .getEncryptedDataKeys ().size ());
58
+ assertEquals (1 , result .getMasterKeys ().size ());
59
+ assertEquals (mk1 , result .getMasterKeys ().get (0 ));
69
60
}
70
61
71
62
@ Test
72
- public void encrypt_noSignatureKeyOnUnsignedAlgo () throws Exception {
63
+ public void encrypt_testBasicFunctionalityWithKeyring () {
64
+ EncryptionMaterialsRequest req = EncryptionMaterialsRequest .newBuilder ().build ();
65
+ EncryptionMaterials result = new DefaultCryptoMaterialsManager (keyring1 ).getMaterialsForEncrypt (req );
66
+
67
+ assertNotNull (result .getAlgorithm ());
68
+ assertNotNull (result .getCleartextDataKey ());
69
+ assertNotNull (result .getEncryptionContext ());
70
+ assertNotNull (result .getKeyringTrace ());
71
+ assertEquals (1 , result .getEncryptedDataKeys ().size ());
72
+ assertEquals (0 , result .getMasterKeys ().size ());
73
+ }
74
+
75
+ @ Test
76
+ public void encrypt_noSignatureKeyOnUnsignedAlgoWithMkp () throws Exception {
73
77
CryptoAlgorithm [] algorithms = new CryptoAlgorithm [] {
74
78
CryptoAlgorithm .ALG_AES_128_GCM_IV12_TAG16_HKDF_SHA256 ,
75
79
CryptoAlgorithm .ALG_AES_128_GCM_IV12_TAG16_NO_KDF ,
@@ -82,21 +86,38 @@ public void encrypt_noSignatureKeyOnUnsignedAlgo() throws Exception {
82
86
for (CryptoAlgorithm algo : algorithms ) {
83
87
EncryptionMaterialsRequest req
84
88
= EncryptionMaterialsRequest .newBuilder ().setRequestedAlgorithm (algo ).build ();
85
- EncryptionMaterials mkpResult = new DefaultCryptoMaterialsManager (mk1 ).getMaterialsForEncrypt (req );
86
- EncryptionMaterials keyringResult = new DefaultCryptoMaterialsManager (keyring1 ).getMaterialsForEncrypt (req );
89
+ EncryptionMaterials result = new DefaultCryptoMaterialsManager (mk1 ).getMaterialsForEncrypt (req );
90
+
91
+ assertNull (result .getTrailingSignatureKey ());
92
+ assertEquals (0 , result .getEncryptionContext ().size ());
93
+ assertEquals (algo , result .getAlgorithm ());
94
+ }
95
+ }
96
+
97
+ @ Test
98
+ public void encrypt_noSignatureKeyOnUnsignedAlgoWithKeyring () throws Exception {
99
+ CryptoAlgorithm [] algorithms = new CryptoAlgorithm [] {
100
+ CryptoAlgorithm .ALG_AES_128_GCM_IV12_TAG16_HKDF_SHA256 ,
101
+ CryptoAlgorithm .ALG_AES_128_GCM_IV12_TAG16_NO_KDF ,
102
+ CryptoAlgorithm .ALG_AES_192_GCM_IV12_TAG16_HKDF_SHA256 ,
103
+ CryptoAlgorithm .ALG_AES_192_GCM_IV12_TAG16_NO_KDF ,
104
+ CryptoAlgorithm .ALG_AES_256_GCM_IV12_TAG16_HKDF_SHA256 ,
105
+ CryptoAlgorithm .ALG_AES_256_GCM_IV12_TAG16_NO_KDF
106
+ };
87
107
88
- assertNull (mkpResult .getTrailingSignatureKey ());
89
- assertEquals (0 , mkpResult .getEncryptionContext ().size ());
90
- assertEquals (algo , mkpResult .getAlgorithm ());
108
+ for (CryptoAlgorithm algo : algorithms ) {
109
+ EncryptionMaterialsRequest req
110
+ = EncryptionMaterialsRequest .newBuilder ().setRequestedAlgorithm (algo ).build ();
111
+ EncryptionMaterials result = new DefaultCryptoMaterialsManager (keyring1 ).getMaterialsForEncrypt (req );
91
112
92
- assertNull (keyringResult .getTrailingSignatureKey ());
93
- assertEquals (0 , keyringResult .getEncryptionContext ().size ());
94
- assertEquals (algo , keyringResult .getAlgorithm ());
113
+ assertNull (result .getTrailingSignatureKey ());
114
+ assertEquals (0 , result .getEncryptionContext ().size ());
115
+ assertEquals (algo , result .getAlgorithm ());
95
116
}
96
117
}
97
118
98
119
@ Test
99
- public void encrypt_hasSignatureKeyForSignedAlgo () throws Exception {
120
+ public void encrypt_hasSignatureKeyForSignedAlgoWithMkp () throws Exception {
100
121
CryptoAlgorithm [] algorithms = new CryptoAlgorithm [] {
101
122
CryptoAlgorithm .ALG_AES_128_GCM_IV12_TAG16_HKDF_SHA256_ECDSA_P256 ,
102
123
CryptoAlgorithm .ALG_AES_192_GCM_IV12_TAG16_HKDF_SHA384_ECDSA_P384 ,
@@ -107,19 +128,34 @@ public void encrypt_hasSignatureKeyForSignedAlgo() throws Exception {
107
128
108
129
EncryptionMaterialsRequest req
109
130
= EncryptionMaterialsRequest .newBuilder ().setRequestedAlgorithm (algo ).build ();
110
- EncryptionMaterials mkpResult = new DefaultCryptoMaterialsManager (mk1 ).getMaterialsForEncrypt (req );
111
- EncryptionMaterials keyringResult = new DefaultCryptoMaterialsManager (keyring1 ).getMaterialsForEncrypt (req );
131
+ EncryptionMaterials result = new DefaultCryptoMaterialsManager (mk1 ).getMaterialsForEncrypt (req );
112
132
113
133
114
- assertNotNull (mkpResult .getTrailingSignatureKey ());
115
- assertEquals (1 , mkpResult .getEncryptionContext ().size ());
116
- assertNotNull (mkpResult .getEncryptionContext ().get (Constants .EC_PUBLIC_KEY_FIELD ));
117
- assertEquals (algo , mkpResult .getAlgorithm ());
134
+ assertNotNull (result .getTrailingSignatureKey ());
135
+ assertEquals (1 , result .getEncryptionContext ().size ());
136
+ assertNotNull (result .getEncryptionContext ().get (Constants .EC_PUBLIC_KEY_FIELD ));
137
+ assertEquals (algo , result .getAlgorithm ());
138
+ }
139
+ }
140
+
141
+ @ Test
142
+ public void encrypt_hasSignatureKeyForSignedAlgoWithKeyring () throws Exception {
143
+ CryptoAlgorithm [] algorithms = new CryptoAlgorithm [] {
144
+ CryptoAlgorithm .ALG_AES_128_GCM_IV12_TAG16_HKDF_SHA256_ECDSA_P256 ,
145
+ CryptoAlgorithm .ALG_AES_192_GCM_IV12_TAG16_HKDF_SHA384_ECDSA_P384 ,
146
+ CryptoAlgorithm .ALG_AES_256_GCM_IV12_TAG16_HKDF_SHA384_ECDSA_P384
147
+ };
148
+
149
+ for (CryptoAlgorithm algo : algorithms ) {
150
+
151
+ EncryptionMaterialsRequest req
152
+ = EncryptionMaterialsRequest .newBuilder ().setRequestedAlgorithm (algo ).build ();
153
+ EncryptionMaterials result = new DefaultCryptoMaterialsManager (keyring1 ).getMaterialsForEncrypt (req );
118
154
119
- assertNotNull (keyringResult .getTrailingSignatureKey ());
120
- assertEquals (1 , keyringResult .getEncryptionContext ().size ());
121
- assertNotNull (keyringResult .getEncryptionContext ().get (Constants .EC_PUBLIC_KEY_FIELD ));
122
- assertEquals (algo , keyringResult .getAlgorithm ());
155
+ assertNotNull (result .getTrailingSignatureKey ());
156
+ assertEquals (1 , result .getEncryptionContext ().size ());
157
+ assertNotNull (result .getEncryptionContext ().get (Constants .EC_PUBLIC_KEY_FIELD ));
158
+ assertEquals (algo , result .getAlgorithm ());
123
159
}
124
160
}
125
161
0 commit comments