pub struct Share(/* private fields */);Expand description
A cryptographic share that securely wraps a secret for a specific recipient
A Share contains an ephemeral public key and an AES-KW wrapped secret.
Only the intended recipient (whose public key was used during creation) can recover the secret.
§Wire Format
[ ephemeral_pubkey: 32 bytes ][ wrapped_secret: 40 bytes ]§Examples
// Alice wants to share a bucket secret with Bob
let bucket_secret = Secret::generate();
let bob_pubkey = bob_secret_key.public();
// Alice creates a share for Bob
let share = Share::new(&bucket_secret, &bob_pubkey)?;
// Bob can recover the secret using his private key
let recovered_secret = share.recover(&bob_secret_key)?;
assert_eq!(bucket_secret, recovered_secret);Implementations§
Sourcepub fn from_hex(hex: &str) -> Result<Self, ShareError>
pub fn from_hex(hex: &str) -> Result<Self, ShareError>
Parse a share from a hexadecimal string
Accepts both plain hex and “0x”-prefixed hex strings.
Sourcepub fn new(secret: &Secret, recipient: &PublicKey) -> Result<Self, ShareError>
pub fn new(secret: &Secret, recipient: &PublicKey) -> Result<Self, ShareError>
Create a new share that wraps a secret for a specific recipient
This uses ECDH + AES Key Wrap to securely share the secret:
- Generates an ephemeral Ed25519 keypair
- Converts both keys to X25519 for ECDH
- Performs ECDH to derive a shared secret
- Uses AES-KW to wrap the secret with the shared secret
- Returns a Share containing [ephemeral_pubkey || wrapped_secret]
§Arguments
secret- The secret to share (e.g., a bucket encryption key)recipient- The public key of the intended recipient
§Errors
Returns an error if key conversion or encryption fails.
Sourcepub fn recover(
&self,
recipient_secret: &SecretKey,
) -> Result<Secret, ShareError>
pub fn recover( &self, recipient_secret: &SecretKey, ) -> Result<Secret, ShareError>
Recover the wrapped secret using the recipient’s private key
This reverses the wrapping process:
- Extracts the ephemeral public key from the Share
- Converts keys to X25519 for ECDH
- Performs ECDH to derive the same shared secret
- Uses AES-KW to unwrap the secret
§Arguments
recipient_secret- The recipient’s private key (must match the public key used innew)
§Errors
Returns an error if:
- Key conversion fails
- AES-KW unwrapping fails (wrong key or corrupted data)
- Unwrapped secret has incorrect size
§Security Note
If this function returns an error, it means either the Share was created for a different recipient, the data was corrupted, or an attacker tampered with it.
Trait Implementations§
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Auto Trait Implementations§
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.