Omnib

Struct Omnib 

Source
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

Source

pub fn new(key_b64: &str) -> Result<Self, Error>

Create a new Omnib instance with a base64 key.

Source

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)?;
Source

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))?;
Source

pub fn autodec(&self, obtext: &str) -> Result<String, Error>

Decode+decrypt with automatic scheme and encoding detection.

§Examples
let ot = omb.enc("hello", "aasv.b64")?;
let pt2 = omb.autodec(&ot)?;  // Autodetects ob:aasv.b64
assert_eq!(pt2, "hello");
Source

pub fn key(&self) -> String

Get the key used by this instance.

Source

pub fn from_bytes(key_bytes: &[u8; 64]) -> Result<Self, Error>

Create a new Omnib instance from raw bytes.

Auto Trait Implementations§

§

impl Freeze for Omnib

§

impl RefUnwindSafe for Omnib

§

impl Send for Omnib

§

impl Sync for Omnib

§

impl Unpin for Omnib

§

impl UnwindSafe for Omnib

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V