pub struct Opener {}Expand description
Opener for bottles.
The Opener provides methods to decrypt and inspect bottles. It can decrypt bottles with multiple encryption layers, working from the outermost layer inward.
§Example
use rust_bottle::*;
use rand::rngs::OsRng;
let mut bottle = Bottle::new(b"Secret".to_vec());
let rng = &mut OsRng;
let key = X25519Key::generate(rng);
bottle.encrypt(rng, &key.public_key_bytes()).unwrap();
let opener = Opener::new();
let decrypted = opener.open(&bottle, Some(&key.private_key_bytes())).unwrap();Implementations§
Source§impl Opener
impl Opener
Sourcepub fn open(
&self,
bottle: &Bottle,
private_key: Option<&[u8]>,
) -> Result<Vec<u8>>
pub fn open( &self, bottle: &Bottle, private_key: Option<&[u8]>, ) -> Result<Vec<u8>>
Open a bottle, decrypting if needed.
This method decrypts all encryption layers sequentially, starting from the outermost layer and working inward. Each layer requires the appropriate private key.
§Arguments
bottle- The bottle to openprivate_key- Optional private key for decryption. Required if the bottle is encrypted.
§Returns
Ok(Vec<u8>)- The decrypted messageErr(BottleError::NoAppropriateKey)- If encryption exists but no key providedErr(BottleError::Decryption)- If decryption failsErr(BottleError::InvalidKeyType)- If the key format is invalid
§Note
For layered encryption, the same key is used for all layers in the current implementation. Future versions may support different keys per layer.
§Example
use rust_bottle::*;
use rand::rngs::OsRng;
let message = b"Hello, world!";
let mut bottle = Bottle::new(message.to_vec());
let rng = &mut OsRng;
let key = X25519Key::generate(rng);
bottle.encrypt(rng, &key.public_key_bytes()).unwrap();
let opener = Opener::new();
let decrypted = opener.open(&bottle, Some(&key.private_key_bytes())).unwrap();
assert_eq!(decrypted, message);Sourcepub fn open_info(&self, bottle: &Bottle) -> Result<BottleInfo>
pub fn open_info(&self, bottle: &Bottle) -> Result<BottleInfo>
Get information about a bottle without decrypting it.
This method provides metadata about encryption and signature status without requiring decryption keys. Useful for inspecting bottles before attempting to decrypt them.
§Arguments
bottle- The bottle to inspect
§Returns
Ok(BottleInfo)- Information about the bottle
§Example
use rust_bottle::*;
use rand::rngs::OsRng;
let mut bottle = Bottle::new(b"Message".to_vec());
let rng = &mut OsRng;
let key = Ed25519Key::generate(rng);
let pub_key = key.public_key_bytes();
bottle.sign(rng, &key, &pub_key).unwrap();
let opener = Opener::new();
let info = opener.open_info(&bottle).unwrap();
assert!(info.is_signed);
assert!(info.is_signed_by(&pub_key));Trait Implementations§
Auto Trait Implementations§
impl Freeze for Opener
impl RefUnwindSafe for Opener
impl Send for Opener
impl Sync for Opener
impl Unpin for Opener
impl UnwindSafe for Opener
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