Skip to content

Commit 7cca10f

Browse files
RustanLeinobdonlan
authored andcommitted
Bug fix, where a builder had copied one field twice and omitted the copy of another field.
1 parent aa7934a commit 7cca10f

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

src/main/java/com/amazonaws/encryptionsdk/model/DecryptionMaterialsRequest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public static final class Builder {
5454

5555
private Builder(DecryptionMaterialsRequest request) {
5656
this.algorithm = request.getAlgorithm();
57-
this.encryptedDataKeys = request.getEncryptedDataKeys();
57+
this.encryptionContext = request.getEncryptionContext();
5858
this.encryptedDataKeys = request.getEncryptedDataKeys();
5959
}
6060

src/test/java/com/amazonaws/encryptionsdk/AllTestsSuite.java

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.amazonaws.encryptionsdk.model.CipherBlockHeadersTest;
2323
import com.amazonaws.encryptionsdk.model.CipherFrameHeadersTest;
2424
import com.amazonaws.encryptionsdk.model.KeyBlobTest;
25+
import com.amazonaws.encryptionsdk.model.DecryptionMaterialsRequestTest;
2526
import com.amazonaws.encryptionsdk.multi.MultipleMasterKeyTest;
2627
import com.amazonaws.encryptionsdk.kms.KMSProviderBuilderMockTests;
2728

@@ -40,6 +41,7 @@
4041
CipherBlockHeadersTest.class,
4142
CipherFrameHeadersTest.class,
4243
KeyBlobTest.class,
44+
DecryptionMaterialsRequestTest.class,
4345
MultipleMasterKeyTest.class,
4446
AwsCryptoTest.class,
4547
CryptoInputStreamTest.class,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except
5+
* in compliance with the License. A copy of the License is located at
6+
*
7+
* http://aws.amazon.com/apache2.0
8+
*
9+
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11+
* specific language governing permissions and limitations under the License.
12+
*/
13+
14+
package com.amazonaws.encryptionsdk.model;
15+
16+
import static org.junit.Assert.assertEquals;
17+
18+
import java.util.HashMap;
19+
import java.util.Map;
20+
import java.util.List;
21+
import java.util.ArrayList;
22+
23+
import org.junit.Test;
24+
25+
import com.amazonaws.encryptionsdk.CryptoAlgorithm;
26+
import com.amazonaws.encryptionsdk.model.DecryptionMaterialsRequest;
27+
import com.amazonaws.encryptionsdk.model.KeyBlob;
28+
29+
public class DecryptionMaterialsRequestTest {
30+
@Test
31+
public void build() {
32+
CryptoAlgorithm alg = CryptoAlgorithm.ALG_AES_256_GCM_IV12_TAG16_HKDF_SHA256;
33+
Map<String, String> encryptionContext = new HashMap<String, String>(1);
34+
encryptionContext.put("DMR", "DecryptionMaterialsRequest Test");
35+
List<KeyBlob> kbs = new ArrayList<KeyBlob>();
36+
37+
DecryptionMaterialsRequest request0 = DecryptionMaterialsRequest.newBuilder()
38+
.setAlgorithm(alg)
39+
.setEncryptionContext(encryptionContext)
40+
.setEncryptedDataKeys(kbs)
41+
.build();
42+
43+
DecryptionMaterialsRequest request1 = request0.toBuilder().build();
44+
45+
assertEquals(request0.getAlgorithm(), request1.getAlgorithm());
46+
assertEquals(request0.getEncryptionContext().size(), request1.getEncryptionContext().size());
47+
assertEquals(request0.getEncryptedDataKeys().size(), request1.getEncryptedDataKeys().size());
48+
}
49+
}

0 commit comments

Comments
 (0)