Skip to content

Commit c28188e

Browse files
committed
Use constants for extracting object metadata
1 parent 90fbdbd commit c28188e

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/main/java/software/amazon/encryption/s3/S3EncryptionClient.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import software.amazon.awssdk.services.s3.model.PutObjectResponse;
3333
import software.amazon.awssdk.utils.IoUtils;
3434
import software.amazon.encryption.s3.algorithms.AlgorithmSuite;
35+
import software.amazon.encryption.s3.internal.MetadataKey;
3536
import software.amazon.encryption.s3.internal.PutEncryptedObjectPipeline;
3637
import software.amazon.encryption.s3.materials.DecryptMaterialsRequest;
3738
import software.amazon.encryption.s3.materials.DecryptionMaterials;
@@ -81,8 +82,8 @@ public <T> T getObject(GetObjectRequest getObjectRequest,
8182

8283
// Build encrypted data key
8384
Base64.Decoder decoder = Base64.getDecoder();
84-
byte[] edkCiphertext = decoder.decode(metadata.get("x-amz-key-v2"));
85-
String keyProviderId = metadata.get("x-amz-wrap-alg");
85+
byte[] edkCiphertext = decoder.decode(metadata.get(MetadataKey.ENCRYPTED_DATA_KEY));
86+
String keyProviderId = metadata.get(MetadataKey.ENCRYPTED_DATA_KEY_ALGORITHM);
8687
EncryptedDataKey edk = EncryptedDataKey.builder()
8788
.ciphertext(edkCiphertext)
8889
.keyProviderId(keyProviderId)
@@ -91,7 +92,7 @@ public <T> T getObject(GetObjectRequest getObjectRequest,
9192

9293
// Get encryption context
9394
final Map<String, String> encryptionContext = new HashMap<>();
94-
final String jsonEncryptionContext = metadata.get("x-amz-matdesc");
95+
final String jsonEncryptionContext = metadata.get(MetadataKey.ENCRYPTED_DATA_KEY_CONTEXT);
9596
try {
9697
JsonNodeParser parser = JsonNodeParser.create();
9798
JsonNode objectNode = parser.parse(jsonEncryptionContext);
@@ -104,7 +105,7 @@ public <T> T getObject(GetObjectRequest getObjectRequest,
104105
}
105106

106107
// Get decryption materials
107-
final String contentEncryptionAlgorithm = metadata.get("x-amz-cek-alg");
108+
final String contentEncryptionAlgorithm = metadata.get(MetadataKey.CONTENT_CIPHER);
108109
AlgorithmSuite algorithmSuite = null;
109110
if (contentEncryptionAlgorithm.equals("AES/GCM/NoPadding")) {
110111
algorithmSuite = AlgorithmSuite.ALG_AES_256_GCM_IV12_TAG16_NO_KDF;
@@ -124,8 +125,8 @@ public <T> T getObject(GetObjectRequest getObjectRequest,
124125

125126
// Get content encryption information
126127
SecretKey contentKey = new SecretKeySpec(materials.plaintextDataKey(), "AES");
127-
final int tagLength = Integer.parseInt(metadata.get("x-amz-tag-len"));
128-
byte[] iv = decoder.decode(metadata.get("x-amz-iv"));
128+
final int tagLength = Integer.parseInt(metadata.get(MetadataKey.CONTENT_CIPHER_TAG_LENGTH));
129+
byte[] iv = decoder.decode(metadata.get(MetadataKey.CONTENT_NONCE));
129130
final Cipher cipher;
130131
byte[] plaintext;
131132
try {

0 commit comments

Comments
 (0)