[][src]Struct tox_encryptsave::PassKey

pub struct PassKey { /* fields omitted */ }

Key and Salt that are used to encrypt/decrypt data.

Implementations

impl PassKey[src]

pub fn from_passphrase(passphrase: &[u8]) -> Result<PassKey, KeyDerivationError>[src]

Create a new PassKey with a random Salt.

Note that passphrase memory is not being zeroed after it has been used. Code that provides passphrase should take care of zeroing that memory.

Can fail for the same reasons as PassKey::with_salt() (./struct.PassKey.html#method.with_salt), that is:

  • passphrase is empty
  • deriving key failed (can happen due to OOM)

E.g.

use tox_encryptsave::*;

// fails with an empty passphrase
assert_eq!(PassKey::from_passphrase(&[]), Err(KeyDerivationError::Null));

pub fn with_salt(
    passphrase: &[u8],
    salt: Salt
) -> Result<PassKey, KeyDerivationError>
[src]

Create a new PassKey with provided Salt, rather than using a random one.

Note that passphrase memory is not being zeroed after it has been used. Code that provides passphrase should take care of zeroing that memory.

Fails when:

  • passphrase is empty
  • deriving key failed (can happen due to OOM)

E.g.

use tox_crypto::pwhash::gen_salt;
use tox_encryptsave::*;

assert_eq!(PassKey::with_salt(&[], gen_salt()), Err(KeyDerivationError::Null));

pub fn encrypt(&self, data: &[u8]) -> Result<Vec<u8>, EncryptionError>[src]

Encrypts provided data with self PassKey.

Encrypted data is bigger than supplied data by EXTRA_LENGTH (./constant.EXTRA_LENGTH.html).

Fails when:

  • provided data is empty

E.g.

use tox_encryptsave::*;

                                      // ↓ don't
let passkey = PassKey::from_passphrase(&[0]).expect("Failed to unwrap PassKey!");

assert_eq!(passkey.encrypt(&[]), Err(EncryptionError::Null));

pub fn decrypt(&self, data: &[u8]) -> Result<Vec<u8>, DecryptionError>[src]

Decrypts provided data with self PassKey.

Decrypted data is smaller by EXTRA_LENGTH than encrypted data.

Fails when:

  • provided data is empty
  • size of provided data is less than EXTRA_LENGTH
  • format of provided data is wrong
  • decrypting data fails
    • could be due to OOM or by providing bytes that aren't encrypted after encrypted part

E.g.

use tox_encryptsave::*;

                                      // ↓ don't
let passkey = PassKey::from_passphrase(&[0]).expect("Failed to unwrap PassKey!");

// empty data
assert_eq!(passkey.decrypt(&[]), Err(DecryptionError::Null));

Trait Implementations

impl Clone for PassKey[src]

impl Debug for PassKey[src]

impl Eq for PassKey[src]

impl PartialEq<PassKey> for PassKey[src]

impl StructuralEq for PassKey[src]

impl StructuralPartialEq for PassKey[src]

Auto Trait Implementations

impl RefUnwindSafe for PassKey

impl Send for PassKey

impl Sync for PassKey

impl Unpin for PassKey

impl UnwindSafe for PassKey

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.