pub struct Features(_);
Expand description

Describes the features supported by an OpenPGP implementation.

The feature flags are defined in Section 5.2.3.24 of RFC 4880, and Section 5.2.3.25 of RFC 4880bis.

The feature flags are set by the user’s OpenPGP implementation to signal to any senders what features the implementation supports.

A note on equality

PartialEq compares the serialized form of the two feature sets. If you prefer to compare two feature sets for semantic equality, you should use Features::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();

match cert.with_policy(p, None)?.primary_userid()?.features() {
    Some(features) => {
        println!("Certificate holder's supported features:");
        assert!(features.supports_mdc());
        assert!(!features.supports_aead());
    }
    None => {
        println!("Certificate Holder did not specify any features.");
    }
}

Implementations§

Creates a new instance from bytes.

This does not remove any trailing padding from bytes.

Returns an empty feature set.

Returns a feature set describing Sequoia’s capabilities.

Compares two feature sets for semantic equality.

Features’ implementation of PartialEq compares two feature sets for serialized equality. That is, the PartialEq implementation considers two feature 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::Features;

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

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

Returns whether the specified feature flag is set.

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

// Feature flags 0 and 2.
let f = Features::new(&[0x5]);

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

Sets the specified feature flag.

This also clears any padding (trailing NUL bytes).

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

let f = Features::empty().set(0).set(2);

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

Clears the specified feature flag.

This also clears any padding (trailing NUL bytes).

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

let f = Features::empty().set(0).set(2).clear(2);

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

Returns whether the MDC feature flag is set.

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

let f = Features::empty();

assert!(! f.supports_mdc());

Sets the MDC feature flag.

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

let f = Features::empty().set_mdc();

assert!(f.supports_mdc());

Clears the MDC feature flag.

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

let f = Features::new(&[0x1]);
assert!(f.supports_mdc());

let f = f.clear_mdc();
assert!(! f.supports_mdc());

Returns whether the AEAD feature flag is set.

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

let f = Features::empty();

assert!(! f.supports_aead());

Sets the AEAD feature flag.

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

let f = Features::empty().set_aead();

assert!(f.supports_aead());

Clears the AEAD feature flag.

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

let f = Features::new(&[0x2]);
assert!(f.supports_aead());

let f = f.clear_aead();
assert!(! f.supports_aead());

Trait Implementations§

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 ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
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.