Skip to main content

XorCipher

Struct XorCipher 

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

Trivial XOR-stream cipher used as a mock. The “key schedule” is a single running byte derived by XOR-folding the supplied key; each input byte is XORed with that running byte. This is not secure cryptography — it exists only to exercise the full cipher FFI surface without pulling in a real cipher library.

Implementations§

Source§

impl XorCipher

Source

pub fn from_key_iv(key: &[u8], iv: &[u8]) -> Self

Construct from key + iv. The key is XOR-folded into a single byte; the IV is folded in on top so different IVs produce different keystreams for the same key.

Trait Implementations§

Source§

impl CipherPlugin for XorCipher

Source§

fn create_with_key( _algorithm: &str, key: &[u8], iv: &[u8], _opts: Option<OptionView<'_>>, ) -> PluginResult<Self>

Construct a new cipher instance for the named algorithm with the given key and IV. Either key or iv may be empty when the algorithm does not require them.
Source§

fn block_size(&self) -> u32

Block size in bytes for this instance.
Source§

fn key_size(&self) -> u32

Key length in bytes for this instance’s algorithm.
Source§

fn iv_size(&self) -> u32

IV / nonce length in bytes for this instance’s algorithm.
Source§

fn update(&mut self, input: &[u8], output: &mut [u8]) -> PluginResult<usize>

Process input and write as many output bytes as fit into output. Returns the number of bytes written. The caller guarantees output.len() is large enough to hold one block of ciphertext per block of input.
Source§

fn finalize(&mut self, _output: &mut [u8]) -> PluginResult<usize>

Flush any buffered output (e.g. the final partial block after padding) into output. Returns the number of bytes written.
Source§

fn reset(&mut self) -> PluginResult<()>

Reset to the initial state (post-create).

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.