in src/main/java/com/amazonaws/encryptionsdk/kmssdkv2/AwsKmsMrkAwareMasterKeyProvider.java [300:362]
private AwsKmsMrkAwareMasterKeyProvider(
RegionalClientSupplier supplier,
Region defaultRegion,
List<String> keyIds,
List<String> grantTokens,
boolean isDiscovery,
DiscoveryFilter discoveryFilter,
Region discoveryMrkRegion) {
// = compliance/framework/aws-kms/aws-kms-mrk-aware-master-key-provider.txt#2.6
// # The key id list MUST NOT be empty or null in strict mode.
if (!isDiscovery && (keyIds == null || keyIds.isEmpty())) {
throw new IllegalArgumentException(
"Strict mode must be configured with a non-empty " + "list of keyIds.");
}
// = compliance/framework/aws-kms/aws-kms-mrk-aware-master-key-provider.txt#2.6
// # The key id
// # list MUST NOT contain any null or empty string values.
if (!isDiscovery && (keyIds.contains(null) || keyIds.contains(""))) {
throw new IllegalArgumentException(
"Strict mode cannot be configured with a " + "null key identifier.");
}
// = compliance/framework/aws-kms/aws-kms-mrk-aware-master-key-provider.txt#2.6
// # All AWS KMS
// # key identifiers are be passed to Assert AWS KMS MRK are unique (aws-
// # kms-mrk-are-unique.md#Implementation) and the function MUST return
// # success.
assertMrksAreUnique(keyIds);
/* Precondition: A region is required to contact AWS KMS.
* This is an edge case because the default region will be the same as the SDK default,
* but it is still possible.
*/
if (!isDiscovery
&& defaultRegion == null
&& keyIds.stream().map(AwsKmsCmkArnInfo::parseInfoFromKeyArn).anyMatch(Objects::isNull)) {
throw new AwsCryptoException(
"Can't use non-ARN key identifiers or aliases when " + "no default region is set");
}
/* Precondition: Discovery filter is only valid in discovery mode. */
if (!isDiscovery && discoveryFilter != null) {
throw new IllegalArgumentException(
"Strict mode cannot be configured with a " + "discovery filter.");
}
/* Precondition: Discovery mode can not have any keys to filter. */
if (isDiscovery && !keyIds.isEmpty()) {
throw new IllegalArgumentException("Discovery mode can not be configured with keys.");
}
// = compliance/framework/aws-kms/aws-kms-mrk-aware-master-key-provider.txt#2.6
// # If an AWS SDK Default Region can not be
// # obtained initialization MUST fail.
if (isDiscovery && discoveryMrkRegion == null) {
throw new IllegalArgumentException("Discovery MRK region can not be null.");
}
this.regionalClientSupplier_ = supplier;
this.defaultRegion_ = defaultRegion;
this.keyIds_ = Collections.unmodifiableList(new ArrayList<>(keyIds));
this.isDiscovery_ = isDiscovery;
this.discoveryFilter_ = discoveryFilter;
this.discoveryMrkRegion_ = discoveryMrkRegion;
this.grantTokens_ = grantTokens;
}