Skip to content

Commit 674053d

Browse files
author
Anirav Kareddy
committed
Modified the ContentMetadataEncodingStrategy class to take into account MaterialsDescription (note: MaterialsDescription and Encryption Context are stored in the same field, but you will never have both at the same time (one of them will always be empty
1 parent cfe9e33 commit 674053d

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/main/java/software/amazon/encryption/s3/internal/ContentMetadataEncodingStrategy.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,16 @@ private Map<String, String> addMetadataToMap(Map<String, String> map, Encryption
8080

8181
try (JsonWriter jsonWriter = JsonWriter.create()) {
8282
jsonWriter.writeStartObject();
83-
for (Map.Entry<String, String> entry : materials.encryptionContext().entrySet()) {
84-
jsonWriter.writeFieldName(entry.getKey()).writeValue(entry.getValue());
83+
if (!materials.encryptionContext().isEmpty() && materials.materialsDescription().isEmpty()) {
84+
for (Map.Entry<String, String> entry : materials.encryptionContext().entrySet()) {
85+
jsonWriter.writeFieldName(entry.getKey()).writeValue(entry.getValue());
86+
}
87+
} else if (materials.encryptionContext().isEmpty() && !materials.materialsDescription().isEmpty()) {
88+
for (Map.Entry<String, String> entry : materials.materialsDescription().entrySet()) {
89+
jsonWriter.writeFieldName(entry.getKey()).writeValue(entry.getValue());
90+
}
8591
}
8692
jsonWriter.writeEndObject();
87-
8893
String jsonEncryptionContext = new String(jsonWriter.getBytes(), StandardCharsets.UTF_8);
8994
metadata.put(MetadataKeyConstants.ENCRYPTED_DATA_KEY_CONTEXT, jsonEncryptionContext);
9095
} catch (JsonWriter.JsonGenerationException e) {

0 commit comments

Comments
 (0)