pub struct Omnib { /* private fields */ }Expand description
An ObtextCodec implementation that takes format on enc operation and autodetects on dec operation. Unlike all other implementations (Ob, ZrbcxC32, .. .) it does not have a format stored internally.
This struct allows specifying the format (scheme + encoding) at enc call time, and automatically detects both scheme and encoding on dec calls. It is the only ObtextCodec implementation that does full format autodetection, all other implementations can only autodetect the scheme (e.g., upbc), but not the encoding (e.g., base32 or base64).
§Examples
let omb = Omnib::new(&key)?;
// Encode with explicit format
let ot1 = omb.enc("hello", "aasv.c32")?; // using explicit string
let ot2 = omb.enc("world", MOCK1_B64)?; // using format constant
// autodec detects both scheme and encoding
let pt1 = omb.autodec(&ot1)?;
let pt2 = omb.autodec(&ot2)?;Implementations§
Source§impl Omnib
impl Omnib
Sourcepub fn new(key_b64: &str) -> Result<Self, Error>
pub fn new(key_b64: &str) -> Result<Self, Error>
Create a new Omnib instance with a base64 key.
Sourcepub fn enc(
&self,
plaintext: &str,
format: impl IntoFormat,
) -> Result<String, Error>
pub fn enc( &self, plaintext: &str, format: impl IntoFormat, ) -> Result<String, Error>
Encrypt and encode plaintext with the specified format.
Accepts either a format string (&str) or a Format instance.
§Examples
let omb = Omnib::new(&key)?;
// Using format string
let ot1 = omb.enc("hello", "aasv.b64")?;
// Using Format instance
let ot2 = omb.enc("hello", Format::new(Scheme::Aasv, Encoding::B64))?;
// Using format constant
let ot3 = omb.enc("hello", AASV_B64)?;Sourcepub fn dec(
&self,
obtext: &str,
format: impl IntoFormat,
) -> Result<String, Error>
pub fn dec( &self, obtext: &str, format: impl IntoFormat, ) -> Result<String, Error>
Decode and decrypt obtext with the specified format.
Accepts either a format string (&str) or a Format instance.
§Examples
// Using format string
let pt1 = omb.dec(&ot, "aasv.b64")?;
// Using Format instance
let pt2 = omb.dec(&ot, Format::new(Scheme::Aasv, Encoding::B64))?;