#[non_exhaustive]pub struct KmsPublicKeyDiscoveryInput {
pub recipient_kms_identifier: Option<String>,
}Expand description
Inputs for creating a KmsPublicKeyDiscovery Configuration. This is a DECRYPT ONLY configuration.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.recipient_kms_identifier: Option<String>AWS KMS key identifier belonging to the recipient.
Implementations§
Source§impl KmsPublicKeyDiscoveryInput
impl KmsPublicKeyDiscoveryInput
Sourcepub fn recipient_kms_identifier(&self) -> &Option<String>
pub fn recipient_kms_identifier(&self) -> &Option<String>
AWS KMS key identifier belonging to the recipient.
Source§impl KmsPublicKeyDiscoveryInput
impl KmsPublicKeyDiscoveryInput
Sourcepub fn builder() -> KmsPublicKeyDiscoveryInputBuilder
pub fn builder() -> KmsPublicKeyDiscoveryInputBuilder
Creates a new builder-style object to manufacture KmsPublicKeyDiscoveryInput.
Examples found in repository?
examples/keyring/ecdh/kms_ecdh_discovery_keyring_example.rs (line 79)
43pub async fn decrypt_with_keyring(
44 example_data: &str,
45 ecdh_curve_spec: EcdhCurveSpec,
46 ecc_recipient_key_arn: &str,
47) -> Result<(), crate::BoxError> {
48 // 1. Instantiate the encryption SDK client.
49 // This builds the default client with the RequireEncryptRequireDecrypt commitment policy,
50 // which enforces that this client only encrypts using committing algorithm suites and enforces
51 // that this client will only decrypt encrypted messages that were created with a committing
52 // algorithm suite.
53 let esdk_config = AwsEncryptionSdkConfig::builder().build()?;
54 let esdk_client = esdk_client::Client::from_conf(esdk_config)?;
55
56 // 2. Create a KMS client.
57 let sdk_config = aws_config::load_defaults(aws_config::BehaviorVersion::latest()).await;
58 let kms_client = aws_sdk_kms::Client::new(&sdk_config);
59
60 // 3. Create encryption context.
61 // Remember that your encryption context is NOT SECRET.
62 // For more information, see
63 // https://docs.aws.amazon.com/encryption-sdk/latest/developer-guide/concepts.html#encryption-context
64 let encryption_context = HashMap::from([
65 ("encryption".to_string(), "context".to_string()),
66 ("is not".to_string(), "secret".to_string()),
67 ("but adds".to_string(), "useful metadata".to_string()),
68 (
69 "that can help you".to_string(),
70 "be confident that".to_string(),
71 ),
72 (
73 "the data you are handling".to_string(),
74 "is what you think it is".to_string(),
75 ),
76 ]);
77
78 // 4. Create the KmsPublicKeyDiscoveryInput
79 let kms_ecdh_discovery_static_configuration_input = KmsPublicKeyDiscoveryInput::builder()
80 .recipient_kms_identifier(ecc_recipient_key_arn)
81 .build()?;
82
83 let kms_ecdh_discovery_static_configuration =
84 KmsEcdhStaticConfigurations::KmsPublicKeyDiscovery(
85 kms_ecdh_discovery_static_configuration_input,
86 );
87
88 // 5. Create the KMS ECDH keyring.
89 let mpl_config = MaterialProvidersConfig::builder().build()?;
90 let mpl = mpl_client::Client::from_conf(mpl_config)?;
91
92 // Create a KMS ECDH Discovery keyring.
93 // This keyring uses the KmsPublicKeyDiscovery configuration.
94 // On encrypt, the keyring will fail as it is not allowed to encrypt data under this configuration.
95 // On decrypt, the keyring will check if its corresponding public key is stored in the message header. It
96 // will AWS KMS to derive the shared from the recipient's KMS ECC Key ARN and the sender's public key;
97 // For more information on this configuration see:
98 // https://docs.aws.amazon.com/encryption-sdk/latest/developer-guide/use-kms-ecdh-keyring.html#kms-ecdh-discovery
99 // This keyring takes in:
100 // - kmsClient
101 // - recipientKmsIdentifier: Must be an ARN representing a KMS ECC key meant for KeyAgreement
102 // - curveSpec: The curve name where the public keys lie
103 let kms_ecdh_discovery_keyring = mpl
104 .create_aws_kms_ecdh_keyring()
105 .kms_client(kms_client.clone())
106 .curve_spec(ecdh_curve_spec)
107 .key_agreement_scheme(kms_ecdh_discovery_static_configuration)
108 .send()
109 .await?;
110
111 // 6. Get ciphertext by creating a KMS ECDH keyring WITHOUT discovery
112 // because the KMS ECDH keyring WITH discovery CANNOT encrypt data.
113 let plaintext = example_data.as_bytes();
114
115 // Get ciphertext by creating a KMS ECDH keyring WITHOUT discovery.
116 // The recipient's public key used in the encrypting KMS ECDH keyring WITHOUT discovery
117 // is a public key generated from ecc_recipient_key_arn, the same ecc key used
118 // when creating the KMS ECDH keyring WITH discovery used for decryption in this example.
119 // We then decrypt this ciphertext using a KMS ECDH keyring WITH discovery
120 let ciphertext = get_ciphertext(
121 example_data,
122 encryption_context.clone(),
123 ecc_recipient_key_arn,
124 ecdh_curve_spec,
125 kms_client,
126 esdk_client.clone(),
127 )
128 .await?;
129
130 // 7. Decrypt your encrypted data using the same keyring you used on encrypt.
131 let decryption_response = esdk_client
132 .decrypt()
133 .ciphertext(ciphertext)
134 .keyring(kms_ecdh_discovery_keyring)
135 // Provide the encryption context that was supplied to the encrypt method
136 .encryption_context(encryption_context)
137 .send()
138 .await?;
139
140 let decrypted_plaintext = decryption_response
141 .plaintext
142 .expect("Unable to unwrap plaintext from decryption response");
143
144 // 8. Demonstrate that the decrypted plaintext is identical to the original plaintext.
145 // (This is an example for demonstration; you do not need to do this in your own code.)
146 assert_eq!(
147 decrypted_plaintext,
148 aws_smithy_types::Blob::new(plaintext),
149 "Decrypted plaintext should be identical to the original plaintext. Invalid decryption"
150 );
151
152 println!("KMS ECDH Discovery Keyring Example Completed Successfully");
153
154 Ok(())
155}Trait Implementations§
Source§impl Clone for KmsPublicKeyDiscoveryInput
impl Clone for KmsPublicKeyDiscoveryInput
Source§fn clone(&self) -> KmsPublicKeyDiscoveryInput
fn clone(&self) -> KmsPublicKeyDiscoveryInput
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for KmsPublicKeyDiscoveryInput
impl Debug for KmsPublicKeyDiscoveryInput
impl StructuralPartialEq for KmsPublicKeyDiscoveryInput
Auto Trait Implementations§
impl Freeze for KmsPublicKeyDiscoveryInput
impl RefUnwindSafe for KmsPublicKeyDiscoveryInput
impl Send for KmsPublicKeyDiscoveryInput
impl Sync for KmsPublicKeyDiscoveryInput
impl Unpin for KmsPublicKeyDiscoveryInput
impl UnwindSafe for KmsPublicKeyDiscoveryInput
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreCreates a shared type from an unshared type.