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

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

Go to download

The AWS Java SDK for AWS KMS module holds the client classes that are used for communicating with AWS Key Management Service

There is a newer version: 2.30.1
Show newest version
/*
 * Copyright 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.nio.ByteBuffer;
import java.time.Instant;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
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.SdkBytes;
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.LocationTrait;
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 ImportKeyMaterialRequest extends KmsRequest implements
        ToCopyableBuilder {
    private static final SdkField KEY_ID_FIELD = SdkField. builder(MarshallingType.STRING).memberName("KeyId")
            .getter(getter(ImportKeyMaterialRequest::keyId)).setter(setter(Builder::keyId))
            .traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("KeyId").build()).build();

    private static final SdkField IMPORT_TOKEN_FIELD = SdkField. builder(MarshallingType.SDK_BYTES)
            .memberName("ImportToken").getter(getter(ImportKeyMaterialRequest::importToken)).setter(setter(Builder::importToken))
            .traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("ImportToken").build()).build();

    private static final SdkField ENCRYPTED_KEY_MATERIAL_FIELD = SdkField. builder(MarshallingType.SDK_BYTES)
            .memberName("EncryptedKeyMaterial").getter(getter(ImportKeyMaterialRequest::encryptedKeyMaterial))
            .setter(setter(Builder::encryptedKeyMaterial))
            .traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("EncryptedKeyMaterial").build())
            .build();

    private static final SdkField VALID_TO_FIELD = SdkField. builder(MarshallingType.INSTANT)
            .memberName("ValidTo").getter(getter(ImportKeyMaterialRequest::validTo)).setter(setter(Builder::validTo))
            .traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("ValidTo").build()).build();

    private static final SdkField EXPIRATION_MODEL_FIELD = SdkField. builder(MarshallingType.STRING)
            .memberName("ExpirationModel").getter(getter(ImportKeyMaterialRequest::expirationModelAsString))
            .setter(setter(Builder::expirationModel))
            .traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("ExpirationModel").build()).build();

    private static final List> SDK_FIELDS = Collections.unmodifiableList(Arrays.asList(KEY_ID_FIELD,
            IMPORT_TOKEN_FIELD, ENCRYPTED_KEY_MATERIAL_FIELD, VALID_TO_FIELD, EXPIRATION_MODEL_FIELD));

    private static final Map> SDK_NAME_TO_FIELD = Collections
            .unmodifiableMap(new HashMap>() {
                {
                    put("KeyId", KEY_ID_FIELD);
                    put("ImportToken", IMPORT_TOKEN_FIELD);
                    put("EncryptedKeyMaterial", ENCRYPTED_KEY_MATERIAL_FIELD);
                    put("ValidTo", VALID_TO_FIELD);
                    put("ExpirationModel", EXPIRATION_MODEL_FIELD);
                }
            });

    private final String keyId;

    private final SdkBytes importToken;

    private final SdkBytes encryptedKeyMaterial;

    private final Instant validTo;

    private final String expirationModel;

    private ImportKeyMaterialRequest(BuilderImpl builder) {
        super(builder);
        this.keyId = builder.keyId;
        this.importToken = builder.importToken;
        this.encryptedKeyMaterial = builder.encryptedKeyMaterial;
        this.validTo = builder.validTo;
        this.expirationModel = builder.expirationModel;
    }

    /**
     * 

* The identifier of the KMS key that will be associated with the imported key material. This must be the same KMS * key specified in the KeyID parameter of the corresponding GetParametersForImport request. The * Origin of the KMS key must be EXTERNAL and its KeyState must be * PendingImport. *

*

* The KMS key can be a symmetric encryption KMS key, HMAC KMS key, asymmetric encryption KMS key, or asymmetric * signing KMS key, including a multi-Region * key of any supported type. You cannot perform this operation on a KMS key in a custom key store, or on a KMS * key in a different Amazon Web Services account. *

*

* Specify the key ID or key ARN of the KMS key. *

*

* For example: *

*
    *
  • *

    * Key ID: 1234abcd-12ab-34cd-56ef-1234567890ab *

    *
  • *
  • *

    * Key ARN: arn:aws:kms:us-east-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab *

    *
  • *
*

* To get the key ID and key ARN for a KMS key, use ListKeys or DescribeKey. *

* * @return The identifier of the KMS key that will be associated with the imported key material. This must be the * same KMS key specified in the KeyID parameter of the corresponding * GetParametersForImport request. The Origin of the KMS key must be * EXTERNAL and its KeyState must be PendingImport.

*

* The KMS key can be a symmetric encryption KMS key, HMAC KMS key, asymmetric encryption KMS key, or * asymmetric signing KMS key, including a multi-Region key of any supported * type. You cannot perform this operation on a KMS key in a custom key store, or on a KMS key in a * different Amazon Web Services account. *

*

* Specify the key ID or key ARN of the KMS key. *

*

* For example: *

*
    *
  • *

    * Key ID: 1234abcd-12ab-34cd-56ef-1234567890ab *

    *
  • *
  • *

    * Key ARN: arn:aws:kms:us-east-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab *

    *
  • *
*

* To get the key ID and key ARN for a KMS key, use ListKeys or DescribeKey. */ public final String keyId() { return keyId; } /** *

* The import token that you received in the response to a previous GetParametersForImport request. It must * be from the same response that contained the public key that you used to encrypt the key material. *

* * @return The import token that you received in the response to a previous GetParametersForImport request. * It must be from the same response that contained the public key that you used to encrypt the key * material. */ public final SdkBytes importToken() { return importToken; } /** *

* The encrypted key material to import. The key material must be encrypted under the public wrapping key that * GetParametersForImport returned, using the wrapping algorithm that you specified in the same * GetParametersForImport request. *

* * @return The encrypted key material to import. The key material must be encrypted under the public wrapping key * that GetParametersForImport returned, using the wrapping algorithm that you specified in the same * GetParametersForImport request. */ public final SdkBytes encryptedKeyMaterial() { return encryptedKeyMaterial; } /** *

* The date and time when the imported key material expires. This parameter is required when the value of the * ExpirationModel parameter is KEY_MATERIAL_EXPIRES. Otherwise it is not valid. *

*

* The value of this parameter must be a future date and time. The maximum value is 365 days from the request date. *

*

* When the key material expires, KMS deletes the key material from the KMS key. Without its key material, the KMS * key is unusable. To use the KMS key in cryptographic operations, you must reimport the same key material. *

*

* You cannot change the ExpirationModel or ValidTo values for the current import after * the request completes. To change either value, you must delete (DeleteImportedKeyMaterial) and reimport * the key material. *

* * @return The date and time when the imported key material expires. This parameter is required when the value of * the ExpirationModel parameter is KEY_MATERIAL_EXPIRES. Otherwise it is not * valid.

*

* The value of this parameter must be a future date and time. The maximum value is 365 days from the * request date. *

*

* When the key material expires, KMS deletes the key material from the KMS key. Without its key material, * the KMS key is unusable. To use the KMS key in cryptographic operations, you must reimport the same key * material. *

*

* You cannot change the ExpirationModel or ValidTo values for the current import * after the request completes. To change either value, you must delete (DeleteImportedKeyMaterial) * and reimport the key material. */ public final Instant validTo() { return validTo; } /** *

* Specifies whether the key material expires. The default is KEY_MATERIAL_EXPIRES. For help with this * choice, see Setting an expiration time in the Key Management Service Developer Guide. *

*

* When the value of ExpirationModel is KEY_MATERIAL_EXPIRES, you must specify a value for * the ValidTo parameter. When value is KEY_MATERIAL_DOES_NOT_EXPIRE, you must omit the * ValidTo parameter. *

*

* You cannot change the ExpirationModel or ValidTo values for the current import after * the request completes. To change either value, you must reimport the key material. *

*

* If the service returns an enum value that is not available in the current SDK version, {@link #expirationModel} * will return {@link ExpirationModelType#UNKNOWN_TO_SDK_VERSION}. The raw value returned by the service is * available from {@link #expirationModelAsString}. *

* * @return Specifies whether the key material expires. The default is KEY_MATERIAL_EXPIRES. For help * with this choice, see Setting an expiration time in the Key Management Service Developer Guide.

*

* When the value of ExpirationModel is KEY_MATERIAL_EXPIRES, you must specify a * value for the ValidTo parameter. When value is KEY_MATERIAL_DOES_NOT_EXPIRE, * you must omit the ValidTo parameter. *

*

* You cannot change the ExpirationModel or ValidTo values for the current import * after the request completes. To change either value, you must reimport the key material. * @see ExpirationModelType */ public final ExpirationModelType expirationModel() { return ExpirationModelType.fromValue(expirationModel); } /** *

* Specifies whether the key material expires. The default is KEY_MATERIAL_EXPIRES. For help with this * choice, see Setting an expiration time in the Key Management Service Developer Guide. *

*

* When the value of ExpirationModel is KEY_MATERIAL_EXPIRES, you must specify a value for * the ValidTo parameter. When value is KEY_MATERIAL_DOES_NOT_EXPIRE, you must omit the * ValidTo parameter. *

*

* You cannot change the ExpirationModel or ValidTo values for the current import after * the request completes. To change either value, you must reimport the key material. *

*

* If the service returns an enum value that is not available in the current SDK version, {@link #expirationModel} * will return {@link ExpirationModelType#UNKNOWN_TO_SDK_VERSION}. The raw value returned by the service is * available from {@link #expirationModelAsString}. *

* * @return Specifies whether the key material expires. The default is KEY_MATERIAL_EXPIRES. For help * with this choice, see Setting an expiration time in the Key Management Service Developer Guide.

*

* When the value of ExpirationModel is KEY_MATERIAL_EXPIRES, you must specify a * value for the ValidTo parameter. When value is KEY_MATERIAL_DOES_NOT_EXPIRE, * you must omit the ValidTo parameter. *

*

* You cannot change the ExpirationModel or ValidTo values for the current import * after the request completes. To change either value, you must reimport the key material. * @see ExpirationModelType */ public final String expirationModelAsString() { return expirationModel; } @Override public Builder toBuilder() { return new BuilderImpl(this); } public static Builder builder() { return new BuilderImpl(); } public static Class serializableBuilderClass() { return BuilderImpl.class; } @Override public final int hashCode() { int hashCode = 1; hashCode = 31 * hashCode + super.hashCode(); hashCode = 31 * hashCode + Objects.hashCode(keyId()); hashCode = 31 * hashCode + Objects.hashCode(importToken()); hashCode = 31 * hashCode + Objects.hashCode(encryptedKeyMaterial()); hashCode = 31 * hashCode + Objects.hashCode(validTo()); hashCode = 31 * hashCode + Objects.hashCode(expirationModelAsString()); return hashCode; } @Override public final boolean equals(Object obj) { return super.equals(obj) && equalsBySdkFields(obj); } @Override public final boolean equalsBySdkFields(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (!(obj instanceof ImportKeyMaterialRequest)) { return false; } ImportKeyMaterialRequest other = (ImportKeyMaterialRequest) obj; return Objects.equals(keyId(), other.keyId()) && Objects.equals(importToken(), other.importToken()) && Objects.equals(encryptedKeyMaterial(), other.encryptedKeyMaterial()) && Objects.equals(validTo(), other.validTo()) && Objects.equals(expirationModelAsString(), other.expirationModelAsString()); } /** * 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 final String toString() { return ToString.builder("ImportKeyMaterialRequest").add("KeyId", keyId()).add("ImportToken", importToken()) .add("EncryptedKeyMaterial", encryptedKeyMaterial()).add("ValidTo", validTo()) .add("ExpirationModel", expirationModelAsString()).build(); } public final Optional getValueForField(String fieldName, Class clazz) { switch (fieldName) { case "KeyId": return Optional.ofNullable(clazz.cast(keyId())); case "ImportToken": return Optional.ofNullable(clazz.cast(importToken())); case "EncryptedKeyMaterial": return Optional.ofNullable(clazz.cast(encryptedKeyMaterial())); case "ValidTo": return Optional.ofNullable(clazz.cast(validTo())); case "ExpirationModel": return Optional.ofNullable(clazz.cast(expirationModelAsString())); default: return Optional.empty(); } } @Override public final List> sdkFields() { return SDK_FIELDS; } @Override public final Map> sdkFieldNameToField() { return SDK_NAME_TO_FIELD; } private static Function getter(Function g) { return obj -> g.apply((ImportKeyMaterialRequest) 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 KMS key that will be associated with the imported key material. This must be the same * KMS key specified in the KeyID parameter of the corresponding GetParametersForImport * request. The Origin of the KMS key must be EXTERNAL and its KeyState * must be PendingImport. *

*

* The KMS key can be a symmetric encryption KMS key, HMAC KMS key, asymmetric encryption KMS key, or asymmetric * signing KMS key, including a multi-Region * key of any supported type. You cannot perform this operation on a KMS key in a custom key store, or on a * KMS key in a different Amazon Web Services account. *

*

* Specify the key ID or key ARN of the KMS key. *

*

* For example: *

*
    *
  • *

    * Key ID: 1234abcd-12ab-34cd-56ef-1234567890ab *

    *
  • *
  • *

    * Key ARN: arn:aws:kms:us-east-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab *

    *
  • *
*

* To get the key ID and key ARN for a KMS key, use ListKeys or DescribeKey. *

* * @param keyId * The identifier of the KMS key that will be associated with the imported key material. This must be the * same KMS key specified in the KeyID parameter of the corresponding * GetParametersForImport request. The Origin of the KMS key must be * EXTERNAL and its KeyState must be PendingImport.

*

* The KMS key can be a symmetric encryption KMS key, HMAC KMS key, asymmetric encryption KMS key, or * asymmetric signing KMS key, including a multi-Region key of any supported * type. You cannot perform this operation on a KMS key in a custom key store, or on a KMS key in a * different Amazon Web Services account. *

*

* Specify the key ID or key ARN of the KMS key. *

*

* For example: *

*
    *
  • *

    * Key ID: 1234abcd-12ab-34cd-56ef-1234567890ab *

    *
  • *
  • *

    * Key ARN: arn:aws:kms:us-east-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab *

    *
  • *
*

* To get the key ID and key ARN for a KMS key, use ListKeys or DescribeKey. * @return Returns a reference to this object so that method calls can be chained together. */ Builder keyId(String keyId); /** *

* The import token that you received in the response to a previous GetParametersForImport request. It * must be from the same response that contained the public key that you used to encrypt the key material. *

* * @param importToken * The import token that you received in the response to a previous GetParametersForImport * request. It must be from the same response that contained the public key that you used to encrypt the * key material. * @return Returns a reference to this object so that method calls can be chained together. */ Builder importToken(SdkBytes importToken); /** *

* The encrypted key material to import. The key material must be encrypted under the public wrapping key that * GetParametersForImport returned, using the wrapping algorithm that you specified in the same * GetParametersForImport request. *

* * @param encryptedKeyMaterial * The encrypted key material to import. The key material must be encrypted under the public wrapping key * that GetParametersForImport returned, using the wrapping algorithm that you specified in the * same GetParametersForImport request. * @return Returns a reference to this object so that method calls can be chained together. */ Builder encryptedKeyMaterial(SdkBytes encryptedKeyMaterial); /** *

* The date and time when the imported key material expires. This parameter is required when the value of the * ExpirationModel parameter is KEY_MATERIAL_EXPIRES. Otherwise it is not valid. *

*

* The value of this parameter must be a future date and time. The maximum value is 365 days from the request * date. *

*

* When the key material expires, KMS deletes the key material from the KMS key. Without its key material, the * KMS key is unusable. To use the KMS key in cryptographic operations, you must reimport the same key material. *

*

* You cannot change the ExpirationModel or ValidTo values for the current import * after the request completes. To change either value, you must delete (DeleteImportedKeyMaterial) and * reimport the key material. *

* * @param validTo * The date and time when the imported key material expires. This parameter is required when the value of * the ExpirationModel parameter is KEY_MATERIAL_EXPIRES. Otherwise it is not * valid.

*

* The value of this parameter must be a future date and time. The maximum value is 365 days from the * request date. *

*

* When the key material expires, KMS deletes the key material from the KMS key. Without its key * material, the KMS key is unusable. To use the KMS key in cryptographic operations, you must reimport * the same key material. *

*

* You cannot change the ExpirationModel or ValidTo values for the current * import after the request completes. To change either value, you must delete * (DeleteImportedKeyMaterial) and reimport the key material. * @return Returns a reference to this object so that method calls can be chained together. */ Builder validTo(Instant validTo); /** *

* Specifies whether the key material expires. The default is KEY_MATERIAL_EXPIRES. For help with * this choice, see Setting an expiration time in the Key Management Service Developer Guide. *

*

* When the value of ExpirationModel is KEY_MATERIAL_EXPIRES, you must specify a value * for the ValidTo parameter. When value is KEY_MATERIAL_DOES_NOT_EXPIRE, you must * omit the ValidTo parameter. *

*

* You cannot change the ExpirationModel or ValidTo values for the current import * after the request completes. To change either value, you must reimport the key material. *

* * @param expirationModel * Specifies whether the key material expires. The default is KEY_MATERIAL_EXPIRES. For help * with this choice, see Setting an expiration time in the Key Management Service Developer Guide.

*

* When the value of ExpirationModel is KEY_MATERIAL_EXPIRES, you must specify * a value for the ValidTo parameter. When value is * KEY_MATERIAL_DOES_NOT_EXPIRE, you must omit the ValidTo parameter. *

*

* You cannot change the ExpirationModel or ValidTo values for the current * import after the request completes. To change either value, you must reimport the key material. * @see ExpirationModelType * @return Returns a reference to this object so that method calls can be chained together. * @see ExpirationModelType */ Builder expirationModel(String expirationModel); /** *

* Specifies whether the key material expires. The default is KEY_MATERIAL_EXPIRES. For help with * this choice, see Setting an expiration time in the Key Management Service Developer Guide. *

*

* When the value of ExpirationModel is KEY_MATERIAL_EXPIRES, you must specify a value * for the ValidTo parameter. When value is KEY_MATERIAL_DOES_NOT_EXPIRE, you must * omit the ValidTo parameter. *

*

* You cannot change the ExpirationModel or ValidTo values for the current import * after the request completes. To change either value, you must reimport the key material. *

* * @param expirationModel * Specifies whether the key material expires. The default is KEY_MATERIAL_EXPIRES. For help * with this choice, see Setting an expiration time in the Key Management Service Developer Guide.

*

* When the value of ExpirationModel is KEY_MATERIAL_EXPIRES, you must specify * a value for the ValidTo parameter. When value is * KEY_MATERIAL_DOES_NOT_EXPIRE, you must omit the ValidTo parameter. *

*

* You cannot change the ExpirationModel or ValidTo values for the current * import after the request completes. To change either value, you must reimport the key material. * @see ExpirationModelType * @return Returns a reference to this object so that method calls can be chained together. * @see ExpirationModelType */ Builder expirationModel(ExpirationModelType expirationModel); @Override Builder overrideConfiguration(AwsRequestOverrideConfiguration overrideConfiguration); @Override Builder overrideConfiguration(Consumer builderConsumer); } static final class BuilderImpl extends KmsRequest.BuilderImpl implements Builder { private String keyId; private SdkBytes importToken; private SdkBytes encryptedKeyMaterial; private Instant validTo; private String expirationModel; private BuilderImpl() { } private BuilderImpl(ImportKeyMaterialRequest model) { super(model); keyId(model.keyId); importToken(model.importToken); encryptedKeyMaterial(model.encryptedKeyMaterial); validTo(model.validTo); expirationModel(model.expirationModel); } public final String getKeyId() { return keyId; } public final void setKeyId(String keyId) { this.keyId = keyId; } @Override public final Builder keyId(String keyId) { this.keyId = keyId; return this; } public final ByteBuffer getImportToken() { return importToken == null ? null : importToken.asByteBuffer(); } public final void setImportToken(ByteBuffer importToken) { importToken(importToken == null ? null : SdkBytes.fromByteBuffer(importToken)); } @Override public final Builder importToken(SdkBytes importToken) { this.importToken = importToken; return this; } public final ByteBuffer getEncryptedKeyMaterial() { return encryptedKeyMaterial == null ? null : encryptedKeyMaterial.asByteBuffer(); } public final void setEncryptedKeyMaterial(ByteBuffer encryptedKeyMaterial) { encryptedKeyMaterial(encryptedKeyMaterial == null ? null : SdkBytes.fromByteBuffer(encryptedKeyMaterial)); } @Override public final Builder encryptedKeyMaterial(SdkBytes encryptedKeyMaterial) { this.encryptedKeyMaterial = encryptedKeyMaterial; return this; } public final Instant getValidTo() { return validTo; } public final void setValidTo(Instant validTo) { this.validTo = validTo; } @Override public final Builder validTo(Instant validTo) { this.validTo = validTo; return this; } public final String getExpirationModel() { return expirationModel; } public final void setExpirationModel(String expirationModel) { this.expirationModel = expirationModel; } @Override public final Builder expirationModel(String expirationModel) { this.expirationModel = expirationModel; return this; } @Override public final Builder expirationModel(ExpirationModelType expirationModel) { this.expirationModel(expirationModel == null ? null : expirationModel.toString()); return this; } @Override public Builder overrideConfiguration(AwsRequestOverrideConfiguration overrideConfiguration) { super.overrideConfiguration(overrideConfiguration); return this; } @Override public Builder overrideConfiguration(Consumer builderConsumer) { super.overrideConfiguration(builderConsumer); return this; } @Override public ImportKeyMaterialRequest build() { return new ImportKeyMaterialRequest(this); } @Override public List> sdkFields() { return SDK_FIELDS; } @Override public Map> sdkFieldNameToField() { return SDK_NAME_TO_FIELD; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy