Skip to main content

CryptoImpl

Struct CryptoImpl 

Source
pub struct CryptoImpl;

Trait Implementations§

Source§

impl Crypto for CryptoStub

Source§

fn create_uuid() -> String

Generate a new UUID (version 4). Returns the UUID as a string.
Source§

fn random_bytes(length: usize) -> Vec<u8>

Generate length random bytes.
Source§

fn hash_sha256<'a>( _to_digest: &'a [u8], ) -> AsyncCryptoResult<'a, [u8; 32], Self::Sha256Error>

Compute the SHA-256 hash of the input data. Returns the 32-byte hash.
Source§

fn hkdf_sha256<'a>( _ikm: &'a [u8], _salt: &'a [u8], ) -> AsyncCryptoResult<'a, [u8; 32], Self::HkdfError>

Derive a 32-byte key from the input keying material and salt using HKDF-SHA256.
Source§

fn gen_ed25519<'a>() -> AsyncCryptoResult<'a, (Vec<u8>, Vec<u8>), Self::Ed25519GenError>

Generate a new Ed25519 key pair. Returns the public and private keys.
Source§

fn sig_ed25519<'a>( _pri_key: &'a [u8], _data: &'a [u8], ) -> AsyncCryptoResult<'a, [u8; 64], Self::Ed25519SignError>

Sign the given data using the provided Ed25519 private key. Returns the signature.
Source§

fn ver_ed25519<'a>( _pub_key: &'a [u8], _sig: &'a [u8], _data: &'a [u8], ) -> AsyncCryptoResult<'a, bool, Self::Ed25519VerifyError>

Verify the given Ed25519 signature against the provided public key and data. Returns true if the signature is valid, false if it is invalid.
Source§

fn aes_ctr_encrypt<'a>( _key: &'a [u8; 32], _iv: &'a [u8; 16], _plaintext: &'a [u8], ) -> AsyncCryptoResult<'a, Vec<u8>, Self::AesCtrError>

Encrypt the plaintext using AES-256 in CTR mode with the given key and IV. Returns the ciphertext.
Source§

fn aes_ctr_decrypt<'a>( _key: &'a [u8; 32], _iv: &'a [u8; 16], _cipher: &'a [u8], ) -> AsyncCryptoResult<'a, Vec<u8>, Self::AesCtrError>

Decrypt the ciphertext using AES-256 in CTR mode with the given key and IV. Returns the plaintext.
Source§

fn key_wrap_rfc3394<'a>( _kek: &'a [u8; 32], _key_to_wrap: &'a [u8; 32], ) -> AsyncCryptoResult<'a, [u8; 40], Self::KeyWrapError>

Wrap the given 32-byte key using the provided 32-byte KEK with the RFC3394 algorithm. Returns the wrapped key.
Source§

fn key_unwrap_rfc3394<'a>( _kek: &'a [u8; 32], _wrapped: &'a [u8; 40], ) -> AsyncCryptoResult<'a, [u8; 32], Self::KeyUnwrapError>

Unwrap the given 40-byte wrapped key using the provided 32-byte KEK with the RFC3394 algorithm. Returns the unwrapped key.
Source§

fn gen_x25519<'a>() -> AsyncCryptoResult<'a, ([u8; 44], [u8; 48]), Self::X25519GenError>

Generate a new X25519 key pair. Returns the public key as a base58 string and the private key as bytes.
Source§

fn derive_x25519<'a>( _pri_key: &'a [u8; 48], _peer_pub: &'a [u8; 44], ) -> AsyncCryptoResult<'a, [u8; 32], Self::X25519DeriveError>

Derive a shared secret using the X25519 key agreement protocol with the given private key and peer’s public key. Returns the derived 32-byte shared secret.
Source§

type Sha256Error = Sha256Error

Source§

fn dec_b58_32(data: &str) -> Result<[u8; 32], B58DecodeError>

Decode the given Base58 string into a 32-byte array. Returns an error if the input is not valid Base58 or does not decode to exactly 32 bytes.
Source§

type HkdfError = HkdfError

Source§

type Ed25519GenError = Ed25519GenError

Source§

type Ed25519SignError = Ed25519SignError

Source§

type Ed25519VerifyError = Ed25519VerifyError

Source§

type AesCtrError = AesCtrError

Source§

type KeyWrapError = KeyWrapError

Source§

type KeyUnwrapError = KeyUnwrapError

Source§

type X25519GenError = X25519GenError

Source§

type X25519DeriveError = X25519DeriveError

Source§

fn enc_b58(data: &[u8]) -> String

Encode the given bytes into a Base58 string.
Source§

fn dec_b58(data: &str) -> Result<Vec<u8>, B58DecodeError>

Decode the given Base58 string into bytes. Returns an error if the input is not valid Base58.

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. 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.