Skip to content

Commit 3af73f0

Browse files
Rename KmsKeying and related classes to AwsKmsKeyring
1 parent 623f6f5 commit 3af73f0

15 files changed

+87
-87
lines changed

src/examples/java/com/amazonaws/crypto/examples/BasicEncryptionExample.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import com.amazonaws.encryptionsdk.EncryptRequest;
2525
import com.amazonaws.encryptionsdk.keyrings.Keyring;
2626
import com.amazonaws.encryptionsdk.keyrings.StandardKeyrings;
27-
import com.amazonaws.encryptionsdk.kms.KmsClientSupplier;
27+
import com.amazonaws.encryptionsdk.kms.AwsKmsClientSupplier;
2828

2929
import static java.util.Collections.emptyList;
3030

@@ -53,15 +53,15 @@ static void encryptAndDecrypt(final String keyArn) {
5353
// 1. Instantiate the SDK
5454
final AwsCrypto crypto = new AwsCrypto();
5555

56-
// 2. Instantiate a KMS Client Supplier. This example uses the default client supplier but you can
56+
// 2. Instantiate an AWS KMS Client Supplier. This example uses the default client supplier but you can
5757
// also configure the credentials provider, client configuration and other settings as necessary
58-
final KmsClientSupplier clientSupplier = KmsClientSupplier.builder().build();
58+
final AwsKmsClientSupplier clientSupplier = AwsKmsClientSupplier.builder().build();
5959

60-
// 3. Instantiate a KMS Keyring, supplying the key ARN as the generator for generating a data key. While using
61-
// a key ARN is a best practice, for encryption operations it is also acceptable to use a CMK alias or an
62-
// alias ARN. For this example, empty lists are provided for grant tokens and additional keys to encrypt
60+
// 3. Instantiate an AWS KMS Keyring, supplying the key ARN as the generator for generating a data key. While
61+
// using a key ARN is a best practice, for encryption operations it is also acceptable to use a CMK alias or
62+
// an alias ARN. For this example, empty lists are provided for grant tokens and additional keys to encrypt
6363
// the data key with, but those can be supplied as necessary.
64-
final Keyring keyring = StandardKeyrings.kms(clientSupplier, emptyList(), emptyList(), keyArn);
64+
final Keyring keyring = StandardKeyrings.awsKms(clientSupplier, emptyList(), emptyList(), keyArn);
6565

6666
// 4. Create an encryption context
6767
//

src/examples/java/com/amazonaws/crypto/examples/EscrowedEncryptExample.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import com.amazonaws.encryptionsdk.EncryptRequest;
1919
import com.amazonaws.encryptionsdk.keyrings.Keyring;
2020
import com.amazonaws.encryptionsdk.keyrings.StandardKeyrings;
21-
import com.amazonaws.encryptionsdk.kms.KmsClientSupplier;
21+
import com.amazonaws.encryptionsdk.kms.AwsKmsClientSupplier;
2222

2323
import java.nio.charset.StandardCharsets;
2424
import java.security.GeneralSecurityException;
@@ -88,16 +88,16 @@ private static byte[] standardEncrypt(final String kmsArn, final PublicKey publi
8888
// 1. Instantiate the SDK
8989
final AwsCrypto crypto = new AwsCrypto();
9090

91-
// 2. Instantiate a KMS Client Supplier. This example uses the default client supplier but you can
91+
// 2. Instantiate an AWS KMS Client Supplier. This example uses the default client supplier but you can
9292
// also configure the credentials provider, client configuration and other settings as necessary
93-
final KmsClientSupplier clientSupplier = KmsClientSupplier.builder().build();
93+
final AwsKmsClientSupplier clientSupplier = AwsKmsClientSupplier.builder().build();
9494

95-
// 3. Instantiate a KMS Keyring, supplying the keyArn as the generator for generating a data key.
95+
// 3. Instantiate an AWS KMS Keyring, supplying the keyArn as the generator for generating a data key.
9696
// For this example, empty lists are provided for grant tokens and additional keys to encrypt the data
9797
// key with, but those can be supplied as necessary.
98-
final Keyring kmsKeyring = StandardKeyrings.kms(clientSupplier, emptyList(), emptyList(), kmsArn);
98+
final Keyring kmsKeyring = StandardKeyrings.awsKms(clientSupplier, emptyList(), emptyList(), kmsArn);
9999

100-
// 4. Instantiate an RawRsaKeyring
100+
// 4. Instantiate a RawRsaKeyring
101101
// Because the user does not have access to the private escrow key,
102102
// they pass in "null" for the private key parameter.
103103
final Keyring rsaKeyring = StandardKeyrings.rawRsa("Escrow", "Escrow",
@@ -121,14 +121,14 @@ private static byte[] standardDecrypt(final String kmsArn, final byte[] cipherTe
121121
// 1. Instantiate the SDK
122122
final AwsCrypto crypto = new AwsCrypto();
123123

124-
// 2. Instantiate a KMS Client Supplier. This example uses the default client supplier but you can
124+
// 2. Instantiate an AWS KMS Client Supplier. This example uses the default client supplier but you can
125125
// also configure the credentials provider, client configuration and other settings as necessary
126-
final KmsClientSupplier clientSupplier = KmsClientSupplier.builder().build();
126+
final AwsKmsClientSupplier clientSupplier = AwsKmsClientSupplier.builder().build();
127127

128-
// 3. Instantiate a KMS Keyring, supplying the keyArn as the generator for generating a data key.
128+
// 3. Instantiate an AWS KMS Keyring, supplying the keyArn as the generator for generating a data key.
129129
// For this example, empty lists are provided for grant tokens and additional keys to encrypt the data
130130
// key with, but those can be supplied as necessary.
131-
final Keyring kmsKeyring = StandardKeyrings.kms(clientSupplier, emptyList(), emptyList(), kmsArn);
131+
final Keyring kmsKeyring = StandardKeyrings.awsKms(clientSupplier, emptyList(), emptyList(), kmsArn);
132132

133133
// 4. Decrypt the data with the keyring.
134134
// To simplify the code, we omit the encryption context. Production code should always

src/main/java/com/amazonaws/encryptionsdk/exception/UnsupportedRegionException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
/**
1717
* This exception is thrown when a region that is not allowed to be used by
18-
* a given KmsClientSupplier is specified.
18+
* a given AwsKmsClientSupplier is specified.
1919
*/
2020
public class UnsupportedRegionException extends AwsCryptoException {
2121

src/main/java/com/amazonaws/encryptionsdk/keyrings/KmsKeyring.java renamed to src/main/java/com/amazonaws/encryptionsdk/keyrings/AwsKmsKeyring.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,16 @@
3939

4040
/**
4141
* A keyring which interacts with AWS Key Management Service (KMS) to create,
42-
* encrypt, and decrypt data keys using KMS defined Customer Master Keys (CMKs).
42+
* encrypt, and decrypt data keys using AWS KMS defined Customer Master Keys (CMKs).
4343
*/
44-
class KmsKeyring implements Keyring {
44+
class AwsKmsKeyring implements Keyring {
4545

4646
private final DataKeyEncryptionDao dataKeyEncryptionDao;
4747
private final List<String> keyIds;
4848
private final String generatorKeyId;
4949
private final boolean isDiscovery;
5050

51-
KmsKeyring(DataKeyEncryptionDao dataKeyEncryptionDao, List<String> keyIds, String generatorKeyId) {
51+
AwsKmsKeyring(DataKeyEncryptionDao dataKeyEncryptionDao, List<String> keyIds, String generatorKeyId) {
5252
requireNonNull(dataKeyEncryptionDao, "dataKeyEncryptionDao is required");
5353
this.dataKeyEncryptionDao = dataKeyEncryptionDao;
5454
this.keyIds = keyIds == null ? emptyList() : unmodifiableList(new ArrayList<>(keyIds));

src/main/java/com/amazonaws/encryptionsdk/keyrings/StandardKeyrings.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
package com.amazonaws.encryptionsdk.keyrings;
1515

1616
import com.amazonaws.encryptionsdk.kms.DataKeyEncryptionDao;
17-
import com.amazonaws.encryptionsdk.kms.KmsClientSupplier;
17+
import com.amazonaws.encryptionsdk.kms.AwsKmsClientSupplier;
1818

1919
import javax.crypto.SecretKey;
2020
import java.security.PrivateKey;
@@ -61,19 +61,19 @@ public static Keyring rawRsa(String keyNamespace, String keyName, PublicKey publ
6161

6262
/**
6363
* Constructs a {@code Keyring} which interacts with AWS Key Management Service (KMS) to create,
64-
* encrypt, and decrypt data keys using KMS defined Customer Master Keys (CMKs).
64+
* encrypt, and decrypt data keys using AWS KMS defined Customer Master Keys (CMKs).
6565
*
66-
* @param clientSupplier A function that returns a KMS client that can make GenerateDataKey,
66+
* @param clientSupplier A function that returns an AWS KMS client that can make GenerateDataKey,
6767
* Encrypt, and Decrypt calls in a particular AWS region.
6868
* @param grantTokens A list of string grant tokens to be included in all KMS calls.
69-
* @param keyIds A list of strings identifying KMS CMKs used for encrypting and decrypting data keys in
70-
* ARN, CMK Alias, or ARN Alias format.
71-
* @param generatorKeyId A string that identifies a KMS CMK responsible for generating a data key,
69+
* @param keyIds A list of strings identifying AWS KMS CMKs used for encrypting and decrypting data keys
70+
* in ARN, CMK Alias, or ARN Alias format.
71+
* @param generatorKeyId A string that identifies a AWS KMS CMK responsible for generating a data key,
7272
* as well as encrypting and decrypting data keys in ARN, CMK Alias, or ARN Alias format.
7373
* @return The {@code Keyring}
7474
*/
75-
public static Keyring kms(KmsClientSupplier clientSupplier, List<String> grantTokens, List<String> keyIds, String generatorKeyId) {
76-
return new KmsKeyring(DataKeyEncryptionDao.kms(clientSupplier, grantTokens), keyIds, generatorKeyId);
75+
public static Keyring awsKms(AwsKmsClientSupplier clientSupplier, List<String> grantTokens, List<String> keyIds, String generatorKeyId) {
76+
return new AwsKmsKeyring(DataKeyEncryptionDao.awsKms(clientSupplier, grantTokens), keyIds, generatorKeyId);
7777
}
7878

7979
/**

src/main/java/com/amazonaws/encryptionsdk/kms/KmsClientSupplier.java renamed to src/main/java/com/amazonaws/encryptionsdk/kms/AwsKmsClientSupplier.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
* function should be able to handle when the region is null.
3939
*/
4040
@FunctionalInterface
41-
public interface KmsClientSupplier {
41+
public interface AwsKmsClientSupplier {
4242

4343
/**
4444
* Gets an {@code AWSKMS} client for the given regionId.
@@ -51,7 +51,7 @@ public interface KmsClientSupplier {
5151
AWSKMS getClient(@Nullable String regionId) throws UnsupportedRegionException;
5252

5353
/**
54-
* Gets a Builder for constructing a KmsClientSupplier
54+
* Gets a Builder for constructing an AwsKmsClientSupplier
5555
*
5656
* @return The builder
5757
*/
@@ -60,7 +60,7 @@ static Builder builder() {
6060
}
6161

6262
/**
63-
* Builder to construct a KmsClientSupplier given various
63+
* Builder to construct an AwsKmsClientSupplier given various
6464
* optional settings.
6565
*/
6666
class Builder {
@@ -71,20 +71,20 @@ class Builder {
7171
private Set<String> excludedRegions = Collections.emptySet();
7272
private boolean clientCachingEnabled = false;
7373
private final Map<String, AWSKMS> clientsCache = new HashMap<>();
74-
private static final Set<String> KMS_METHODS = new HashSet<>();
75-
private AWSKMSClientBuilder kmsClientBuilder;
74+
private static final Set<String> AWSKMS_METHODS = new HashSet<>();
75+
private AWSKMSClientBuilder awsKmsClientBuilder;
7676

7777
static {
78-
KMS_METHODS.add("generateDataKey");
79-
KMS_METHODS.add("encrypt");
80-
KMS_METHODS.add("decrypt");
78+
AWSKMS_METHODS.add("generateDataKey");
79+
AWSKMS_METHODS.add("encrypt");
80+
AWSKMS_METHODS.add("decrypt");
8181
}
8282

83-
Builder(AWSKMSClientBuilder kmsClientBuilder) {
84-
this.kmsClientBuilder = kmsClientBuilder;
83+
Builder(AWSKMSClientBuilder awsKmsClientBuilder) {
84+
this.awsKmsClientBuilder = awsKmsClientBuilder;
8585
}
8686

87-
public KmsClientSupplier build() {
87+
public AwsKmsClientSupplier build() {
8888
isTrue(allowedRegions.isEmpty() || excludedRegions.isEmpty(),
8989
"Either allowed regions or excluded regions may be set, not both.");
9090

@@ -104,18 +104,18 @@ public KmsClientSupplier build() {
104104
}
105105

106106
if (credentialsProvider != null) {
107-
kmsClientBuilder = kmsClientBuilder.withCredentials(credentialsProvider);
107+
awsKmsClientBuilder = awsKmsClientBuilder.withCredentials(credentialsProvider);
108108
}
109109

110110
if (clientConfiguration != null) {
111-
kmsClientBuilder = kmsClientBuilder.withClientConfiguration(clientConfiguration);
111+
awsKmsClientBuilder = awsKmsClientBuilder.withClientConfiguration(clientConfiguration);
112112
}
113113

114114
if (regionId != null) {
115-
kmsClientBuilder = kmsClientBuilder.withRegion(regionId);
115+
awsKmsClientBuilder = awsKmsClientBuilder.withRegion(regionId);
116116
}
117117

118-
AWSKMS client = kmsClientBuilder.build();
118+
AWSKMS client = awsKmsClientBuilder.build();
119119

120120
if (clientCachingEnabled) {
121121
client = newCachingProxy(client, regionId);
@@ -179,7 +179,7 @@ public Builder clientCaching(boolean enabled) {
179179

180180
/**
181181
* Creates a proxy for the AWSKMS client that will populate the client into the client cache
182-
* after a KMS method successfully completes or a KMS exception occurs. This is to prevent a
182+
* after an AWS KMS method successfully completes or an AWS KMS exception occurs. This is to prevent a
183183
* a malicious user from causing a local resource DOS by sending ciphertext with a large number
184184
* of spurious regions, thereby filling the cache with regions and exhausting resources.
185185
*
@@ -194,13 +194,13 @@ private AWSKMS newCachingProxy(AWSKMS client, String regionId) {
194194
(proxy, method, methodArgs) -> {
195195
try {
196196
final Object result = method.invoke(client, methodArgs);
197-
if (KMS_METHODS.contains(method.getName())) {
197+
if (AWSKMS_METHODS.contains(method.getName())) {
198198
clientsCache.put(regionId, client);
199199
}
200200
return result;
201201
} catch (InvocationTargetException e) {
202202
if (e.getTargetException() instanceof AWSKMSException &&
203-
KMS_METHODS.contains(method.getName())) {
203+
AWSKMS_METHODS.contains(method.getName())) {
204204
clientsCache.put(regionId, client);
205205
}
206206

src/main/java/com/amazonaws/encryptionsdk/kms/KmsDataKeyEncryptionDao.java renamed to src/main/java/com/amazonaws/encryptionsdk/kms/AwsKmsDataKeyEncryptionDao.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@
4646
* generation, encryption, and decryption of data keys. The KmsMethods interface is implemented
4747
* to allow usage in KmsMasterKey.
4848
*/
49-
class KmsDataKeyEncryptionDao implements DataKeyEncryptionDao, KmsMethods {
49+
class AwsKmsDataKeyEncryptionDao implements DataKeyEncryptionDao, KmsMethods {
5050

51-
private final KmsClientSupplier clientSupplier;
51+
private final AwsKmsClientSupplier clientSupplier;
5252
private List<String> grantTokens;
5353

54-
KmsDataKeyEncryptionDao(KmsClientSupplier clientSupplier, List<String> grantTokens) {
54+
AwsKmsDataKeyEncryptionDao(AwsKmsClientSupplier clientSupplier, List<String> grantTokens) {
5555
requireNonNull(clientSupplier, "clientSupplier is required");
5656

5757
this.clientSupplier = clientSupplier;

src/main/java/com/amazonaws/encryptionsdk/kms/DataKeyEncryptionDao.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ public interface DataKeyEncryptionDao {
6161
* @param grantTokens A list of grant tokens to supply to KMS
6262
* @return The DataKeyEncryptionDao
6363
*/
64-
static DataKeyEncryptionDao kms(KmsClientSupplier clientSupplier, List<String> grantTokens) {
65-
return new KmsDataKeyEncryptionDao(clientSupplier, grantTokens);
64+
static DataKeyEncryptionDao awsKms(AwsKmsClientSupplier clientSupplier, List<String> grantTokens) {
65+
return new AwsKmsDataKeyEncryptionDao(clientSupplier, grantTokens);
6666
}
6767

6868
class GenerateDataKeyResult {

src/main/java/com/amazonaws/encryptionsdk/kms/KmsMasterKey.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
*/
4444
@Deprecated
4545
public final class KmsMasterKey extends MasterKey<KmsMasterKey> implements KmsMethods {
46-
private final KmsDataKeyEncryptionDao dataKeyEncryptionDao_;
46+
private final AwsKmsDataKeyEncryptionDao dataKeyEncryptionDao_;
4747
private final MasterKeyProvider<KmsMasterKey> sourceProvider_;
4848
private final String id_;
4949

@@ -67,10 +67,10 @@ public static KmsMasterKey getInstance(final AWSCredentialsProvider creds, final
6767

6868
static KmsMasterKey getInstance(final Supplier<AWSKMS> kms, final String id,
6969
final MasterKeyProvider<KmsMasterKey> provider) {
70-
return new KmsMasterKey(new KmsDataKeyEncryptionDao(s -> kms.get(), emptyList()), id, provider);
70+
return new KmsMasterKey(new AwsKmsDataKeyEncryptionDao(s -> kms.get(), emptyList()), id, provider);
7171
}
7272

73-
KmsMasterKey(final KmsDataKeyEncryptionDao dataKeyEncryptionDao, final String id, final MasterKeyProvider<KmsMasterKey> provider) {
73+
KmsMasterKey(final AwsKmsDataKeyEncryptionDao dataKeyEncryptionDao, final String id, final MasterKeyProvider<KmsMasterKey> provider) {
7474
dataKeyEncryptionDao_ = dataKeyEncryptionDao;
7575
id_ = id;
7676
sourceProvider_ = provider;

src/main/java/com/amazonaws/encryptionsdk/kms/KmsUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class KmsUtils {
3535
* @return AWSKMS The client
3636
* @throws MalformedArnException if the arn is malformed
3737
*/
38-
public static AWSKMS getClientByArn(String arn, KmsClientSupplier clientSupplier) throws MalformedArnException {
38+
public static AWSKMS getClientByArn(String arn, AwsKmsClientSupplier clientSupplier) throws MalformedArnException {
3939
if (isKeyAlias(arn)) {
4040
return clientSupplier.getClient(null);
4141
}

0 commit comments

Comments
 (0)