Struct FPE

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

Represents an instance of format preserving encryption

§Examples

use std::str::FromStr;
let modulus = botan::MPI::from_str("1000000000").unwrap();
let key = vec![0; 32];
let rounds = 16;
let compat_mode = false;
let fpe = botan::FPE::new_fe1(&modulus, &key, rounds, compat_mode).unwrap();
let input = botan::MPI::from_str("9392024").unwrap();
let tweak = vec![1,2,3,4,5];
let ctext = fpe.encrypt(&input, &tweak).unwrap();
assert!(ctext < modulus);
let ptext = fpe.decrypt(&ctext, &tweak).unwrap();
assert_eq!(ptext, input);

Implementations§

Source§

impl FPE

Source

pub fn new_fe1( modulus: &MPI, key: &[u8], rounds: usize, compat_mode: bool, ) -> Result<FPE>

Create a new FPE instance, FE1 scheme Rounds should be 16 or higher for best security

Source

pub fn encrypt(&self, x: &MPI, tweak: &[u8]) -> Result<MPI>

Encrypt value under the FPE scheme using provided tweak

Source

pub fn decrypt(&self, x: &MPI, tweak: &[u8]) -> Result<MPI>

Decrypt value under the FPE scheme using provided tweak

Trait Implementations§

Source§

impl Debug for FPE

Source§

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

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

impl Drop for FPE

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Send for FPE

Source§

impl Sync for FPE

Auto Trait Implementations§

§

impl Freeze for FPE

§

impl RefUnwindSafe for FPE

§

impl Unpin for FPE

§

impl UnwindSafe for FPE

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.