Skip to content

Commit 20ed743

Browse files
author
Anirav Kareddy
committed
Created an abstract class with an abstract builder method that AES + RSA Keyrings will extend from and I also moved the warnIfEncryptionContextIsPresent() method from S3Keyring to RawKeyring since the method really only targets AES + RSA keyrings which will extend this class
1 parent 3bd8556 commit 20ed743

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
package software.amazon.encryption.s3.materials;
4+
5+
import org.apache.commons.logging.LogFactory;
6+
import software.amazon.encryption.s3.S3EncryptionClient;
7+
8+
public abstract class RawKeyring extends S3Keyring {
9+
protected final MaterialsDescription _materialsDescription;
10+
protected final boolean _reEncryptInstructionFile;
11+
12+
protected RawKeyring(Builder<?, ?> builder) {
13+
super(builder);
14+
_materialsDescription = builder._materialsDescription;
15+
_reEncryptInstructionFile = builder._reEncryptInstructionFile;
16+
}
17+
public MaterialsDescription materialsDescription() {
18+
return _materialsDescription;
19+
}
20+
public boolean reEncryptInstructionFile() {
21+
return _reEncryptInstructionFile;
22+
}
23+
public void warnIfEncryptionContextIsPresent(EncryptionMaterials materials) {
24+
materials.s3Request().overrideConfiguration()
25+
.flatMap(overrideConfiguration ->
26+
overrideConfiguration.executionAttributes()
27+
.getOptionalAttribute(S3EncryptionClient.ENCRYPTION_CONTEXT))
28+
.ifPresent(ctx -> LogFactory.getLog(getClass()).warn("Usage of Encryption Context provides no security benefit in " + getClass().getSimpleName()));
29+
30+
}
31+
public static abstract class Builder<KeyringT extends RawKeyring, BuilderT extends Builder<KeyringT, BuilderT>>
32+
extends S3Keyring.Builder<KeyringT, BuilderT> {
33+
34+
protected MaterialsDescription _materialsDescription;
35+
protected boolean _reEncryptInstructionFile = false;
36+
37+
protected Builder() {
38+
super();
39+
}
40+
41+
public BuilderT materialsDescription(MaterialsDescription materialsDescription) {
42+
_materialsDescription = materialsDescription;
43+
return builder();
44+
}
45+
46+
public BuilderT reEncryptInstructionFile(boolean reEncryptInstructionFile) {
47+
_reEncryptInstructionFile = reEncryptInstructionFile;
48+
return builder();
49+
}
50+
}
51+
}

0 commit comments

Comments
 (0)