logo
pub struct KeyFlags(_);
Expand description

Describes how a key may be used, and stores additional information.

Key flags are described in Section 5.2.3.21 of RFC 4880 and Section 5.2.3.22 of RFC 4880bis.

A note on equality

PartialEq compares the serialized form of the key flag sets. If you prefer to compare two key flag sets for semantic equality, you should use KeyFlags::normalized_eq. The difference between semantic equality and serialized equality is that semantic equality ignores differences in the amount of padding.

Examples

use sequoia_openpgp as openpgp;
use openpgp::cert::prelude::*;
use openpgp::policy::StandardPolicy;

let p = &StandardPolicy::new();

let (cert, _) =
    CertBuilder::new()
        .add_userid("Alice <alice@example.com>")
        .add_transport_encryption_subkey()
        .generate()?;

for subkey in cert.with_policy(p, None)?.keys().subkeys() {
    // Key contains one Encryption subkey:
    assert!(subkey.key_flags().unwrap().for_transport_encryption());
}

Implementations

Creates a new instance from bits.

Returns a new KeyFlags with all capabilities disabled.

Returns a reference to the underlying Bitfield.

Returns a mutable reference to the underlying Bitfield.

Compares two key flag sets for semantic equality.

KeyFlags’ implementation of PartialEq compares two key flag sets for serialized equality. That is, the PartialEq implementation considers two key flag sets to not be equal if they have different amounts of padding. This comparison function ignores padding.

Examples
use sequoia_openpgp as openpgp;
use openpgp::types::KeyFlags;

let a = KeyFlags::new(&[0x1]);
let b = KeyFlags::new(&[0x1, 0x0]);

assert!(a != b);
assert!(a.normalized_eq(&b));

Returns whether the specified key flag is set.

Examples
use sequoia_openpgp as openpgp;
use openpgp::types::KeyFlags;

// Key flags 0 and 2.
let kf = KeyFlags::new(&[0x5]);

assert!(kf.get(0));
assert!(! kf.get(1));
assert!(kf.get(2));
assert!(! kf.get(3));
assert!(! kf.get(8));
assert!(! kf.get(80));

Sets the specified key flag.

This also clears any padding (trailing NUL bytes).

Examples
use sequoia_openpgp as openpgp;
use openpgp::types::KeyFlags;

let kf = KeyFlags::empty().set(0).set(2);

assert!(kf.get(0));
assert!(! kf.get(1));
assert!(kf.get(2));
assert!(! kf.get(3));

Clears the specified key flag.

This also clears any padding (trailing NUL bytes).

Examples
use sequoia_openpgp as openpgp;
use openpgp::types::KeyFlags;

let kf = KeyFlags::empty().set(0).set(2).clear(2);

assert!(kf.get(0));
assert!(! kf.get(1));
assert!(! kf.get(2));
assert!(! kf.get(3));

This key may be used to certify other keys.

Declares that this key may be used to certify other keys.

Declares that this key may not be used to certify other keys.

Declares whether this key may be used to certify other keys.

This key may be used to sign data.

Declares that this key may be used to sign data.

Declares that this key may not be used to sign data.

Declares whether this key may be used to sign data.

This key may be used to encrypt communications.

Declares that this key may be used to encrypt communications.

Declares that this key may not be used to encrypt communications.

Declares whether this key may be used to encrypt communications.

This key may be used to encrypt storage.

Declares that this key may be used to encrypt storage.

Declares that this key may not be used to encrypt storage.

Declares whether this key may be used to encrypt storage.

This key may be used for authentication.

Declares that this key may be used for authentication.

Declares that this key may not be used for authentication.

Declares whether this key may be used for authentication.

The private component of this key may have been split using a secret-sharing mechanism.

Declares that the private component of this key may have been split using a secret-sharing mechanism.

Declares that the private component of this key has not been split using a secret-sharing mechanism.

Declares whether the private component of this key may have been split using a secret-sharing mechanism.

The private component of this key may be in possession of more than one person.

Declares that the private component of this key is in possession of more than one person.

Declares that the private component of this key should not be in possession of more than one person.

Declares whether the private component of this key is in possession of more than one person.

Returns whether no flags are set.

Trait Implementations

Converts this type into a shared reference of the (usually inferred) input type.

The resulting type after applying the & operator.

Performs the & operation. Read more

The resulting type after applying the | operator.

Performs the | operation. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.