Struct FieldEncryption

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

FieldEncryption struct. Provides methods to encrypt values matching the input regex to a value matching the output regex (and to decrypt).

Both regular expressions must be finite, i.e. they must contain a bounded number of possible values - so no unbounded expressions such as .* or [0-9]+ are permitted.

Furthermore the number of possible values of the output regex must be equal to, or greater than, the number of possible values of the input regex, i.e. the ‘domain’ of the output regex must be greater than or equal to the ‘domain’ pf the input regex.

Implementations§

Source§

impl FieldEncryption

Source

pub fn new( input_regex: &str, output_regex: &str, key: &[u8], ) -> Result<Self, Error>

Create a new FieldEncryption instance.

§Arguments
  • input_regex - the regular expression that describes all inputs
  • output_regex - the regular expression that describes all outputs
  • key - the encryption key, must be at least 32 bytes
§Errors
  • InfiniteRegex - if either regex is infinite
  • OutputDomainTooSmall - if the domain of the output regex is < domain of the input regex
  • InvalidKeyLength - of the encryption key is too small
Source

pub fn encrypt(&self, input: &str) -> Result<String, Error>

Encrypts the supplied input.

§Errors
  • InvalidInput - if the specified value does not match the input regex
Source

pub fn decrypt(&self, input: &str) -> Result<String, Error>

Decrypts the supplied input.

§Errors
  • InvalidInput - if the specified value does not match the output regex

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