/*
* Copyright 2010-2016 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 com.amazonaws.services.kms.model;
import java.io.Serializable;
import com.amazonaws.AmazonWebServiceRequest;
/**
* <p>
* Decrypts ciphertext. Ciphertext is plaintext that has been previously
* encrypted by using any of the following functions:
* </p>
* <ul>
* <li>
* <p>
* <a>GenerateDataKey</a>
* </p>
* </li>
* <li>
* <p>
* <a>GenerateDataKeyWithoutPlaintext</a>
* </p>
* </li>
* <li>
* <p>
* <a>Encrypt</a>
* </p>
* </li>
* </ul>
* <p>
* Note that if a caller has been granted access permissions to all keys
* (through, for example, IAM user policies that grant <code>Decrypt</code>
* permission on all resources), then ciphertext encrypted by using keys in
* other accounts where the key grants access to the caller can be decrypted. To
* remedy this, we recommend that you do not grant <code>Decrypt</code> access
* in an IAM user policy. Instead grant <code>Decrypt</code> access only in key
* policies. If you must grant <code>Decrypt</code> access in an IAM user
* policy, you should scope the resource to specific keys or to specific trusted
* accounts.
* </p>
*/
public class DecryptRequest extends AmazonWebServiceRequest implements Serializable {
/**
* <p>
* Ciphertext to be decrypted. The blob includes metadata.
* </p>
* <p>
* <b>Constraints:</b><br/>
* <b>Length: </b>1 - 6144<br/>
*/
private java.nio.ByteBuffer ciphertextBlob;
/**
* <p>
* The encryption context. If this was specified in the <a>Encrypt</a>
* function, it must be specified here or the decryption operation will
* fail. For more information, see <a href=
* "http://docs.aws.amazon.com/kms/latest/developerguide/encrypt-context.html"
* >Encryption Context</a>.
* </p>
*/
private java.util.Map<String, String> encryptionContext = new java.util.HashMap<String, String>();
/**
* <p>
* A list of grant tokens.
* </p>
* <p>
* For more information, see <a href=
* "http://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#grant_token"
* >Grant Tokens</a> in the <i>AWS Key Management Service Developer
* Guide</i>.
* </p>
*/
private java.util.List<String> grantTokens = new java.util.ArrayList<String>();
/**
* <p>
* Ciphertext to be decrypted. The blob includes metadata.
* </p>
* <p>
* <b>Constraints:</b><br/>
* <b>Length: </b>1 - 6144<br/>
*
* @return <p>
* Ciphertext to be decrypted. The blob includes metadata.
* </p>
*/
public java.nio.ByteBuffer getCiphertextBlob() {
return ciphertextBlob;
}
/**
* <p>
* Ciphertext to be decrypted. The blob includes metadata.
* </p>
* <p>
* <b>Constraints:</b><br/>
* <b>Length: </b>1 - 6144<br/>
*
* @param ciphertextBlob <p>
* Ciphertext to be decrypted. The blob includes metadata.
* </p>
*/
public void setCiphertextBlob(java.nio.ByteBuffer ciphertextBlob) {
this.ciphertextBlob = ciphertextBlob;
}
/**
* <p>
* Ciphertext to be decrypted. The blob includes metadata.
* </p>
* <p>
* Returns a reference to this object so that method calls can be chained
* together.
* <p>
* <b>Constraints:</b><br/>
* <b>Length: </b>1 - 6144<br/>
*
* @param ciphertextBlob <p>
* Ciphertext to be decrypted. The blob includes metadata.
* </p>
* @return A reference to this updated object so that method calls can be
* chained together.
*/
public DecryptRequest withCiphertextBlob(java.nio.ByteBuffer ciphertextBlob) {
this.ciphertextBlob = ciphertextBlob;
return this;
}
/**
* <p>
* The encryption context. If this was specified in the <a>Encrypt</a>
* function, it must be specified here or the decryption operation will
* fail. For more information, see <a href=
* "http://docs.aws.amazon.com/kms/latest/developerguide/encrypt-context.html"
* >Encryption Context</a>.
* </p>
*
* @return <p>
* The encryption context. If this was specified in the
* <a>Encrypt</a> function, it must be specified here or the
* decryption operation will fail. For more information, see <a
* href=
* "http://docs.aws.amazon.com/kms/latest/developerguide/encrypt-context.html"
* >Encryption Context</a>.
* </p>
*/
public java.util.Map<String, String> getEncryptionContext() {
return encryptionContext;
}
/**
* <p>
* The encryption context. If this was specified in the <a>Encrypt</a>
* function, it must be specified here or the decryption operation will
* fail. For more information, see <a href=
* "http://docs.aws.amazon.com/kms/latest/developerguide/encrypt-context.html"
* >Encryption Context</a>.
* </p>
*
* @param encryptionContext <p>
* The encryption context. If this was specified in the
* <a>Encrypt</a> function, it must be specified here or the
* decryption operation will fail. For more information, see <a
* href=
* "http://docs.aws.amazon.com/kms/latest/developerguide/encrypt-context.html"
* >Encryption Context</a>.
* </p>
*/
public void setEncryptionContext(java.util.Map<String, String> encryptionContext) {
this.encryptionContext = encryptionContext;
}
/**
* <p>
* The encryption context. If this was specified in the <a>Encrypt</a>
* function, it must be specified here or the decryption operation will
* fail. For more information, see <a href=
* "http://docs.aws.amazon.com/kms/latest/developerguide/encrypt-context.html"
* >Encryption Context</a>.
* </p>
* <p>
* Returns a reference to this object so that method calls can be chained
* together.
*
* @param encryptionContext <p>
* The encryption context. If this was specified in the
* <a>Encrypt</a> function, it must be specified here or the
* decryption operation will fail. For more information, see <a
* href=
* "http://docs.aws.amazon.com/kms/latest/developerguide/encrypt-context.html"
* >Encryption Context</a>.
* </p>
* @return A reference to this updated object so that method calls can be
* chained together.
*/
public DecryptRequest withEncryptionContext(java.util.Map<String, String> encryptionContext) {
this.encryptionContext = encryptionContext;
return this;
}
/**
* <p>
* The encryption context. If this was specified in the <a>Encrypt</a>
* function, it must be specified here or the decryption operation will
* fail. For more information, see <a href=
* "http://docs.aws.amazon.com/kms/latest/developerguide/encrypt-context.html"
* >Encryption Context</a>.
* </p>
* <p>
* The method adds a new key-value pair into EncryptionContext parameter,
* and returns a reference to this object so that method calls can be
* chained together.
*
* @param key The key of the entry to be added into EncryptionContext.
* @param value The corresponding value of the entry to be added into
* EncryptionContext.
* @return A reference to this updated object so that method calls can be
* chained together.
*/
public DecryptRequest addEncryptionContextEntry(String key, String value) {
if (null == this.encryptionContext) {
this.encryptionContext = new java.util.HashMap<String, String>();
}
if (this.encryptionContext.containsKey(key))
throw new IllegalArgumentException("Duplicated keys (" + key.toString()
+ ") are provided.");
this.encryptionContext.put(key, value);
return this;
}
/**
* Removes all the entries added into EncryptionContext.
* <p>
* Returns a reference to this object so that method calls can be chained
* together.
*/
public DecryptRequest clearEncryptionContextEntries() {
this.encryptionContext = null;
return this;
}
/**
* <p>
* A list of grant tokens.
* </p>
* <p>
* For more information, see <a href=
* "http://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#grant_token"
* >Grant Tokens</a> in the <i>AWS Key Management Service Developer
* Guide</i>.
* </p>
*
* @return <p>
* A list of grant tokens.
* </p>
* <p>
* For more information, see <a href=
* "http://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#grant_token"
* >Grant Tokens</a> in the <i>AWS Key Management Service Developer
* Guide</i>.
* </p>
*/
public java.util.List<String> getGrantTokens() {
return grantTokens;
}
/**
* <p>
* A list of grant tokens.
* </p>
* <p>
* For more information, see <a href=
* "http://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#grant_token"
* >Grant Tokens</a> in the <i>AWS Key Management Service Developer
* Guide</i>.
* </p>
*
* @param grantTokens <p>
* A list of grant tokens.
* </p>
* <p>
* For more information, see <a href=
* "http://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#grant_token"
* >Grant Tokens</a> in the <i>AWS Key Management Service
* Developer Guide</i>.
* </p>
*/
public void setGrantTokens(java.util.Collection<String> grantTokens) {
if (grantTokens == null) {
this.grantTokens = null;
return;
}
this.grantTokens = new java.util.ArrayList<String>(grantTokens);
}
/**
* <p>
* A list of grant tokens.
* </p>
* <p>
* For more information, see <a href=
* "http://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#grant_token"
* >Grant Tokens</a> in the <i>AWS Key Management Service Developer
* Guide</i>.
* </p>
* <p>
* Returns a reference to this object so that method calls can be chained
* together.
*
* @param grantTokens <p>
* A list of grant tokens.
* </p>
* <p>
* For more information, see <a href=
* "http://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#grant_token"
* >Grant Tokens</a> in the <i>AWS Key Management Service
* Developer Guide</i>.
* </p>
* @return A reference to this updated object so that method calls can be
* chained together.
*/
public DecryptRequest withGrantTokens(String... grantTokens) {
if (getGrantTokens() == null) {
this.grantTokens = new java.util.ArrayList<String>(grantTokens.length);
}
for (String value : grantTokens) {
this.grantTokens.add(value);
}
return this;
}
/**
* <p>
* A list of grant tokens.
* </p>
* <p>
* For more information, see <a href=
* "http://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#grant_token"
* >Grant Tokens</a> in the <i>AWS Key Management Service Developer
* Guide</i>.
* </p>
* <p>
* Returns a reference to this object so that method calls can be chained
* together.
*
* @param grantTokens <p>
* A list of grant tokens.
* </p>
* <p>
* For more information, see <a href=
* "http://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#grant_token"
* >Grant Tokens</a> in the <i>AWS Key Management Service
* Developer Guide</i>.
* </p>
* @return A reference to this updated object so that method calls can be
* chained together.
*/
public DecryptRequest withGrantTokens(java.util.Collection<String> grantTokens) {
setGrantTokens(grantTokens);
return this;
}
/**
* Returns a string representation of this object; useful for testing and
* debugging.
*
* @return A string representation of this object.
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("{");
if (getCiphertextBlob() != null)
sb.append("CiphertextBlob: " + getCiphertextBlob() + ",");
if (getEncryptionContext() != null)
sb.append("EncryptionContext: " + getEncryptionContext() + ",");
if (getGrantTokens() != null)
sb.append("GrantTokens: " + getGrantTokens());
sb.append("}");
return sb.toString();
}
@Override
public int hashCode() {
final int prime = 31;
int hashCode = 1;
hashCode = prime * hashCode
+ ((getCiphertextBlob() == null) ? 0 : getCiphertextBlob().hashCode());
hashCode = prime * hashCode
+ ((getEncryptionContext() == null) ? 0 : getEncryptionContext().hashCode());
hashCode = prime * hashCode
+ ((getGrantTokens() == null) ? 0 : getGrantTokens().hashCode());
return hashCode;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (obj instanceof DecryptRequest == false)
return false;
DecryptRequest other = (DecryptRequest) obj;
if (other.getCiphertextBlob() == null ^ this.getCiphertextBlob() == null)
return false;
if (other.getCiphertextBlob() != null
&& other.getCiphertextBlob().equals(this.getCiphertextBlob()) == false)
return false;
if (other.getEncryptionContext() == null ^ this.getEncryptionContext() == null)
return false;
if (other.getEncryptionContext() != null
&& other.getEncryptionContext().equals(this.getEncryptionContext()) == false)
return false;
if (other.getGrantTokens() == null ^ this.getGrantTokens() == null)
return false;
if (other.getGrantTokens() != null
&& other.getGrantTokens().equals(this.getGrantTokens()) == false)
return false;
return true;
}
}