All Downloads are FREE. Search and download functionalities are using the official Maven repository.

software.amazon.awssdk.services.kms.model.GenerateDataKeyRequest Maven / Gradle / Ivy

/*
 * Copyright 2014-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
 * the License. A copy of the License is located at
 * 
 * http://aws.amazon.com/apache2.0
 * 
 * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
 * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
 * and limitations under the License.
 */

package software.amazon.awssdk.services.kms.model;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function;
import software.amazon.awssdk.annotations.Generated;
import software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration;
import software.amazon.awssdk.core.SdkField;
import software.amazon.awssdk.core.SdkPojo;
import software.amazon.awssdk.core.protocol.MarshallLocation;
import software.amazon.awssdk.core.protocol.MarshallingType;
import software.amazon.awssdk.core.traits.ListTrait;
import software.amazon.awssdk.core.traits.LocationTrait;
import software.amazon.awssdk.core.traits.MapTrait;
import software.amazon.awssdk.core.util.DefaultSdkAutoConstructList;
import software.amazon.awssdk.core.util.DefaultSdkAutoConstructMap;
import software.amazon.awssdk.utils.ToString;
import software.amazon.awssdk.utils.builder.CopyableBuilder;
import software.amazon.awssdk.utils.builder.ToCopyableBuilder;

/**
 */
@Generated("software.amazon.awssdk:codegen")
public final class GenerateDataKeyRequest extends KmsRequest implements
        ToCopyableBuilder {
    private static final SdkField KEY_ID_FIELD = SdkField. builder(MarshallingType.STRING)
            .getter(getter(GenerateDataKeyRequest::keyId)).setter(setter(Builder::keyId))
            .traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("KeyId").build()).build();

    private static final SdkField> ENCRYPTION_CONTEXT_FIELD = SdkField
            .> builder(MarshallingType.MAP)
            .getter(getter(GenerateDataKeyRequest::encryptionContext))
            .setter(setter(Builder::encryptionContext))
            .traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("EncryptionContext").build(),
                    MapTrait.builder()
                            .keyLocationName("key")
                            .valueLocationName("value")
                            .valueFieldInfo(
                                    SdkField. builder(MarshallingType.STRING)
                                            .traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD)
                                                    .locationName("value").build()).build()).build()).build();

    private static final SdkField NUMBER_OF_BYTES_FIELD = SdkField. builder(MarshallingType.INTEGER)
            .getter(getter(GenerateDataKeyRequest::numberOfBytes)).setter(setter(Builder::numberOfBytes))
            .traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("NumberOfBytes").build()).build();

    private static final SdkField KEY_SPEC_FIELD = SdkField. builder(MarshallingType.STRING)
            .getter(getter(GenerateDataKeyRequest::keySpecAsString)).setter(setter(Builder::keySpec))
            .traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("KeySpec").build()).build();

    private static final SdkField> GRANT_TOKENS_FIELD = SdkField
            .> builder(MarshallingType.LIST)
            .getter(getter(GenerateDataKeyRequest::grantTokens))
            .setter(setter(Builder::grantTokens))
            .traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("GrantTokens").build(),
                    ListTrait
                            .builder()
                            .memberLocationName(null)
                            .memberFieldInfo(
                                    SdkField. builder(MarshallingType.STRING)
                                            .traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD)
                                                    .locationName("member").build()).build()).build()).build();

    private static final List> SDK_FIELDS = Collections.unmodifiableList(Arrays.asList(KEY_ID_FIELD,
            ENCRYPTION_CONTEXT_FIELD, NUMBER_OF_BYTES_FIELD, KEY_SPEC_FIELD, GRANT_TOKENS_FIELD));

    private final String keyId;

    private final Map encryptionContext;

    private final Integer numberOfBytes;

    private final String keySpec;

    private final List 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 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; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy