Skip to main content

TequelEncrypt

Struct TequelEncrypt 

Source
pub struct TequelEncrypt {
    pub salt: String,
    pub iterations: u32,
}
Expand description

TequelEncrypt is a struct that controls Encryption, it uses Salt and Custom Iterations.

You use this struct to use encrypt in Tequel.

use tequel::encrypt::TequelEncrypt;
 
fn main() {
    let mut teq_encrypt: TequelEncrypt = TequelEncrypt::new();
}

Fields§

§salt: String§iterations: u32

Implementations§

Source§

impl TequelEncrypt

Source

pub fn new() -> Self

Source

pub fn with_salt(self, salt: &str) -> Self

Source

pub fn with_iteration(self, value: u32) -> Self

Source

pub fn encrypt( &mut self, data: &[u8], key: &str, ) -> Result<TequelEncryption, TequelError>

Encrypts a byte slice using the Tequel protocol with AVX2 acceleration.

This function implements a multi-layered transformation “ladder” based on internal constants, a random salt, and a user-provided key. It ensures data integrity by generating a MAC (Message Authentication Code) as part of the encryption process.

§Arguments
  • data - A byte slice (&[u8]) containing the plaintext to be encrypted.
  • key - A string slice that serves as the master key for the cipher derivation.
§Returns
  • Ok(TequelEncryption) - A struct containing the hex-encoded encrypted data, the salt used, and the integrity MAC.
  • Err(TequelError::EmptyKey) - If the provided key string is empty.
§Performance

On x86_64 systems supporting AVX2, this function processes data in 32-byte chunks using SIMD instructions. It automatically falls back to a scalar implementation for the remaining bytes or unsupported hardware.

§Example
use tequel::encrypt::TequelEncrypt;

let mut teq = TequelEncrypt::new();
let secret_data = b"Tequel: Weighted and Measured";
let master_key = "guard_the_gate";

if let Ok(encryption) = teq.encrypt(secret_data, master_key) {
    println!("Ciphertext: {}", encryption.encrypted_data);
    println!("MAC: {}", encryption.mac);
}
Source

pub fn decrypt( &mut self, tequel_encryption: &TequelEncryption, key: &str, ) -> Result<String, TequelError>

Decrypts a Tequel-encrypted structure and verifies its integrity.

This function performs a reverse transformation of the Tequel protocol, using AVX2 SIMD instructions when available. Before decryption, it reconstructs the MAC (Message Authentication Code) to ensure the ciphertext, salt, and key have not been tampered with.

§Arguments
  • tequel_encryption - A reference to the TequelEncryption struct containing the hex-encoded data, salt, and MAC.
  • key - The string slice key used during the original encryption process.
§Returns
  • Ok(String) - The original plaintext as a UTF-8 string.
  • Err(TequelError::InvalidMac) - If the calculated MAC does not match the provided one (Integrity violation).
  • Err(TequelError::InvalidUtf8) - If the decrypted bytes are not valid UTF-8.
  • Err(TequelError::InvalidHex) - If the input strings are not valid hex.
§Security

The function follows a “Verify-then-Decrypt” pattern. If the MAC check fails, the decryption logic is never executed, protecting against certain types of side-channel attacks.

§Example
use tequel::encrypt::TequelEncrypt;
 
fn main() {
 
    let mut teq = TequelEncrypt::new();
     
    let encrypted_obj = teq.encrypt(b"secret", "master_key").expect("Failed to encrypt");
    let decrypted = teq.decrypt(&encrypted_obj, "master_key")
        .expect("Failed to decrypt or verify data");

    println!("Decrypted content: {}", decrypted);
}

Trait Implementations§

Source§

impl Clone for TequelEncrypt

Source§

fn clone(&self) -> TequelEncrypt

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TequelEncrypt

Source§

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

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

impl Drop for TequelEncrypt

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl PartialEq for TequelEncrypt

Source§

fn eq(&self, other: &TequelEncrypt) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Zeroize for TequelEncrypt

Source§

fn zeroize(&mut self)

Zero out this object from memory using Rust intrinsics which ensure the zeroization operation is not “optimized away” by the compiler.
Source§

impl Eq for TequelEncrypt

Source§

impl StructuralPartialEq for TequelEncrypt

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.