2
2
// SPDX-License-Identifier: Apache-2.0
3
3
package software .amazon .encryption .s3 .internal ;
4
4
5
- import software .amazon .awssdk .core .ResponseBytes ;
5
+ import software .amazon .awssdk .core .ResponseInputStream ;
6
6
import software .amazon .awssdk .core .async .AsyncResponseTransformer ;
7
7
import software .amazon .awssdk .protocols .jsoncore .JsonNode ;
8
8
import software .amazon .awssdk .protocols .jsoncore .JsonNodeParser ;
18
18
import software .amazon .encryption .s3 .materials .EncryptionMaterials ;
19
19
import software .amazon .encryption .s3 .materials .S3Keyring ;
20
20
21
+ import java .io .IOException ;
21
22
import java .nio .charset .StandardCharsets ;
22
23
import java .util .Base64 ;
23
24
import java .util .HashMap ;
@@ -40,38 +41,22 @@ public ContentMetadata decodeMetadata(GetObjectRequest getObjectRequest, GetObje
40
41
.key (getObjectRequest .key () + INSTRUCTION_FILE_SUFFIX )
41
42
.build ();
42
43
43
- try (ResponseInputStream <GetObjectResponse > instruction = s3AsyncClient .getObject (instructionGetObjectRequest , AsyncResponseTransformer .toBlockingInputStream ()).join ()){
44
- Map <String , String > metadata = new HashMap <>();
45
- JsonNodeParser parser = JsonNodeParser .create ();
46
- JsonNode objectNode = parser .parse (instruction );
47
- for (Map .Entry <String , JsonNode > entry : objectNode .asObject ().entrySet ()) {
48
- metadata .put (entry .getKey (), entry .getValue ().asString ());
49
- }
50
- return ContentMetadataStrategy .readFromMap (metadata , response );
51
- } catch (IOException ioException ) {
52
- throw new S3EncryptionClientException ("IOException while reading instruction file!" , ioException );
53
- } catch (NoSuchKeyException exception ) {
54
- // Most likely, the customer is attempting to decrypt an object
55
- // which is not encrypted with the S3 EC.
56
- throw new S3EncryptionClientException ("Instruction file not found! Please ensure the object you are" +
57
- " attempting to decrypt has been encrypted using the S3 Encryption Client." , exception );
58
- }
59
- try {
60
- instruction = s3AsyncClient .getObject (instructionGetObjectRequest , AsyncResponseTransformer .toBytes ()).join ();
44
+ try (ResponseInputStream <GetObjectResponse > instruction = s3AsyncClient .getObject (instructionGetObjectRequest , AsyncResponseTransformer .toBlockingInputStream ()).join ()){
45
+ Map <String , String > metadata = new HashMap <>();
46
+ JsonNodeParser parser = JsonNodeParser .create ();
47
+ JsonNode objectNode = parser .parse (instruction );
48
+ for (Map .Entry <String , JsonNode > entry : objectNode .asObject ().entrySet ()) {
49
+ metadata .put (entry .getKey (), entry .getValue ().asString ());
50
+ }
51
+ return ContentMetadataStrategy .readFromMap (metadata , response );
52
+ } catch (IOException ioException ) {
53
+ throw new S3EncryptionClientException ("IOException while reading instruction file!" , ioException );
61
54
} catch (NoSuchKeyException exception ) {
62
55
// Most likely, the customer is attempting to decrypt an object
63
56
// which is not encrypted with the S3 EC.
64
57
throw new S3EncryptionClientException ("Instruction file not found! Please ensure the object you are" +
65
- " attempting to decrypt has been encrypted using the S3 Encryption Client." , exception );
66
- }
67
-
68
- Map <String , String > metadata = new HashMap <>();
69
- JsonNodeParser parser = JsonNodeParser .create ();
70
- JsonNode objectNode = parser .parse (instruction .asByteArray ());
71
- for (Map .Entry <String , JsonNode > entry : objectNode .asObject ().entrySet ()) {
72
- metadata .put (entry .getKey (), entry .getValue ().asString ());
58
+ " attempting to decrypt has been encrypted using the S3 Encryption Client." , exception );
73
59
}
74
- return ContentMetadataStrategy .readFromMap (metadata , response );
75
60
}
76
61
};
77
62
0 commit comments