Skip to content

Commit 8a00b2a

Browse files
Improve wording around need of SaveBehavior.CLOBBER
1 parent b5f7fe9 commit 8a00b2a

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
The **[Amazon DynamoDB][ddb] Client-side Encryption in Java** supports encryption and signing of your data when stored in Amazon DynamoDB.
44

55
A typical use of this library is when you are using [DynamoDBMapper][ddbmapper], where transparent protection of all objects serialized through the mapper can be enabled via configuring an [AttributeEncryptor][attrencryptor].
6-
**Please note that it is critically important that you use `SaveBehavior.CLOBBER` when using AttributeEncryptor.**
6+
7+
> Important: Use `SaveBehavior.CLOBBER` with `AttributeEncryptor`. If you do not do so you risk corrupting your signatures and encrypted data.
78
89
For more advanced use cases where tighter control over the encryption and signing process is necessary, the low-level [DynamoDBEncryptor][ddbencryptor] can be used directly.
910

@@ -75,7 +76,7 @@ To enable transparent encryption and signing, simply specify the necessary encry
7576
SecretKey cek = ...; // Content encrypting key
7677
SecretKey macKey = ...; // Signing key
7778
EncryptionMaterialsProvider provider = new SymmetricStaticProvider(cek, macKey);
78-
mapper = new DynamoDBMapper(client, DynamoDBMapperConfig.DEFAULT,
79+
mapper = new DynamoDBMapper(client, DynamoDBMapperConfig.builder().withSaveBehavior(SaveBehavior.CLOBBER).build(),
7980
new AttributeEncryptor(provider));
8081
Book book = new Book();
8182
book.setId(123);

examples/com/amazonaws/examples/AwsKmsEncryptedObject.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public static void encryptRecord(final String cmkArn, final String region) {
5252
// Encryptor creation
5353
final DynamoDBEncryptor encryptor = DynamoDBEncryptor.getInstance(cmp);
5454
// Mapper Creation
55-
// Please note the use of SaveBehavior.CLOBBER. Omitting this may result in data-corruption.
55+
// Please note the use of SaveBehavior.CLOBBER. Omitting this can result in data-corruption.
5656
DynamoDBMapperConfig mapperConfig = DynamoDBMapperConfig.builder().withSaveBehavior(SaveBehavior.CLOBBER).build();
5757
DynamoDBMapper mapper = new DynamoDBMapper(ddb, mapperConfig, new AttributeEncryptor(encryptor));
5858

src/main/java/com/amazonaws/services/dynamodbv2/datamodeling/AttributeEncryptor.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838

3939
/**
4040
* Encrypts all non-key fields prior to storing them in DynamoDB.
41-
* <em>It is critically important that this is only used with @{link SaveBehavior#CLOBBER}. Use of
42-
* any other @{code SaveBehavior} may result in data-corruption.</em>
41+
* <em>This must be used with @{link SaveBehavior#CLOBBER}. Use of
42+
* any other @{code SaveBehavior} can result in data-corruption.</em>
4343
*
4444
* @author Greg Rubin
4545
*/
@@ -66,12 +66,14 @@ public Map<String, AttributeValue> transform(final Parameters<?> parameters) {
6666
final ModelClassMetadata metadata = getModelClassMetadata(parameters);
6767

6868
final Map<String, AttributeValue> attributeValues = parameters.getAttributeValues();
69+
// If this class is marked as "DoNotTouch" then we know our encryptor will not change it at all
70+
// so we may as well fast-return and do nothing. This also avoids emitting errors when they would not apply.
6971
if (metadata.doNotTouch) {
7072
return attributeValues;
7173
}
7274

7375
if (parameters.isPartialUpdate()) {
74-
LOG.error("Use of AttributeEncryptor without SaveBehavior.CLOBBER is an error and may result in data-corruption. " +
76+
LOG.error("Use of AttributeEncryptor without SaveBehavior.CLOBBER is an error and can result in data-corruption. " +
7577
"This occured while trying to save " + parameters.getModelClass());
7678
}
7779

0 commit comments

Comments
 (0)