Struct sequoia_openpgp::types::KeyFlags
source · pub struct KeyFlags(/* private fields */);
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§
source§impl KeyFlags
impl KeyFlags
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 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 certification() -> Self
pub fn certification() -> Self
Returns a KeyFlags where the certificate flag is set.
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 transport_encryption() -> Self
pub fn transport_encryption() -> Self
Returns a KeyFlags where the transport encryption flag is set.
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 storage_encryption() -> Self
pub fn storage_encryption() -> Self
Returns a KeyFlags where the storage encryption flag is set.
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 authentication() -> Self
pub fn authentication() -> Self
Returns a KeyFlags where the authentication flag is set.
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§
source§impl Ord for KeyFlags
impl Ord for KeyFlags
source§impl PartialEq for KeyFlags
impl PartialEq for KeyFlags
source§impl PartialOrd for KeyFlags
impl PartialOrd for KeyFlags
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moreimpl Eq for KeyFlags
impl StructuralPartialEq for KeyFlags
Auto Trait Implementations§
impl Freeze for KeyFlags
impl RefUnwindSafe for KeyFlags
impl Send for KeyFlags
impl Sync for KeyFlags
impl Unpin for KeyFlags
impl UnwindSafe for KeyFlags
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)