#[non_exhaustive]pub struct EphemeralPrivateKeyToStaticPublicKeyInput {
pub recipient_public_key: Option<Blob>,
}Expand description
Inputs for creating a EphemeralPrivateKeyToStaticPublicKey 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_public_key: Option<Blob>The recipient’s public key. MUST be DER encoded.
Implementations§
Source§impl EphemeralPrivateKeyToStaticPublicKeyInput
impl EphemeralPrivateKeyToStaticPublicKeyInput
Sourcepub fn recipient_public_key(&self) -> &Option<Blob>
pub fn recipient_public_key(&self) -> &Option<Blob>
The recipient’s public key. MUST be DER encoded.
Source§impl EphemeralPrivateKeyToStaticPublicKeyInput
impl EphemeralPrivateKeyToStaticPublicKeyInput
Sourcepub fn builder() -> EphemeralPrivateKeyToStaticPublicKeyInputBuilder
pub fn builder() -> EphemeralPrivateKeyToStaticPublicKeyInputBuilder
Creates a new builder-style object to manufacture EphemeralPrivateKeyToStaticPublicKeyInput.
Examples found in repository?
examples/keyring/ecdh/public_key_discovery_raw_ecdh_keyring_example.rs (line 219)
202async fn get_ciphertext(
203 example_data: &str,
204 ecdh_curve_spec: EcdhCurveSpec,
205 encryption_context: HashMap<String, String>,
206 esdk_client: esdk_client::Client,
207 mpl: mpl_client::Client,
208) -> Result<Blob, crate::BoxError> {
209 // 1. Load keys from UTF-8 encoded PEM files.
210
211 // Load public key from UTF-8 encoded PEM files into a DER encoded public key.
212 let public_key_file_content =
213 std::fs::read_to_string(Path::new(EXAMPLE_ECC_PUBLIC_KEY_FILENAME_RECIPIENT))?;
214 let parsed_public_key_file_content = parse(public_key_file_content)?;
215 let public_key_recipient_utf8_bytes = parsed_public_key_file_content.contents();
216
217 // 2. Create the EphemeralPrivateKeyToStaticPublicKeyInput to generate the ciphertext
218 let ephemeral_raw_ecdh_static_configuration_input =
219 EphemeralPrivateKeyToStaticPublicKeyInput::builder()
220 // Must be a UTF8 DER-encoded X.509 public key
221 .recipient_public_key(public_key_recipient_utf8_bytes)
222 .build()?;
223
224 let ephemeral_raw_ecdh_static_configuration =
225 RawEcdhStaticConfigurations::EphemeralPrivateKeyToStaticPublicKey(
226 ephemeral_raw_ecdh_static_configuration_input,
227 );
228
229 // 3. Create the Ephemeral Raw ECDH keyring.
230
231 // Create the keyring.
232 // This keyring uses an ephemeral configuration. This configuration will always create a new
233 // key pair as the sender key pair for the key agreement operation. The ephemeral configuration can only
234 // encrypt data and CANNOT decrypt messages.
235 let ephemeral_raw_ecdh_keyring = mpl
236 .create_raw_ecdh_keyring()
237 .curve_spec(ecdh_curve_spec)
238 .key_agreement_scheme(ephemeral_raw_ecdh_static_configuration)
239 .send()
240 .await?;
241
242 // 4. Encrypt the data with the encryption_context
243
244 // A raw ecdh keyring with Ephemeral configuration cannot decrypt data since the key pair
245 // used as the sender is ephemeral. This means that at decrypt time it does not have
246 // the private key that corresponds to the public key that is stored on the message.
247 let plaintext = example_data.as_bytes();
248
249 let encryption_response = esdk_client
250 .encrypt()
251 .plaintext(plaintext)
252 .keyring(ephemeral_raw_ecdh_keyring)
253 .encryption_context(encryption_context)
254 .send()
255 .await?;
256
257 let ciphertext = encryption_response
258 .ciphertext
259 .expect("Unable to unwrap ciphertext from encryption response");
260
261 // 5. Demonstrate that the ciphertext and plaintext are different.
262 // (This is an example for demonstration; you do not need to do this in your own code.)
263 assert_ne!(
264 ciphertext,
265 aws_smithy_types::Blob::new(plaintext),
266 "Ciphertext and plaintext data are the same. Invalid encryption"
267 );
268
269 Ok(ciphertext)
270}More examples
examples/keyring/ecdh/ephemeral_raw_ecdh_keyring_example.rs (line 108)
55pub async fn encrypt_with_keyring(
56 example_data: &str,
57 ecdh_curve_spec: EcdhCurveSpec,
58) -> Result<(), crate::BoxError> {
59 // 1. Instantiate the encryption SDK client.
60 // This builds the default client with the RequireEncryptRequireDecrypt commitment policy,
61 // which enforces that this client only encrypts using committing algorithm suites and enforces
62 // that this client will only decrypt encrypted messages that were created with a committing
63 // algorithm suite.
64 let esdk_config = AwsEncryptionSdkConfig::builder().build()?;
65 let esdk_client = esdk_client::Client::from_conf(esdk_config)?;
66
67 // 2. Create encryption context.
68 // Remember that your encryption context is NOT SECRET.
69 // For more information, see
70 // https://docs.aws.amazon.com/encryption-sdk/latest/developer-guide/concepts.html#encryption-context
71 let encryption_context = HashMap::from([
72 ("encryption".to_string(), "context".to_string()),
73 ("is not".to_string(), "secret".to_string()),
74 ("but adds".to_string(), "useful metadata".to_string()),
75 (
76 "that can help you".to_string(),
77 "be confident that".to_string(),
78 ),
79 (
80 "the data you are handling".to_string(),
81 "is what you think it is".to_string(),
82 ),
83 ]);
84
85 // 3. You may provide your own ECC keys in the files located at
86 // - EXAMPLE_ECC_PUBLIC_KEY_FILENAME_RECIPIENT
87
88 // If you do not provide these files, running this example through this
89 // class' main method will generate three files required for all raw ECDH examples
90 // EXAMPLE_ECC_PRIVATE_KEY_FILENAME_SENDER, EXAMPLE_ECC_PRIVATE_KEY_FILENAME_RECIPIENT
91 // and EXAMPLE_ECC_PUBLIC_KEY_FILENAME_RECIPIENT for you.
92
93 // Do not use these files for any other purpose.
94 if should_generate_new_ecc_key_pair_ephemeral_raw_ecdh()? {
95 write_raw_ecdh_ecc_keys(ecdh_curve_spec)?;
96 }
97
98 // 4. Load keys from UTF-8 encoded PEM files.
99
100 // Load public key from UTF-8 encoded PEM files into a DER encoded public key.
101 let public_key_file_content =
102 std::fs::read_to_string(Path::new(EXAMPLE_ECC_PUBLIC_KEY_FILENAME_RECIPIENT))?;
103 let parsed_public_key_file_content = parse(public_key_file_content)?;
104 let public_key_recipient_utf8_bytes = parsed_public_key_file_content.contents();
105
106 // 5. Create the EphemeralPrivateKeyToStaticPublicKeyInput
107 let ephemeral_raw_ecdh_static_configuration_input =
108 EphemeralPrivateKeyToStaticPublicKeyInput::builder()
109 // Must be a UTF8 DER-encoded X.509 public key
110 .recipient_public_key(public_key_recipient_utf8_bytes)
111 .build()?;
112
113 let ephemeral_raw_ecdh_static_configuration =
114 RawEcdhStaticConfigurations::EphemeralPrivateKeyToStaticPublicKey(
115 ephemeral_raw_ecdh_static_configuration_input,
116 );
117
118 // 6. Create the Ephemeral Raw ECDH keyring.
119 let mpl_config = MaterialProvidersConfig::builder().build()?;
120 let mpl = mpl_client::Client::from_conf(mpl_config)?;
121
122 // Create the keyring.
123 // This keyring uses an ephemeral configuration. This configuration will always create a new
124 // key pair as the sender key pair for the key agreement operation. The ephemeral configuration can only
125 // encrypt data and CANNOT decrypt messages.
126 let ephemeral_raw_ecdh_keyring = mpl
127 .create_raw_ecdh_keyring()
128 .curve_spec(ecdh_curve_spec)
129 .key_agreement_scheme(ephemeral_raw_ecdh_static_configuration)
130 .send()
131 .await?;
132
133 // 7. Encrypt the data with the encryption_context
134
135 // A raw ecdh keyring with Ephemeral configuration cannot decrypt data since the key pair
136 // used as the sender is ephemeral. This means that at decrypt time it does not have
137 // the private key that corresponds to the public key that is stored on the message.
138 let plaintext = example_data.as_bytes();
139
140 let encryption_response = esdk_client
141 .encrypt()
142 .plaintext(plaintext)
143 .keyring(ephemeral_raw_ecdh_keyring)
144 .encryption_context(encryption_context)
145 .send()
146 .await?;
147
148 let ciphertext = encryption_response
149 .ciphertext
150 .expect("Unable to unwrap ciphertext from encryption response");
151
152 // 8. Demonstrate that the ciphertext and plaintext are different.
153 // (This is an example for demonstration; you do not need to do this in your own code.)
154 assert_ne!(
155 ciphertext,
156 aws_smithy_types::Blob::new(plaintext),
157 "Ciphertext and plaintext data are the same. Invalid encryption"
158 );
159
160 println!("Ephemeral Raw ECDH Keyring Example Completed Successfully");
161
162 Ok(())
163}Trait Implementations§
Source§impl Clone for EphemeralPrivateKeyToStaticPublicKeyInput
impl Clone for EphemeralPrivateKeyToStaticPublicKeyInput
Source§fn clone(&self) -> EphemeralPrivateKeyToStaticPublicKeyInput
fn clone(&self) -> EphemeralPrivateKeyToStaticPublicKeyInput
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 PartialEq for EphemeralPrivateKeyToStaticPublicKeyInput
impl PartialEq for EphemeralPrivateKeyToStaticPublicKeyInput
Source§fn eq(&self, other: &EphemeralPrivateKeyToStaticPublicKeyInput) -> bool
fn eq(&self, other: &EphemeralPrivateKeyToStaticPublicKeyInput) -> bool
Tests for
self and other values to be equal, and is used by ==.impl StructuralPartialEq for EphemeralPrivateKeyToStaticPublicKeyInput
Auto Trait Implementations§
impl Freeze for EphemeralPrivateKeyToStaticPublicKeyInput
impl RefUnwindSafe for EphemeralPrivateKeyToStaticPublicKeyInput
impl Send for EphemeralPrivateKeyToStaticPublicKeyInput
impl Sync for EphemeralPrivateKeyToStaticPublicKeyInput
impl Unpin for EphemeralPrivateKeyToStaticPublicKeyInput
impl UnwindSafe for EphemeralPrivateKeyToStaticPublicKeyInput
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.