pub struct KeyBuilder { /* private fields */ }Expand description
Builder over rnp_op_generate_* for primary keys.
Terminal method KeyBuilder::build consumes self, executes the
generation, and returns the resulting Key.
let key = KeyBuilder::new(Algorithm::Rsa)
.bits(2048)
.userid("alice <alice@example.com>")
.hash(Hash::Sha256)
.add_usage(KeyUsage::Sign)
.add_usage(KeyUsage::Certify)
.build(&ctx)
.unwrap();Implementations§
Source§impl KeyBuilder
impl KeyBuilder
pub fn new(alg: Algorithm) -> Self
pub fn bits(self, n: u32) -> Self
pub fn hash(self, h: Hash) -> Self
pub fn dsa_qbits(self, n: u32) -> Self
pub fn curve(self, c: Curve) -> Self
pub fn userid(self, uid: impl Into<String>) -> Self
pub fn expiration(self, seconds: u32) -> Self
pub fn add_usage(self, u: KeyUsage) -> Self
pub fn add_pref_hash(self, h: Hash) -> Self
pub fn add_pref_cipher(self, c: Cipher) -> Self
pub fn add_pref_compression(self, c: Compression) -> Self
Sourcepub fn clear_usage(self) -> Self
pub fn clear_usage(self) -> Self
Clear all key usage flags. Equivalent to
rnp_op_generate_clear_usage: the builder defers every setter to
build time, so clearing the local vector is exactly the C-side
clear.
Sourcepub fn clear_pref_hash(self) -> Self
pub fn clear_pref_hash(self) -> Self
Clear all preferred hashes. Equivalent to
rnp_op_generate_clear_pref_hash (see Self::clear_usage for why
the local vector is cleared instead of the C-side state).
Sourcepub fn clear_pref_cipher(self) -> Self
pub fn clear_pref_cipher(self) -> Self
Clear all preferred ciphers. Equivalent to
rnp_op_generate_clear_pref_cipher (see Self::clear_usage).
Sourcepub fn clear_pref_compression(self) -> Self
pub fn clear_pref_compression(self) -> Self
Clear all preferred compressions.
Equivalent to rnp_op_generate_clear_pref_compression
(see Self::clear_usage).
pub fn pref_keyserver(self, s: impl Into<String>) -> Self
Sourcepub fn protection(self, opts: &ProtectOptions) -> Self
pub fn protection(self, opts: &ProtectOptions) -> Self
Apply protection (encryption of secret material) at generation
time. Takes the same ProtectOptions type used by
Key::protect — single canonical config.
Sourcepub fn request_password(self) -> Self
pub fn request_password(self) -> Self
Have librnp ask the configured password provider for the protection
password at execution time (instead of supplying it inline via
Self::protection).
Sourcepub fn v6(self) -> Self
pub fn v6(self) -> Self
Generate a v6 (RFC 9580) primary key instead of v4. Requires the
crypto-refresh Cargo feature and a librnp built with
ENABLE_CRYPTO_REFRESH=ON.
Sourcepub fn add_subkey(self, sub: SubkeyBuilder) -> Self
pub fn add_subkey(self, sub: SubkeyBuilder) -> Self
Add a subkey to be generated alongside the primary in
KeyBuilder::build.
The subkey is created after the primary key, with a binding signature. This is the idiomatic way to build a composite keypair (primary + signing subkey + encryption subkey) in one call.
KeyBuilder::new(Algorithm::Rsa)
.bits(2048)
.userid("alice")
.add_subkey(SubkeyBuilder::new(Algorithm::Rsa)
.bits(2048)
.add_usage(KeyUsage::EncryptComms))
.add_subkey(SubkeyBuilder::new(Algorithm::Eddsa)
.add_usage(KeyUsage::Sign));Sourcepub fn add_pqc_encryption_subkey(self, alg: PqcAlgorithm) -> Self
pub fn add_pqc_encryption_subkey(self, alg: PqcAlgorithm) -> Self
Add a PQC encryption subkey (e.g. ML-KEM-768+X25519).
Requires the pqc Cargo feature.
Sourcepub fn add_pqc_signing_subkey(self, alg: PqcAlgorithm) -> Self
pub fn add_pqc_signing_subkey(self, alg: PqcAlgorithm) -> Self
Add a PQC signing subkey (e.g. ML-DSA-65+ED25519).
Requires the pqc Cargo feature.