Skip to main content

CryptoNative

Struct CryptoNative 

Source
pub struct CryptoNative;

Trait Implementations§

Source§

impl Clone for CryptoNative

Source§

fn clone(&self) -> CryptoNative

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 Crypto for CryptoNative

Source§

type Sha256Error = ()

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_text: &'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_bytes: &'a [u8; 32], rb: &'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_bytes: &'a [u8; 32], cipher: &'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_raw: &'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§

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

impl Debug for CryptoNative

Source§

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

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

impl PartialEq for CryptoNative

Source§

fn eq(&self, other: &CryptoNative) -> 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 StructuralPartialEq for CryptoNative

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V