Cryptor

Struct Cryptor 

Source
pub struct Cryptor { /* private fields */ }
Expand description

A cryptor supporting all of the block and stream ciphers provided by the common crypto library.

let config = Config::RC4 { key: b"Key" };
assert_eq!(
    Cryptor::encrypt(&config, b"Plaintext").unwrap(),
    &[0xbb, 0xf3, 0x16, 0xe8, 0xd9, 0x40, 0xaf, 0x0a, 0xd3]
);

Implementations§

Source§

impl Cryptor

Source

pub fn new_encryptor<'a>(config: &Config<'a>) -> Result<Self, CryptorError>

Source

pub fn new_decryptor<'a>(config: &Config<'a>) -> Result<Self, CryptorError>

Source

pub fn update( &self, input: impl AsRef<[u8]>, output: &mut Vec<u8>, ) -> Result<(), CryptorError>

Encrypts the data and writes to the provided buffer. The buffer will be resized as required, and will be cleared on error.

Source

pub fn finish(self, output: &mut Vec<u8>) -> Result<(), CryptorError>

Finalises the encryption, returning any remaining data where appropriate. The cryptor cannot be used again.

Source§

impl Cryptor

Source

pub fn encrypt<'a>( config: &Config<'a>, input: impl AsRef<[u8]>, ) -> Result<Vec<u8>, CryptorError>

Source

pub fn decrypt<'a>( config: &Config<'a>, input: impl AsRef<[u8]>, ) -> Result<Vec<u8>, CryptorError>

Trait Implementations§

Source§

impl Debug for Cryptor

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> Drop for Cryptor

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

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, 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.