Struct distant_core::SecretKey[][src]

pub struct SecretKey { /* fields omitted */ }
Expand description

A type to represent a secret key.

As default it will randomly generate a SecretKey of 32 bytes.

Errors:

An error will be returned if:

  • slice is empty.
  • length is 0.
  • length is not less than isize::MAX.

Panics:

A panic will occur if:

  • Failure to generate random bytes securely.

Security:

  • Avoid using unprotected_as_bytes() whenever possible, as it breaks all protections that the type implements.

  • The trait PartialEq<&'_ [u8]> is implemented for this type so that users are not tempted to call unprotected_as_bytes to compare this sensitive value to a byte slice. The trait is implemented in such a way that the comparison happens in constant time. Thus, users should prefer SecretType == &[u8] over SecretType.unprotected_as_bytes() == &[u8]. Examples are shown below. The examples apply to any type that implements PartialEq<&'_ [u8]>.

use orion::pwhash::Password;

// Initialize a password with 32 random bytes.
let password = Password::generate(32)?;

// Secure, constant-time comparison with a byte slice
assert!(password != &[0; 32][..]);

// Secure, constant-time comparison with another Password
assert!(password != Password::generate(32)?);

Implementations

Construct from a given byte slice.

Return the object as byte slice. Warning: Should not be used unless strictly needed. This breaks protections that the type implements.

Return the length of the object.

Randomly generate using a CSPRNG. Not available in no_std context.

Trait Implementations

Formats the value using the given formatter. Read more

Randomly generate using a CSPRNG with recommended size. Not available in no_std context.

Executes the destructor for this type. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

Should always be Self

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.