Skip to main content

RandomDesc

Enum RandomDesc 

Source
pub enum RandomDesc {
    System,
    Zero,
    Xorshift {
        seed: NonZeroU64,
    },
    ChaCha20 {
        key: [u8; 32],
        iv: [u8; 8],
    },
    Master {
        version: u32,
        level: u32,
        passphrase: String,
        seed: Vec<u8>,
        domain: String,
        user: String,
    },
}
Expand description

Description of a source of randomness.

This is only data: it says which source to use, and with what. It is what a user chooses the source of randomness with, and is opened to get the Random source. It defaults to the System randomness generator.

§Syntax

A description can be parsed from a string, in the syntax of the C implementation:

  • system
  • zero
  • xorshift:SEED
  • chacha20:KEY[:IV], where the key is 64 hex digits and the IV is 16 hex digits
  • master:VERSION:LEVEL:PASSPHRASE:SEED:DOMAIN:USER, which is the master passphrase mode. All six parts have to be there. The seed (in hex), the domain and the user can be empty. In the passphrase, the domain and the user, a colon is written as \: and a backslash as \\.
use passgen::random::*;

let desc: RandomDesc = "xorshift:1234".parse().unwrap();
let random = desc.open().unwrap();
assert_eq!(random.stream(0).below(100), 91);

It can also be deserialized, for use in configuration files. This uses a structured form (and not the syntax above): "system", or {"xorshift": {"seed": 1234}}.

Variants§

§

System

See System.

§

Zero

See Zero.

§

Xorshift

See Xorshift.

Fields

§seed: NonZeroU64

Seed of the generator.

§

ChaCha20

See ChaCha20.

Fields

§key: [u8; 32]

Key of the cipher.

§iv: [u8; 8]

IV of the cipher, which is DEFAULT_IV without one.

§

Master

Master passphrase mode, see Master.

Fields

§version: u32

How keys are derived.

§level: u32

How much effort deriving the master key takes.

§passphrase: String

The master passphrase.

§seed: Vec<u8>

The seed, which is empty when there is none.

§domain: String

What the passphrases are for, such as the name of a website. Can be empty.

§user: String

Who the passphrases are for, such as the name of an account. Can be empty.

Implementations§

Source§

impl RandomDesc

Source

pub fn is_secret(input: &str) -> bool

Whether a description has a secret in it (a key or a master passphrase), going by how it starts. This also works for one that cannot be parsed, so that an error about it does not have to show it.

Source

pub fn open(&self) -> Result<Random, Error>

Creates the source of randomness that this describes.

For the master passphrase mode, this is what derives the key, which takes a while.

Trait Implementations§

Source§

impl Clone for RandomDesc

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RandomDesc

Source§

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

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

impl Default for RandomDesc

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for RandomDesc

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl FromStr for RandomDesc

Source§

type Err = ParseError

The associated error which can be returned from parsing.
Source§

fn from_str(input: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl PartialEq for RandomDesc

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for RandomDesc

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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> Is for T
where T: ?Sized,

Source§

type EqTo = T

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.