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:
systemzeroxorshift:SEEDchacha20:KEY[:IV], where the key is 64 hex digits and the IV is 16 hex digitsmaster: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: NonZeroU64Seed of the generator.
ChaCha20
See ChaCha20.
Fields
§
iv: [u8; 8]IV of the cipher, which is DEFAULT_IV without one.
Master
Master passphrase mode, see Master.
Fields
Implementations§
Trait Implementations§
Source§impl Clone for RandomDesc
impl Clone for RandomDesc
Source§impl Debug for RandomDesc
impl Debug for RandomDesc
Source§impl Default for RandomDesc
impl Default for RandomDesc
Source§impl<'de> Deserialize<'de> for RandomDesc
impl<'de> Deserialize<'de> for RandomDesc
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
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
impl FromStr for RandomDesc
Source§impl PartialEq for RandomDesc
impl PartialEq for RandomDesc
impl StructuralPartialEq for RandomDesc
Auto Trait Implementations§
impl Forget for RandomDesc
impl Freeze for RandomDesc
impl Move for RandomDesc
impl RefUnwindSafe for RandomDesc
impl Send for RandomDesc
impl Sync for RandomDesc
impl Unpin for RandomDesc
impl UnsafeUnpin for RandomDesc
impl UnwindSafe for RandomDesc
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more