@@ -40,11 +40,11 @@ public PutObjectRequest encodeMetadata(
4040 PutObjectRequest request ) {
4141 Map <String ,String > metadata = new HashMap <>(request .metadata ());
4242 EncryptedDataKey edk = materials .encryptedDataKeys ().get (0 );
43- metadata .put (MetadataKey .ENCRYPTED_DATA_KEY_V2 , _encoder .encodeToString (edk .ciphertext ()));
44- metadata .put (MetadataKey .CONTENT_NONCE , _encoder .encodeToString (encryptedContent .nonce ));
45- metadata .put (MetadataKey .CONTENT_CIPHER , materials .algorithmSuite ().cipherName ());
46- metadata .put (MetadataKey .CONTENT_CIPHER_TAG_LENGTH , Integer .toString (materials .algorithmSuite ().cipherTagLengthBits ()));
47- metadata .put (MetadataKey .ENCRYPTED_DATA_KEY_ALGORITHM , new String (edk .keyProviderInfo (), StandardCharsets .UTF_8 ));
43+ metadata .put (MetadataKeyConstants .ENCRYPTED_DATA_KEY_V2 , _encoder .encodeToString (edk .ciphertext ()));
44+ metadata .put (MetadataKeyConstants .CONTENT_NONCE , _encoder .encodeToString (encryptedContent .nonce ));
45+ metadata .put (MetadataKeyConstants .CONTENT_CIPHER , materials .algorithmSuite ().cipherName ());
46+ metadata .put (MetadataKeyConstants .CONTENT_CIPHER_TAG_LENGTH , Integer .toString (materials .algorithmSuite ().cipherTagLengthBits ()));
47+ metadata .put (MetadataKeyConstants .ENCRYPTED_DATA_KEY_ALGORITHM , new String (edk .keyProviderInfo (), StandardCharsets .UTF_8 ));
4848
4949 try (JsonWriter jsonWriter = JsonWriter .create ()) {
5050 jsonWriter .writeStartObject ();
@@ -54,7 +54,7 @@ public PutObjectRequest encodeMetadata(
5454 jsonWriter .writeEndObject ();
5555
5656 String jsonEncryptionContext = new String (jsonWriter .getBytes (), StandardCharsets .UTF_8 );
57- metadata .put (MetadataKey .ENCRYPTED_DATA_KEY_CONTEXT , jsonEncryptionContext );
57+ metadata .put (MetadataKeyConstants .ENCRYPTED_DATA_KEY_CONTEXT , jsonEncryptionContext );
5858 } catch (JsonGenerationException e ) {
5959 throw new S3EncryptionClientException ("Cannot serialize encryption context to JSON." , e );
6060 }
@@ -67,7 +67,7 @@ public ContentMetadata decodeMetadata(GetObjectResponse response) {
6767 Map <String , String > metadata = response .metadata ();
6868
6969 // Get algorithm suite
70- final String contentEncryptionAlgorithm = metadata .get (MetadataKey .CONTENT_CIPHER );
70+ final String contentEncryptionAlgorithm = metadata .get (MetadataKeyConstants .CONTENT_CIPHER );
7171 AlgorithmSuite algorithmSuite ;
7272 if (contentEncryptionAlgorithm == null
7373 || contentEncryptionAlgorithm .equals (AlgorithmSuite .ALG_AES_256_CBC_IV16_NO_KDF .cipherName ())) {
@@ -89,24 +89,24 @@ public ContentMetadata decodeMetadata(GetObjectResponse response) {
8989 switch (algorithmSuite ) {
9090 case ALG_AES_256_CBC_IV16_NO_KDF :
9191 // Extract encrypted data key ciphertext
92- edkCiphertext = _decoder .decode (metadata .get (MetadataKey .ENCRYPTED_DATA_KEY_V1 ));
92+ edkCiphertext = _decoder .decode (metadata .get (MetadataKeyConstants .ENCRYPTED_DATA_KEY_V1 ));
9393
9494 // Hardcode the key provider id to match what V1 does
9595 keyProviderInfo = "AES" ;
9696
9797 break ;
9898 case ALG_AES_256_GCM_IV12_TAG16_NO_KDF :
9999 // Check tag length
100- final int tagLength = Integer .parseInt (metadata .get (MetadataKey .CONTENT_CIPHER_TAG_LENGTH ));
100+ final int tagLength = Integer .parseInt (metadata .get (MetadataKeyConstants .CONTENT_CIPHER_TAG_LENGTH ));
101101 if (tagLength != algorithmSuite .cipherTagLengthBits ()) {
102102 throw new S3EncryptionClientException ("Expected tag length (bits) of: "
103103 + algorithmSuite .cipherTagLengthBits ()
104104 + ", got: " + tagLength );
105105 }
106106
107107 // Extract encrypted data key ciphertext and provider id
108- edkCiphertext = _decoder .decode (metadata .get (MetadataKey .ENCRYPTED_DATA_KEY_V2 ));
109- keyProviderInfo = metadata .get (MetadataKey .ENCRYPTED_DATA_KEY_ALGORITHM );
108+ edkCiphertext = _decoder .decode (metadata .get (MetadataKeyConstants .ENCRYPTED_DATA_KEY_V2 ));
109+ keyProviderInfo = metadata .get (MetadataKeyConstants .ENCRYPTED_DATA_KEY_ALGORITHM );
110110
111111 break ;
112112 default :
@@ -123,7 +123,7 @@ public ContentMetadata decodeMetadata(GetObjectResponse response) {
123123
124124 // Get encrypted data key encryption context
125125 final Map <String , String > encryptionContext = new HashMap <>();
126- final String jsonEncryptionContext = metadata .get (MetadataKey .ENCRYPTED_DATA_KEY_CONTEXT );
126+ final String jsonEncryptionContext = metadata .get (MetadataKeyConstants .ENCRYPTED_DATA_KEY_CONTEXT );
127127 try {
128128 JsonNodeParser parser = JsonNodeParser .create ();
129129 JsonNode objectNode = parser .parse (jsonEncryptionContext );
@@ -136,7 +136,7 @@ public ContentMetadata decodeMetadata(GetObjectResponse response) {
136136 }
137137
138138 // Get content nonce
139- byte [] nonce = _decoder .decode (metadata .get (MetadataKey .CONTENT_NONCE ));
139+ byte [] nonce = _decoder .decode (metadata .get (MetadataKeyConstants .CONTENT_NONCE ));
140140
141141 return ContentMetadata .builder ()
142142 .algorithmSuite (algorithmSuite )
0 commit comments