pub fn generate<R: CryptoRng + RngCore>(
        rng: &mut R,
        derivation_info: NewKeyOpts,
    ) -> Result<Self, Error> {
        let keynum = KeyNumber::generate(rng);

        let key_pair = ed25519_dalek::Keypair::generate(rng);

        let mut complete_key = {
            let skey = Zeroizing::new(key_pair.secret.to_bytes());
            let pkey = key_pair.public.to_bytes();

            let mut complete_key = Zeroizing::new([0u8; FULL_KEY_LEN]);
            complete_key[..32].copy_from_slice(skey.as_ref());
            complete_key[32..].copy_from_slice(&pkey);
            UnencryptedKey(complete_key)
        };

        let checksum = Self::calculate_checksum(&complete_key);

        let mut salt = [0; 16];
        rng.fill_bytes(&mut salt);

        let kdf_rounds = if let NewKeyOpts::Encrypted {
            passphrase,
            kdf_rounds,
        } = &derivation_info
        {
            let kdf_rounds = *kdf_rounds;
            Self::inner_kdf_mix(&mut complete_key.0[..32], kdf_rounds, &salt, passphrase)?;
            kdf_rounds
        } else {
            0
        };

        Ok(Self {
            public_key_alg: PKGALG,
            kdf_alg: KDFALG,
            kdf_rounds,
            salt,
            checksum,
            keynum,
            // The state of the key doesn't matter at this stage.
            complete_key: complete_key.0,
        })
    }
/// Generates a new random secret (private) key with the provided options.
///
/// # Errors
///
/// This only returns an error if the provided password was empty.
Generates a new random secret (private) key with the provided options.
Generates a new random secret ( private ) key with the provided options .
pub fn generate<R: CryptoRng + RngCore>(
        rng: &mut R,
        derivation_info: NewKeyOpts,
    ) -> Result<Self, Error> {
        let keynum = KeyNumber::generate(rng);
        let key_pair = ed25519_dalek::Keypair::generate(rng);
        let mut complete_key = {
            let skey = Zeroizing::new(key_pair.secret.to_bytes());
            let pkey = key_pair.public.to_bytes();
            let mut complete_key = Zeroizing::new([0u8; FULL_KEY_LEN]);
            complete_key[..32].copy_from_slice(skey.as_ref());
            complete_key[32..].copy_from_slice(&pkey);
            UnencryptedKey(complete_key)
        };
        let checksum = Self::calculate_checksum(&complete_key);
        let mut salt = [0; 16];
        rng.fill_bytes(&mut salt);
        let kdf_rounds = if let NewKeyOpts::Encrypted {
            passphrase,
            kdf_rounds,
        } = &derivation_info
        {
            let kdf_rounds = *kdf_rounds;
            Self::inner_kdf_mix(&mut complete_key.0[..32], kdf_rounds, &salt, passphrase)?;
            kdf_rounds
        } else {
            0
        };
        Ok(Self {
            public_key_alg: PKGALG,
            kdf_alg: KDFALG,
            kdf_rounds,
            salt,
            checksum,
            keynum,
            // The state of the key doesn't matter at this stage.
            complete_key: complete_key.0,
        })
    }
pub fn generate < R : CryptoRng + RngCore > ( rng : & mut R , derivation_info : NewKeyOpts , ) -> Result < Self , Error > { let keynum = KeyNumber :: generate ( rng ) ; let key_pair = ed25519_dalek :: Keypair :: generate ( rng ) ; let mut complete_key = { let skey = Zeroizing :: new ( key_pair . secret . to_bytes ( ) ) ; let pkey = key_pair . public . to_bytes ( ) ; let mut complete_key = Zeroizing :: new ( [ 0u8 ; FULL_KEY_LEN ] ) ; complete_key [ .. 32 ] . copy_from_slice ( skey . as_ref ( ) ) ; complete_key [ 32 .. ] . copy_from_slice ( & pkey ) ; UnencryptedKey ( complete_key ) } ; let checksum = Self :: calculate_checksum ( & complete_key ) ; let mut salt = [ 0 ; 16 ] ; rng . fill_bytes ( & mut salt ) ; let kdf_rounds = if let NewKeyOpts :: Encrypted { passphrase , kdf_rounds , } = & derivation_info { let kdf_rounds = * kdf_rounds ; Self :: inner_kdf_mix ( & mut complete_key . 0 [ .. 32 ] , kdf_rounds , & salt , passphrase ) ? ; kdf_rounds } else { 0 } ; Ok ( Self { public_key_alg : PKGALG , kdf_alg : KDFALG , kdf_rounds , salt , checksum , keynum , // The state of the key doesn't matter at this stage. complete_key : complete_key . 0 , } ) }
Generates a new random secret (private) key with the provided options.
Generates a new random secret ( private ) key with the provided options .
rng
&mut R
derivation_info
NewKeyOpts
rng
&mut R
derivation_info
NewKeyOpts
errors
This only returns an error if the provided password was empty.
This only returns an error if the provided password was empty .