#[non_exhaustive]pub struct PublicKeyDiscoveryInput {
pub recipient_static_private_key: Option<Blob>,
}Expand description
Inputs for creating a PublicKeyDiscovery 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_static_private_key: Option<Blob>The sender’s private key. MUST be PEM encoded.
Implementations§
Source§impl PublicKeyDiscoveryInput
impl PublicKeyDiscoveryInput
Sourcepub fn recipient_static_private_key(&self) -> &Option<Blob>
pub fn recipient_static_private_key(&self) -> &Option<Blob>
The sender’s private key. MUST be PEM encoded.
Source§impl PublicKeyDiscoveryInput
impl PublicKeyDiscoveryInput
Sourcepub fn builder() -> PublicKeyDiscoveryInputBuilder
pub fn builder() -> PublicKeyDiscoveryInputBuilder
Creates a new builder-style object to manufacture PublicKeyDiscoveryInput.
Examples found in repository?
examples/keyring/ecdh/public_key_discovery_raw_ecdh_keyring_example.rs (line 128)
66pub async fn decrypt_with_keyring(
67 example_data: &str,
68 ecdh_curve_spec: EcdhCurveSpec,
69) -> Result<(), crate::BoxError> {
70 // 1. Instantiate the encryption SDK client.
71 // This builds the default client with the RequireEncryptRequireDecrypt commitment policy,
72 // which enforces that this client only encrypts using committing algorithm suites and enforces
73 // that this client will only decrypt encrypted messages that were created with a committing
74 // algorithm suite.
75 let esdk_config = AwsEncryptionSdkConfig::builder().build()?;
76 let esdk_client = esdk_client::Client::from_conf(esdk_config)?;
77
78 let mpl_config = MaterialProvidersConfig::builder().build()?;
79 let mpl = mpl_client::Client::from_conf(mpl_config)?;
80
81 // 2. Create encryption context.
82 // Remember that your encryption context is NOT SECRET.
83 // For more information, see
84 // https://docs.aws.amazon.com/encryption-sdk/latest/developer-guide/concepts.html#encryption-context
85 let encryption_context = HashMap::from([
86 ("encryption".to_string(), "context".to_string()),
87 ("is not".to_string(), "secret".to_string()),
88 ("but adds".to_string(), "useful metadata".to_string()),
89 (
90 "that can help you".to_string(),
91 "be confident that".to_string(),
92 ),
93 (
94 "the data you are handling".to_string(),
95 "is what you think it is".to_string(),
96 ),
97 ]);
98
99 // 3. You may provide your own ECC keys in the files located at
100 // - EXAMPLE_ECC_PRIVATE_KEY_FILENAME_RECIPIENT
101
102 // If you do not provide these files, running this example through this
103 // class' main method will generate three files required for all raw ECDH examples
104 // EXAMPLE_ECC_PRIVATE_KEY_FILENAME_SENDER, EXAMPLE_ECC_PRIVATE_KEY_FILENAME_RECIPIENT
105 // and EXAMPLE_ECC_PUBLIC_KEY_FILENAME_RECIPIENT for you.
106
107 // Do not use these files for any other purpose.
108 if should_generate_new_ecc_key_pair_discovery_raw_ecdh()? {
109 write_raw_ecdh_ecc_keys(ecdh_curve_spec)?;
110 }
111
112 // 4. Load keys from UTF-8 encoded PEM files.
113 let mut file = File::open(Path::new(EXAMPLE_ECC_PRIVATE_KEY_FILENAME_RECIPIENT))?;
114 let mut private_key_recipient_utf8_bytes = Vec::new();
115 file.read_to_end(&mut private_key_recipient_utf8_bytes)?;
116
117 // Generate the ciphertext
118 let ciphertext = get_ciphertext(
119 example_data,
120 ecdh_curve_spec,
121 encryption_context.clone(),
122 esdk_client.clone(),
123 mpl.clone(),
124 )
125 .await?;
126
127 // 5. Create the PublicKeyDiscoveryInput
128 let discovery_raw_ecdh_static_configuration_input = PublicKeyDiscoveryInput::builder()
129 // Must be a UTF8 PEM-encoded private key
130 .recipient_static_private_key(private_key_recipient_utf8_bytes)
131 .build()?;
132
133 let discovery_raw_ecdh_static_configuration = RawEcdhStaticConfigurations::PublicKeyDiscovery(
134 discovery_raw_ecdh_static_configuration_input,
135 );
136
137 // 6. Create the Public Key Discovery Raw ECDH keyring.
138
139 // Create the keyring.
140 // This keyring uses a discovery configuration. This configuration will check on decrypt
141 // if it is meant to decrypt the message by checking if the configured public key is stored on the message.
142 // The discovery configuration can only decrypt messages and CANNOT encrypt messages.
143 let discovery_raw_ecdh_keyring = mpl
144 .create_raw_ecdh_keyring()
145 .curve_spec(ecdh_curve_spec)
146 .key_agreement_scheme(discovery_raw_ecdh_static_configuration)
147 .send()
148 .await?;
149
150 // 7. Decrypt your encrypted data using the same keyring you used on encrypt.
151 let decryption_response = esdk_client
152 .decrypt()
153 .ciphertext(ciphertext)
154 .keyring(discovery_raw_ecdh_keyring)
155 // Provide the encryption context that was supplied to the encrypt method
156 .encryption_context(encryption_context)
157 .send()
158 .await?;
159
160 let decrypted_plaintext = decryption_response
161 .plaintext
162 .expect("Unable to unwrap plaintext from decryption response");
163
164 // 8. Demonstrate that the decrypted plaintext is identical to the original plaintext.
165 // (This is an example for demonstration; you do not need to do this in your own code.)
166 let plaintext = example_data.as_bytes();
167
168 assert_eq!(
169 decrypted_plaintext,
170 aws_smithy_types::Blob::new(plaintext),
171 "Decrypted plaintext should be identical to the original plaintext. Invalid decryption"
172 );
173
174 println!("Public Key Discovery Raw ECDH Keyring Example Completed Successfully");
175
176 Ok(())
177}Trait Implementations§
Source§impl Clone for PublicKeyDiscoveryInput
impl Clone for PublicKeyDiscoveryInput
Source§fn clone(&self) -> PublicKeyDiscoveryInput
fn clone(&self) -> PublicKeyDiscoveryInput
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 PublicKeyDiscoveryInput
impl Debug for PublicKeyDiscoveryInput
Source§impl PartialEq for PublicKeyDiscoveryInput
impl PartialEq for PublicKeyDiscoveryInput
impl StructuralPartialEq for PublicKeyDiscoveryInput
Auto Trait Implementations§
impl Freeze for PublicKeyDiscoveryInput
impl RefUnwindSafe for PublicKeyDiscoveryInput
impl Send for PublicKeyDiscoveryInput
impl Sync for PublicKeyDiscoveryInput
impl Unpin for PublicKeyDiscoveryInput
impl UnwindSafe for PublicKeyDiscoveryInput
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.