pub struct Features(/* private fields */);
Expand description
Describes the features supported by an OpenPGP implementation.
The feature flags are defined in Section 5.2.3.32 of RFC 9580, and Section 5.2.3.32 of draft-ietf-openpgp-crypto-refresh.
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();
let (cert, _) =
CertBuilder::general_purpose(Some("alice@example.org"))
.generate()?;
match cert.with_policy(p, None)?.primary_userid()?.features() {
Some(features) => {
println!("Certificate holder's supported features:");
assert!(features.supports_seipdv1());
assert!(features.supports_seipdv2());
}
None => {
println!("Certificate Holder did not specify any features.");
}
}
Implementations§
Source§impl Features
impl Features
Sourcepub fn new<B>(bytes: B) -> Self
pub fn new<B>(bytes: B) -> Self
Creates a new instance from bytes
.
This does not remove any trailing padding from bytes
.
Sourcepub fn as_bitfield(&self) -> &Bitfield
pub fn as_bitfield(&self) -> &Bitfield
Returns a reference to the underlying Bitfield
.
Sourcepub fn as_bitfield_mut(&mut self) -> &mut Bitfield
pub fn as_bitfield_mut(&mut self) -> &mut Bitfield
Returns a mutable reference to the underlying Bitfield
.
Sourcepub fn normalized_eq(&self, other: &Self) -> bool
pub fn normalized_eq(&self, other: &Self) -> bool
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));
Sourcepub fn get(&self, bit: usize) -> bool
pub fn get(&self, bit: usize) -> bool
Returns whether the specified feature flag is set.
§Examples
use sequoia_openpgp as openpgp;
use openpgp::types::Features;
// Feature flags 0 and 3.
let f = Features::new(&[0x9]);
assert!(f.get(0));
assert!(! f.get(1));
assert!(! f.get(2));
assert!(f.get(3));
assert!(! f.get(4));
assert!(! f.get(8));
assert!(! f.get(80));
Sourcepub fn set(self, bit: usize) -> Self
pub fn set(self, bit: usize) -> Self
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(3);
assert!(f.get(0));
assert!(! f.get(1));
assert!(! f.get(2));
assert!(f.get(3));
assert!(! f.get(4));
assert!(! f.get(8));
assert!(! f.get(80));
Sourcepub fn clear(self, bit: usize) -> Self
pub fn clear(self, bit: usize) -> Self
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(3).clear(3);
assert!(f.get(0));
assert!(! f.get(1));
assert!(! f.get(2));
assert!(! f.get(3));
Sourcepub fn supports_seipdv1(&self) -> bool
pub fn supports_seipdv1(&self) -> bool
Returns whether the SEIPDv1 feature flag is set.
§Examples
use sequoia_openpgp as openpgp;
use openpgp::types::Features;
let f = Features::empty();
assert!(! f.supports_seipdv1());
Sourcepub fn set_seipdv1(self) -> Self
pub fn set_seipdv1(self) -> Self
Sets the SEIPDv1 feature flag.
§Examples
use sequoia_openpgp as openpgp;
use openpgp::types::Features;
let f = Features::empty().set_seipdv1();
assert!(f.supports_seipdv1());
Sourcepub fn clear_seipdv1(self) -> Self
pub fn clear_seipdv1(self) -> Self
Clears the SEIPDv1 feature flag.
§Examples
use sequoia_openpgp as openpgp;
use openpgp::types::Features;
let f = Features::new(&[0x1]);
assert!(f.supports_seipdv1());
let f = f.clear_seipdv1();
assert!(! f.supports_seipdv1());
Sourcepub fn supports_seipdv2(&self) -> bool
pub fn supports_seipdv2(&self) -> bool
Returns whether the SEIPDv2 feature flag is set.
§Examples
use sequoia_openpgp as openpgp;
use openpgp::types::Features;
let f = Features::empty();
assert!(! f.supports_seipdv2());
Sourcepub fn set_seipdv2(self) -> Self
pub fn set_seipdv2(self) -> Self
Sets the SEIPDv2 feature flag.
§Examples
use sequoia_openpgp as openpgp;
use openpgp::types::Features;
let f = Features::empty().set_seipdv2();
assert!(f.supports_seipdv2());
Sourcepub fn clear_seipdv2(self) -> Self
pub fn clear_seipdv2(self) -> Self
Clears the SEIPDv2 feature flag.
§Examples
use sequoia_openpgp as openpgp;
use openpgp::types::Features;
let f = Features::new(&[0x8]);
assert!(f.supports_seipdv2());
let f = f.clear_seipdv2();
assert!(! f.supports_seipdv2());