Skip to main content

Subkey

Struct Subkey 

Source
pub struct Subkey<'key> { /* private fields */ }
Expand description

Borrowed handle to a subkey. Behaves like a Key via Deref.

Implementations§

Source§

impl<'key> Subkey<'key>

Source

pub fn as_key(&self) -> &Key<'key>

Borrow the underlying Key. Useful when an API wants a &Key explicitly.

Source

pub fn into_key(self) -> Key<'key>

Consume into the underlying Key.

Methods from Deref<Target = Key<'key>>§

Source

pub fn export(&self, flags: ExportFlags) -> Result<Vec<u8>>

Export this key as raw bytes. Pass ExportFlags::ARMORED for ASCII armor, otherwise binary OpenPGP packets are produced.

Source

pub fn raw_public_data(&self) -> Result<Vec<u8>>

Source

pub fn raw_secret_data(&self) -> Result<Vec<u8>>

Source

pub fn export_autocrypt( &self, subkey: Option<&Key<'_>>, uid: Option<&str>, flags: ExportFlags, ) -> Result<Vec<u8>>

Export an Autocrypt-compatible form of this key (a single-UID public key suitable for inclusion in email headers). subkey may be None for the primary-only case.

Source

pub fn export_revocation( &self, flags: ExportFlags, reason: RevocationReason, hash: Hash, ) -> Result<Vec<u8>>

Export a revocation certificate for this key. The hash algorithm and revocation reason are configured by hash and reason; the password (if needed) is obtained from the configured password provider.

Source

pub fn primary_uid(&self) -> Result<Option<String>>

The key’s primary user id, if any.

Source

pub fn alg(&self) -> Result<String>

Algorithm name (e.g. "RSA", "EDDSA").

Source

pub fn bits(&self) -> Result<u32>

Key size in bits. Returns 0 for curves where the concept doesn’t apply.

Source

pub fn dsa_qbits(&self) -> Result<u32>

DSA q size in bits. Only meaningful for DSA keys.

Source

pub fn curve(&self) -> Result<Option<String>>

Curve name (e.g. "NIST P-256", "Ed25519"). Returns None if the algorithm is not curve-based.

Source

pub fn version(&self) -> Result<u32>

Key version (4 or 6 in current OpenPGP; legacy v3 possible).

Source

pub fn creation(&self) -> Result<u32>

Creation time, seconds since the Unix epoch.

Source

pub fn expiration(&self) -> Result<u32>

Expiration in seconds from creation. 0 means no expiration.

Source

pub fn keyid(&self) -> Result<String>

Hex keyid (e.g. "014F7B24CD14F2A5").

Source

pub fn fingerprint(&self) -> Result<String>

Hex fingerprint (40 chars for v4 SHA-1, 64 for v6 SHA-256).

Source

pub fn grip(&self) -> Result<String>

Hex key grip (librnp’s SHA-1-based identifier used for keyring lookups).

Source

pub fn primary_fprint(&self) -> Result<Option<String>>

Fingerprint of the primary key that this subkey belongs to. None if this is itself a primary.

Source

pub fn primary_grip(&self) -> Result<Option<String>>

Grip of the primary key that this subkey belongs to. None if this is itself a primary.

Source

pub fn allows_usage(&self, usage: KeyUsage) -> Result<bool>

Key usage flags word (ORed RNP_KEY_USAGE_* constants). Use Self::allows_usage to test individual usages.

Source

pub fn have_secret(&self) -> Result<bool>

Source

pub fn have_public(&self) -> Result<bool>

Source

pub fn is_primary(&self) -> Result<bool>

Source

pub fn is_sub(&self) -> Result<bool>

Source

pub fn is_valid(&self) -> Result<bool>

Source

pub fn is_revoked(&self) -> Result<bool>

Source

pub fn is_locked(&self) -> Result<bool>

Source

pub fn is_compromised(&self) -> Result<bool>

True if the key was revoked with a “key compromised” reason code. Wraps rnp_key_is_compromised. Upstream reports RNP_ERROR_BAD_PARAMETERS for keys that are not revoked at all; that case is reported as Ok(false) — the answer to “was it compromised?” is simply no.

Source

pub fn is_retired(&self) -> Result<bool>

True if the key was retired (revocation reason “no longer used”). Wraps rnp_key_is_retired; see Self::is_compromised for the not-revoked mapping.

Source

pub fn is_superseded(&self) -> Result<bool>

True if the key was superseded (revocation reason “superseded by another key”). Wraps rnp_key_is_superseded; see Self::is_compromised for the not-revoked mapping.

Source

pub fn uid_string_at(&self, idx: usize) -> Result<Option<String>>

The userid string at idx, without going through a Uid handle (the handle-returning variant is Self::uid_at). None when idx is out of range. Wraps rnp_key_get_uid_at.

Source

pub fn revocation_signature(&self) -> Result<Option<Signature<'_>>>

The key’s direct revocation signature, if the key is revoked. Wraps rnp_key_get_revocation_signature.

Source

pub fn is_protected(&self) -> Result<bool>

Source

pub fn valid_till(&self) -> Result<u32>

Last time the key is valid, as a 32-bit seconds-since-epoch. Returns u32::MAX if the key never expires.

Source

pub fn valid_till64(&self) -> Result<u64>

Same as Self::valid_till but 64-bit (y2038-safe).

Source

pub fn is_expired(&self) -> Result<bool>

Whether the key’s validity window has passed, as computed by librnp itself (accounts for self-signature expiry, not just the expiration field). Wraps rnp_key_is_expired.

Source

pub fn protection_type(&self) -> Result<String>

Source

pub fn protection_mode(&self) -> Result<String>

Source

pub fn protection_cipher(&self) -> Result<String>

Source

pub fn protection_hash(&self) -> Result<String>

Source

pub fn protection_iterations(&self) -> Result<usize>

Source

pub fn revocation_reason(&self) -> Result<Option<String>>

Textual reason for the key’s revocation, if any.

Source

pub fn revoker_count(&self) -> Result<usize>

Number of revokers (third-party keys authorized to revoke this key).

Source

pub fn revoker_at(&self, idx: usize) -> Result<String>

Revocation key specification at idx (a string of the form "1:FINGERPRINT").

Source

pub fn is_25519_bits_tweaked(&self) -> Result<bool>

Source

pub fn uid_count(&self) -> Result<usize>

Source

pub fn uid_at(&self, idx: usize) -> Result<Option<Uid<'_>>>

Source

pub fn uids(&self) -> Result<Vec<Uid<'_>>>

Source

pub fn subkey_count(&self) -> Result<usize>

Source

pub fn subkey_at(&self, idx: usize) -> Result<Option<Subkey<'_>>>

Source

pub fn subkeys(&self) -> Result<Vec<Subkey<'_>>>

Source

pub fn signature_count(&self) -> Result<usize>

Source

pub fn signature_at(&self, idx: usize) -> Result<Option<Signature<'_>>>

Source

pub fn signatures(&self) -> Result<Vec<Signature<'_>>>

Source

pub fn default_key_for(&self, usage: KeyUsage) -> Result<Option<Key<'_>>>

Find the default subkey for a given usage. Returns None if no subkey is suitable. Wraps rnp_key_get_default_key.

Source

pub fn to_json(&self, flags: JsonFlags) -> Result<String>

Source

pub fn packets_to_json( &self, secret: bool, flags: JsonDumpFlags, ) -> Result<String>

Source

pub fn protect(&self, options: &ProtectOptions) -> Result<()>

Protect (encrypt) the secret material with options.password.

Source

pub fn unprotect(&self, password: Option<&str>) -> Result<()>

Remove the secret-key protection. password is required if the key is protected; pass None to use the configured password provider.

Source

pub fn lock(&self) -> Result<()>

Lock the key — discard the in-memory decrypted secret material.

Source

pub fn unlock(&self, password: Option<&str>) -> Result<()>

Unlock the key (decrypt secret material in memory).

Source

pub fn add_uid(&self, uid: &str, options: &AddUidOptions) -> Result<()>

Add a user ID to this key. The key must be unlocked if protected.

Source

pub fn revoke(&self, reason: RevocationReason, hash: Hash) -> Result<()>

Revoke this key. The hash algorithm and reason are configured; if the secret key is locked, the password is obtained from the password provider.

Source

pub fn set_expiration(&self, seconds: u32) -> Result<()>

Update the key’s expiration. seconds is from creation. Requires an unlocked key.

Source

pub fn remove(&self, flags: RemoveFlags) -> Result<()>

Remove the key from its keyring.

Source

pub fn remove_signatures(&self, flags: RemoveSignaturesFlags) -> Result<()>

Remove signatures matching flags. The optional callback is not surfaced — callers can re-inspect remaining signatures after the call.

Source

pub fn set_25519_bits_tweak(&self) -> Result<()>

Apply the v6 25519 bit-tweak (HKP fingerprint masking).

Trait Implementations§

Source§

impl<'key> Deref for Subkey<'key>

Source§

type Target = Key<'key>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.

Auto Trait Implementations§

§

impl<'key> !RefUnwindSafe for Subkey<'key>

§

impl<'key> !Send for Subkey<'key>

§

impl<'key> !Sync for Subkey<'key>

§

impl<'key> !UnwindSafe for Subkey<'key>

§

impl<'key> Freeze for Subkey<'key>

§

impl<'key> Unpin for Subkey<'key>

§

impl<'key> UnsafeUnpin for Subkey<'key>

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> 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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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, <T as TryFrom<U>>::Error>

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.