grantTokens;
private GenerateDataKeyRequest(BuilderImpl builder) {
super(builder);
this.keyId = builder.keyId;
this.encryptionContext = builder.encryptionContext;
this.numberOfBytes = builder.numberOfBytes;
this.keySpec = builder.keySpec;
this.grantTokens = builder.grantTokens;
}
/**
*
* The identifier of the CMK under which to generate and encrypt the data encryption key.
*
*
* To specify a CMK, use its key ID, Amazon Resource Name (ARN), alias name, or alias ARN. When using an alias name,
* prefix it with "alias/". To specify a CMK in a different AWS account, you must use the key ARN or alias ARN.
*
*
* For example:
*
*
*
*
* Key ID: 1234abcd-12ab-34cd-56ef-1234567890ab
*
*
*
*
* Key ARN: arn:aws:kms:us-east-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab
*
*
*
*
* Alias name: alias/ExampleAlias
*
*
*
*
* Alias ARN: arn:aws:kms:us-east-2:111122223333:alias/ExampleAlias
*
*
*
*
* To get the key ID and key ARN for a CMK, use ListKeys or DescribeKey . To get the alias name and
* alias ARN, use ListAliases .
*
*
* @return The identifier of the CMK under which to generate and encrypt the data encryption key.
*
* To specify a CMK, use its key ID, Amazon Resource Name (ARN), alias name, or alias ARN. When using an
* alias name, prefix it with "alias/". To specify a CMK in a different AWS account, you must use the key
* ARN or alias ARN.
*
*
* For example:
*
*
*
*
* Key ID: 1234abcd-12ab-34cd-56ef-1234567890ab
*
*
*
*
* Key ARN: arn:aws:kms:us-east-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab
*
*
*
*
* Alias name: alias/ExampleAlias
*
*
*
*
* Alias ARN: arn:aws:kms:us-east-2:111122223333:alias/ExampleAlias
*
*
*
*
* To get the key ID and key ARN for a CMK, use ListKeys or DescribeKey . To get the alias name
* and alias ARN, use ListAliases .
*/
public String keyId() {
return keyId;
}
/**
*
* A set of key-value pairs that represents additional authenticated data.
*
*
* For more information, see Encryption Context in the
* AWS Key Management Service Developer Guide .
*
*
* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException.
*
*
* @return A set of key-value pairs that represents additional authenticated data.
*
* For more information, see Encryption
* Context in the AWS Key Management Service Developer Guide .
*/
public Map encryptionContext() {
return encryptionContext;
}
/**
*
* The length of the data encryption key in bytes. For example, use the value 64 to generate a 512-bit data key (64
* bytes is 512 bits). For common key lengths (128-bit and 256-bit symmetric keys), we recommend that you use the
* KeySpec
field instead of this one.
*
*
* @return The length of the data encryption key in bytes. For example, use the value 64 to generate a 512-bit data
* key (64 bytes is 512 bits). For common key lengths (128-bit and 256-bit symmetric keys), we recommend
* that you use the KeySpec
field instead of this one.
*/
public Integer numberOfBytes() {
return numberOfBytes;
}
/**
*
* The length of the data encryption key. Use AES_128
to generate a 128-bit symmetric key, or
* AES_256
to generate a 256-bit symmetric key.
*
*
* If the service returns an enum value that is not available in the current SDK version, {@link #keySpec} will
* return {@link DataKeySpec#UNKNOWN_TO_SDK_VERSION}. The raw value returned by the service is available from
* {@link #keySpecAsString}.
*
*
* @return The length of the data encryption key. Use AES_128
to generate a 128-bit symmetric key, or
* AES_256
to generate a 256-bit symmetric key.
* @see DataKeySpec
*/
public DataKeySpec keySpec() {
return DataKeySpec.fromValue(keySpec);
}
/**
*
* The length of the data encryption key. Use AES_128
to generate a 128-bit symmetric key, or
* AES_256
to generate a 256-bit symmetric key.
*
*
* If the service returns an enum value that is not available in the current SDK version, {@link #keySpec} will
* return {@link DataKeySpec#UNKNOWN_TO_SDK_VERSION}. The raw value returned by the service is available from
* {@link #keySpecAsString}.
*
*
* @return The length of the data encryption key. Use AES_128
to generate a 128-bit symmetric key, or
* AES_256
to generate a 256-bit symmetric key.
* @see DataKeySpec
*/
public String keySpecAsString() {
return keySpec;
}
/**
*
* A list of grant tokens.
*
*
* For more information, see Grant Tokens in the
* AWS Key Management Service Developer Guide .
*
*
* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException.
*
*
* @return A list of grant tokens.
*
* For more information, see Grant Tokens in
* the AWS Key Management Service Developer Guide .
*/
public List grantTokens() {
return grantTokens;
}
@Override
public Builder toBuilder() {
return new BuilderImpl(this);
}
public static Builder builder() {
return new BuilderImpl();
}
public static Class extends Builder> serializableBuilderClass() {
return BuilderImpl.class;
}
@Override
public int hashCode() {
int hashCode = 1;
hashCode = 31 * hashCode + Objects.hashCode(keyId());
hashCode = 31 * hashCode + Objects.hashCode(encryptionContext());
hashCode = 31 * hashCode + Objects.hashCode(numberOfBytes());
hashCode = 31 * hashCode + Objects.hashCode(keySpecAsString());
hashCode = 31 * hashCode + Objects.hashCode(grantTokens());
return hashCode;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof GenerateDataKeyRequest)) {
return false;
}
GenerateDataKeyRequest other = (GenerateDataKeyRequest) obj;
return Objects.equals(keyId(), other.keyId()) && Objects.equals(encryptionContext(), other.encryptionContext())
&& Objects.equals(numberOfBytes(), other.numberOfBytes())
&& Objects.equals(keySpecAsString(), other.keySpecAsString())
&& Objects.equals(grantTokens(), other.grantTokens());
}
/**
* Returns a string representation of this object. This is useful for testing and debugging. Sensitive data will be
* redacted from this string using a placeholder value.
*/
@Override
public String toString() {
return ToString.builder("GenerateDataKeyRequest").add("KeyId", keyId()).add("EncryptionContext", encryptionContext())
.add("NumberOfBytes", numberOfBytes()).add("KeySpec", keySpecAsString()).add("GrantTokens", grantTokens())
.build();
}
public Optional getValueForField(String fieldName, Class clazz) {
switch (fieldName) {
case "KeyId":
return Optional.ofNullable(clazz.cast(keyId()));
case "EncryptionContext":
return Optional.ofNullable(clazz.cast(encryptionContext()));
case "NumberOfBytes":
return Optional.ofNullable(clazz.cast(numberOfBytes()));
case "KeySpec":
return Optional.ofNullable(clazz.cast(keySpecAsString()));
case "GrantTokens":
return Optional.ofNullable(clazz.cast(grantTokens()));
default:
return Optional.empty();
}
}
@Override
public List> sdkFields() {
return SDK_FIELDS;
}
private static Function getter(Function g) {
return obj -> g.apply((GenerateDataKeyRequest) obj);
}
private static BiConsumer setter(BiConsumer s) {
return (obj, val) -> s.accept((Builder) obj, val);
}
public interface Builder extends KmsRequest.Builder, SdkPojo, CopyableBuilder {
/**
*
* The identifier of the CMK under which to generate and encrypt the data encryption key.
*
*
* To specify a CMK, use its key ID, Amazon Resource Name (ARN), alias name, or alias ARN. When using an alias
* name, prefix it with "alias/". To specify a CMK in a different AWS account, you must use the key ARN or alias
* ARN.
*
*
* For example:
*
*
*
*
* Key ID: 1234abcd-12ab-34cd-56ef-1234567890ab
*
*
*
*
* Key ARN: arn:aws:kms:us-east-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab
*
*
*
*
* Alias name: alias/ExampleAlias
*
*
*
*
* Alias ARN: arn:aws:kms:us-east-2:111122223333:alias/ExampleAlias
*
*
*
*
* To get the key ID and key ARN for a CMK, use ListKeys or DescribeKey . To get the alias name and
* alias ARN, use ListAliases .
*
*
* @param keyId
* The identifier of the CMK under which to generate and encrypt the data encryption key.
*
* To specify a CMK, use its key ID, Amazon Resource Name (ARN), alias name, or alias ARN. When using an
* alias name, prefix it with "alias/". To specify a CMK in a different AWS account, you must use the key
* ARN or alias ARN.
*
*
* For example:
*
*
*
*
* Key ID: 1234abcd-12ab-34cd-56ef-1234567890ab
*
*
*
*
* Key ARN: arn:aws:kms:us-east-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab
*
*
*
*
* Alias name: alias/ExampleAlias
*
*
*
*
* Alias ARN: arn:aws:kms:us-east-2:111122223333:alias/ExampleAlias
*
*
*
*
* To get the key ID and key ARN for a CMK, use ListKeys or DescribeKey . To get the alias
* name and alias ARN, use ListAliases .
* @return Returns a reference to this object so that method calls can be chained together.
*/
Builder keyId(String keyId);
/**
*
* A set of key-value pairs that represents additional authenticated data.
*
*
* For more information, see Encryption Context in
* the AWS Key Management Service Developer Guide .
*
*
* @param encryptionContext
* A set of key-value pairs that represents additional authenticated data.
*
* For more information, see Encryption
* Context in the AWS Key Management Service Developer Guide .
* @return Returns a reference to this object so that method calls can be chained together.
*/
Builder encryptionContext(Map encryptionContext);
/**
*
* The length of the data encryption key in bytes. For example, use the value 64 to generate a 512-bit data key
* (64 bytes is 512 bits). For common key lengths (128-bit and 256-bit symmetric keys), we recommend that you
* use the KeySpec
field instead of this one.
*
*
* @param numberOfBytes
* The length of the data encryption key in bytes. For example, use the value 64 to generate a 512-bit
* data key (64 bytes is 512 bits). For common key lengths (128-bit and 256-bit symmetric keys), we
* recommend that you use the KeySpec
field instead of this one.
* @return Returns a reference to this object so that method calls can be chained together.
*/
Builder numberOfBytes(Integer numberOfBytes);
/**
*
* The length of the data encryption key. Use AES_128
to generate a 128-bit symmetric key, or
* AES_256
to generate a 256-bit symmetric key.
*
*
* @param keySpec
* The length of the data encryption key. Use AES_128
to generate a 128-bit symmetric key,
* or AES_256
to generate a 256-bit symmetric key.
* @see DataKeySpec
* @return Returns a reference to this object so that method calls can be chained together.
* @see DataKeySpec
*/
Builder keySpec(String keySpec);
/**
*
* The length of the data encryption key. Use AES_128
to generate a 128-bit symmetric key, or
* AES_256
to generate a 256-bit symmetric key.
*
*
* @param keySpec
* The length of the data encryption key. Use AES_128
to generate a 128-bit symmetric key,
* or AES_256
to generate a 256-bit symmetric key.
* @see DataKeySpec
* @return Returns a reference to this object so that method calls can be chained together.
* @see DataKeySpec
*/
Builder keySpec(DataKeySpec keySpec);
/**
*
* A list of grant tokens.
*
*
* For more information, see Grant Tokens in the
* AWS Key Management Service Developer Guide .
*
*
* @param grantTokens
* A list of grant tokens.
*
* For more information, see Grant Tokens
* in the AWS Key Management Service Developer Guide .
* @return Returns a reference to this object so that method calls can be chained together.
*/
Builder grantTokens(Collection grantTokens);
/**
*
* A list of grant tokens.
*
*
* For more information, see Grant Tokens in the
* AWS Key Management Service Developer Guide .
*
*
* @param grantTokens
* A list of grant tokens.
*
* For more information, see Grant Tokens
* in the AWS Key Management Service Developer Guide .
* @return Returns a reference to this object so that method calls can be chained together.
*/
Builder grantTokens(String... grantTokens);
@Override
Builder overrideConfiguration(AwsRequestOverrideConfiguration overrideConfiguration);
@Override
Builder overrideConfiguration(Consumer builderConsumer);
}
static final class BuilderImpl extends KmsRequest.BuilderImpl implements Builder {
private String keyId;
private Map encryptionContext = DefaultSdkAutoConstructMap.getInstance();
private Integer numberOfBytes;
private String keySpec;
private List grantTokens = DefaultSdkAutoConstructList.getInstance();
private BuilderImpl() {
}
private BuilderImpl(GenerateDataKeyRequest model) {
super(model);
keyId(model.keyId);
encryptionContext(model.encryptionContext);
numberOfBytes(model.numberOfBytes);
keySpec(model.keySpec);
grantTokens(model.grantTokens);
}
public final String getKeyId() {
return keyId;
}
@Override
public final Builder keyId(String keyId) {
this.keyId = keyId;
return this;
}
public final void setKeyId(String keyId) {
this.keyId = keyId;
}
public final Map getEncryptionContext() {
return encryptionContext;
}
@Override
public final Builder encryptionContext(Map encryptionContext) {
this.encryptionContext = EncryptionContextTypeCopier.copy(encryptionContext);
return this;
}
public final void setEncryptionContext(Map encryptionContext) {
this.encryptionContext = EncryptionContextTypeCopier.copy(encryptionContext);
}
public final Integer getNumberOfBytes() {
return numberOfBytes;
}
@Override
public final Builder numberOfBytes(Integer numberOfBytes) {
this.numberOfBytes = numberOfBytes;
return this;
}
public final void setNumberOfBytes(Integer numberOfBytes) {
this.numberOfBytes = numberOfBytes;
}
public final String getKeySpecAsString() {
return keySpec;
}
@Override
public final Builder keySpec(String keySpec) {
this.keySpec = keySpec;
return this;
}
@Override
public final Builder keySpec(DataKeySpec keySpec) {
this.keySpec(keySpec.toString());
return this;
}
public final void setKeySpec(String keySpec) {
this.keySpec = keySpec;
}
public final Collection getGrantTokens() {
return grantTokens;
}
@Override
public final Builder grantTokens(Collection grantTokens) {
this.grantTokens = GrantTokenListCopier.copy(grantTokens);
return this;
}
@Override
@SafeVarargs
public final Builder grantTokens(String... grantTokens) {
grantTokens(Arrays.asList(grantTokens));
return this;
}
public final void setGrantTokens(Collection grantTokens) {
this.grantTokens = GrantTokenListCopier.copy(grantTokens);
}
@Override
public Builder overrideConfiguration(AwsRequestOverrideConfiguration overrideConfiguration) {
super.overrideConfiguration(overrideConfiguration);
return this;
}
@Override
public Builder overrideConfiguration(Consumer builderConsumer) {
super.overrideConfiguration(builderConsumer);
return this;
}
@Override
public GenerateDataKeyRequest build() {
return new GenerateDataKeyRequest(this);
}
@Override
public List> sdkFields() {
return SDK_FIELDS;
}
}
}