pub fn wrap_secret_v1(
secret: impl AsRef<[u8]>,
recipient_public_key: &P256PublicKeyCoordinates,
kid: &str,
class: &str,
public_key: Option<&P256PublicKeyCoordinates>,
policy: Option<Value>,
) -> Result<Value, WrappedSecretError>Examples found in repository?
examples/wrapped_audience.rs (lines 10-17)
6fn run() -> Result<(), Box<dyn std::error::Error>> {
7 let recipient = generate_p256_key_pair()?;
8 let outsider = generate_p256_key_pair()?;
9
10 let envelope = wrap_secret_v1(
11 "shared-audience-secret",
12 &recipient.public_key,
13 "apps.demo.keys.audience",
14 "identity-key",
15 Some(&recipient.public_key),
16 None,
17 )?;
18
19 let opened = unwrap_secret_v1(&envelope, &recipient.private_key, WrappedSecretOutput::Utf8)?;
20 assert_eq!(
21 opened,
22 WrappedSecretCleartext::Utf8("shared-audience-secret".to_string())
23 );
24
25 assert!(unwrap_secret_v1(&envelope, &outsider.private_key, WrappedSecretOutput::Utf8).is_err());
26
27 println!("wrapped audience key opens only for the recipient");
28 Ok(())
29}