Struct Crypt

Source
pub struct Crypt {
    pub encrypted: String,
    /* private fields */
}
Expand description

Encryption struct.

Fields§

§encrypted: String

Stores encrypted data.

Implementations§

Source§

impl Crypt

Source

pub fn new() -> Self

Create new instance of Crypt object.

Source

pub fn set_salt(&mut self, salt: String) -> Result<(), NulError>

Set custom salt for encryption.

use libcrypt_rs::Crypt;
 
let mut engine = Crypt::new();
engine.set_salt("$1$N1TAWHQs".to_string()).expect("Setting custom salt failed");
 
println!("{}", engine.get_salt().unwrap());
Source

pub fn gen_salt(&mut self, encryption: Encryptions) -> Result<(), String>

Generate salt.

use libcrypt_rs::{Crypt, Encryptions};
 
let mut engine = Crypt::new();
engine.gen_salt(Encryptions::Sha256).expect("Salt generation failed");
 
println!("{}", engine.get_salt().unwrap());
Source

pub fn encrypt(&mut self, encrypt: String) -> Result<(), String>

Encrypt data. Encrypted data can be accessed in the encrypted field of Crypt struct.

use libcrypt_rs::{Crypt, Encryptions};
 
let mut engine = Crypt::new();
engine.gen_salt(Encryptions::Sha256).expect("Salt generation failed");
 
engine.encrypt("example_phrase".to_string()).expect("Encryption failed");
 
println!("Encrypted data: {}", engine.encrypted);
Source

pub fn get_salt(&self) -> Result<String, String>

salt is a private field of Crypt struct, using this function.

Auto Trait Implementations§

§

impl Freeze for Crypt

§

impl RefUnwindSafe for Crypt

§

impl Send for Crypt

§

impl Sync for Crypt

§

impl Unpin for Crypt

§

impl UnwindSafe for Crypt

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.