Struct sequoia_openpgp::types::KeyFlags
source · [−]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
sourceimpl KeyFlags
impl KeyFlags
sourcepub fn normalized_eq(&self, other: &Self) -> bool
pub fn normalized_eq(&self, other: &Self) -> bool
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));
sourcepub fn get(&self, bit: usize) -> bool
pub fn get(&self, bit: usize) -> bool
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));
sourcepub fn set(self, bit: usize) -> Self
pub fn set(self, bit: usize) -> Self
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));
sourcepub fn clear(self, bit: usize) -> Self
pub fn clear(self, bit: usize) -> Self
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));
sourcepub fn for_certification(&self) -> bool
pub fn for_certification(&self) -> bool
This key may be used to certify other keys.
sourcepub fn set_certification(self) -> Self
pub fn set_certification(self) -> Self
Declares that this key may be used to certify other keys.
sourcepub fn clear_certification(self) -> Self
pub fn clear_certification(self) -> Self
Declares that this key may not be used to certify other keys.
sourcepub fn set_certification_to(self, value: bool) -> Self
pub fn set_certification_to(self, value: bool) -> Self
Declares whether this key may be used to certify other keys.
sourcepub fn for_signing(&self) -> bool
pub fn for_signing(&self) -> bool
This key may be used to sign data.
sourcepub fn set_signing(self) -> Self
pub fn set_signing(self) -> Self
Declares that this key may be used to sign data.
sourcepub fn clear_signing(self) -> Self
pub fn clear_signing(self) -> Self
Declares that this key may not be used to sign data.
sourcepub fn set_signing_to(self, value: bool) -> Self
pub fn set_signing_to(self, value: bool) -> Self
Declares whether this key may be used to sign data.
sourcepub fn for_transport_encryption(&self) -> bool
pub fn for_transport_encryption(&self) -> bool
This key may be used to encrypt communications.
sourcepub fn set_transport_encryption(self) -> Self
pub fn set_transport_encryption(self) -> Self
Declares that this key may be used to encrypt communications.
sourcepub fn clear_transport_encryption(self) -> Self
pub fn clear_transport_encryption(self) -> Self
Declares that this key may not be used to encrypt communications.
sourcepub fn set_transport_encryption_to(self, value: bool) -> Self
pub fn set_transport_encryption_to(self, value: bool) -> Self
Declares whether this key may be used to encrypt communications.
sourcepub fn for_storage_encryption(&self) -> bool
pub fn for_storage_encryption(&self) -> bool
This key may be used to encrypt storage.
sourcepub fn set_storage_encryption(self) -> Self
pub fn set_storage_encryption(self) -> Self
Declares that this key may be used to encrypt storage.
sourcepub fn clear_storage_encryption(self) -> Self
pub fn clear_storage_encryption(self) -> Self
Declares that this key may not be used to encrypt storage.
sourcepub fn set_storage_encryption_to(self, value: bool) -> Self
pub fn set_storage_encryption_to(self, value: bool) -> Self
Declares whether this key may be used to encrypt storage.
sourcepub fn for_authentication(&self) -> bool
pub fn for_authentication(&self) -> bool
This key may be used for authentication.
sourcepub fn set_authentication(self) -> Self
pub fn set_authentication(self) -> Self
Declares that this key may be used for authentication.
sourcepub fn clear_authentication(self) -> Self
pub fn clear_authentication(self) -> Self
Declares that this key may not be used for authentication.
sourcepub fn set_authentication_to(self, value: bool) -> Self
pub fn set_authentication_to(self, value: bool) -> Self
Declares whether this key may be used for authentication.
sourcepub fn is_split_key(&self) -> bool
pub fn is_split_key(&self) -> bool
The private component of this key may have been split using a secret-sharing mechanism.
sourcepub fn set_split_key(self) -> Self
pub fn set_split_key(self) -> Self
Declares that the private component of this key may have been split using a secret-sharing mechanism.
sourcepub fn clear_split_key(self) -> Self
pub fn clear_split_key(self) -> Self
Declares that the private component of this key has not been split using a secret-sharing mechanism.
sourcepub fn set_split_key_to(self, value: bool) -> Self
pub fn set_split_key_to(self, value: bool) -> Self
Declares whether the private component of this key may have been split using a secret-sharing mechanism.
sourcepub fn is_group_key(&self) -> bool
pub fn is_group_key(&self) -> bool
The private component of this key may be in possession of more than one person.
sourcepub fn set_group_key(self) -> Self
pub fn set_group_key(self) -> Self
Declares that the private component of this key is in possession of more than one person.
sourcepub fn clear_group_key(self) -> Self
pub fn clear_group_key(self) -> Self
Declares that the private component of this key should not be in possession of more than one person.
sourcepub fn set_group_key_to(self, value: bool) -> Self
pub fn set_group_key_to(self, value: bool) -> Self
Declares whether the private component of this key is in possession of more than one person.
Trait Implementations
sourceimpl Ord for KeyFlags
impl Ord for KeyFlags
sourceimpl PartialOrd<KeyFlags> for KeyFlags
impl PartialOrd<KeyFlags> for KeyFlags
sourcefn partial_cmp(&self, other: &KeyFlags) -> Option<Ordering>
fn partial_cmp(&self, other: &KeyFlags) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
impl Eq for KeyFlags
impl StructuralEq for KeyFlags
impl StructuralPartialEq for KeyFlags
Auto Trait Implementations
impl RefUnwindSafe for KeyFlags
impl Send for KeyFlags
impl Sync for KeyFlags
impl Unpin for KeyFlags
impl UnwindSafe for KeyFlags
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more