[−][src]Struct lib3h_sodium::SodiumCryptoSystem
the libsodium (NaCl) implementation of lib3h_crypto_api::CryptoSystem
Examples
extern crate lib3h_crypto_api; use lib3h_crypto_api::{Buffer, CryptoSystem}; extern crate lib3h_sodium; use lib3h_sodium::{ SecureBuffer, SodiumCryptoSystem, }; // CryptoSystem is designed to be used through trait-objects like this: fn test(crypto: Box<dyn CryptoSystem>) { let mut seed = crypto.buf_new_secure(crypto.sign_seed_bytes()); crypto.randombytes_buf(&mut seed).unwrap(); let mut pubkey: Box<dyn Buffer> = Box::new(vec![0; crypto.sign_public_key_bytes()]); let mut seckey = crypto.buf_new_secure(crypto.sign_secret_key_bytes()); crypto.sign_seed_keypair(&seed, &mut pubkey, &mut seckey).unwrap(); let mut signature: Box<dyn Buffer> = Box::new(vec![0; crypto.sign_bytes()]); let message: Box<dyn Buffer> = Box::new(vec![1, 2, 3, 4]); let bad_message: Box<dyn Buffer> = Box::new(vec![4, 3, 2, 1]); crypto.sign( &mut signature, &message, &seckey).unwrap(); assert!(crypto.sign_verify( &signature, &message, &pubkey).unwrap()); assert!(!crypto.sign_verify( &signature, &bad_message, &pubkey).unwrap()); } fn main() { let crypto: Box<dyn CryptoSystem> = Box::new(SodiumCryptoSystem::new()); test(crypto); }
Methods
impl SodiumCryptoSystem
[src]
Trait Implementations
impl Clone for SodiumCryptoSystem
[src]
fn clone(&self) -> SodiumCryptoSystem
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl CryptoSystem for SodiumCryptoSystem
[src]
fn box_clone(&self) -> Box<dyn CryptoSystem>
[src]
fn as_crypto_system(&self) -> &dyn CryptoSystem
[src]
fn buf_new_secure(&self, size: usize) -> Box<dyn Buffer>
[src]
fn randombytes_buf(&self, buffer: &mut Box<dyn Buffer>) -> CryptoResult<()>
[src]
fn sign_seed_bytes(&self) -> usize
[src]
fn sign_public_key_bytes(&self) -> usize
[src]
fn sign_secret_key_bytes(&self) -> usize
[src]
fn sign_bytes(&self) -> usize
[src]
fn sign_seed_keypair(
&self,
seed: &Box<dyn Buffer>,
public_key: &mut Box<dyn Buffer>,
secret_key: &mut Box<dyn Buffer>
) -> CryptoResult<()>
[src]
&self,
seed: &Box<dyn Buffer>,
public_key: &mut Box<dyn Buffer>,
secret_key: &mut Box<dyn Buffer>
) -> CryptoResult<()>
fn sign_keypair(
&self,
public_key: &mut Box<dyn Buffer>,
secret_key: &mut Box<dyn Buffer>
) -> CryptoResult<()>
[src]
&self,
public_key: &mut Box<dyn Buffer>,
secret_key: &mut Box<dyn Buffer>
) -> CryptoResult<()>
fn sign(
&self,
signature: &mut Box<dyn Buffer>,
message: &Box<dyn Buffer>,
secret_key: &Box<dyn Buffer>
) -> CryptoResult<()>
[src]
&self,
signature: &mut Box<dyn Buffer>,
message: &Box<dyn Buffer>,
secret_key: &Box<dyn Buffer>
) -> CryptoResult<()>
fn sign_verify(
&self,
signature: &Box<dyn Buffer>,
message: &Box<dyn Buffer>,
public_key: &Box<dyn Buffer>
) -> CryptoResult<bool>
[src]
&self,
signature: &Box<dyn Buffer>,
message: &Box<dyn Buffer>,
public_key: &Box<dyn Buffer>
) -> CryptoResult<bool>
fn buf_new_insecure(
&self,
size: usize
) -> Box<dyn Buffer<Target = [u8]> + 'static>
[src]
&self,
size: usize
) -> Box<dyn Buffer<Target = [u8]> + 'static>
this is just a helper to create a sized boxed Vec as a Box Read more
Auto Trait Implementations
impl Send for SodiumCryptoSystem
impl Unpin for SodiumCryptoSystem
impl Sync for SodiumCryptoSystem
impl UnwindSafe for SodiumCryptoSystem
impl RefUnwindSafe for SodiumCryptoSystem
Blanket Implementations
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,