Struct sequoia_openpgp::packet::user_attribute::UserAttribute
source · [−]pub struct UserAttribute { /* private fields */ }
Expand description
Holds a UserAttribute packet.
See Section 5.12 of RFC 4880 for details.
Implementations
sourceimpl UserAttribute
impl UserAttribute
sourcepub fn new(subpackets: &[Subpacket]) -> Result<Self>
pub fn new(subpackets: &[Subpacket]) -> Result<Self>
Returns a new UserAttribute
packet.
Note: a valid UserAttribute has at least one subpacket.
sourcepub fn hash_algo_security(&self) -> HashAlgoSecurity
pub fn hash_algo_security(&self) -> HashAlgoSecurity
The security requirements of the hash algorithm for self-signatures.
A cryptographic hash algorithm usually has three security properties: pre-image resistance, second pre-image resistance, and collision resistance. If an attacker can influence the signed data, then the hash algorithm needs to have both second pre-image resistance, and collision resistance. If not, second pre-image resistance is sufficient.
In general, an attacker may be able to influence third-party signatures. But direct key signatures, and binding signatures are only over data fully determined by signer. And, an attacker’s control over self signatures over User IDs is limited due to their structure.
These observations can be used to extend the life of a hash algorithm after its collision resistance has been partially compromised, but not completely broken. For more details, please refer to the documentation for HashAlgoSecurity.
sourcepub fn value(&self) -> &[u8]ⓘNotable traits for &[u8]impl<'_> Read for &[u8]impl<'_> Write for &mut [u8]
pub fn value(&self) -> &[u8]ⓘNotable traits for &[u8]impl<'_> Read for &[u8]impl<'_> Write for &mut [u8]
Gets the user attribute packet’s raw, unparsed value.
Most likely you will want to use subpackets()
to iterate
over the subpackets.
sourcepub fn value_mut(&mut self) -> &mut Vec<u8>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
pub fn value_mut(&mut self) -> &mut Vec<u8>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
Gets a mutable reference to the user attribute packet’s raw value.
sourcepub fn subpackets(&self) -> SubpacketIterator<'_>ⓘNotable traits for SubpacketIterator<'a>impl<'a> Iterator for SubpacketIterator<'a> type Item = Result<Subpacket>;
pub fn subpackets(&self) -> SubpacketIterator<'_>ⓘNotable traits for SubpacketIterator<'a>impl<'a> Iterator for SubpacketIterator<'a> type Item = Result<Subpacket>;
Iterates over the subpackets.
sourceimpl UserAttribute
impl UserAttribute
sourcepub fn bind(
&self,
signer: &mut dyn Signer,
cert: &Cert,
signature: SignatureBuilder
) -> Result<Signature>
pub fn bind(
&self,
signer: &mut dyn Signer,
cert: &Cert,
signature: SignatureBuilder
) -> Result<Signature>
Creates a binding signature.
The signature binds this user attribute to cert
. signer
will be used to create a signature using signature
as
builder. Thehash_algo
defaults to SHA512, creation_time
to the current time.
This function adds a creation time subpacket, a issuer fingerprint subpacket, and a issuer subpacket to the signature.
Examples
This example demonstrates how to bind this user attribute to a
Cert. Note that in general, the CertBuilder
is a better way
to add User IDs to a Cert.
// Generate a Cert, and create a keypair from the primary key.
let (cert, _) = CertBuilder::new()
.generate()?;
let mut keypair = cert.primary_key().key().clone()
.parts_into_secret()?.into_keypair()?;
assert_eq!(cert.userids().len(), 0);
// Generate a user attribute and a binding signature.
let user_attr = UserAttribute::new(&[
Subpacket::Image(
Image::Private(100, vec![0, 1, 2].into_boxed_slice())),
])?;
let builder =
signature::SignatureBuilder::new(SignatureType::PositiveCertification);
let binding = user_attr.bind(&mut keypair, &cert, builder)?;
// Now merge the user attribute and binding signature into the Cert.
let cert = cert.insert_packets(vec![Packet::from(user_attr),
binding.into()])?;
// Check that we have a user attribute.
assert_eq!(cert.user_attributes().count(), 1);
sourcepub fn certify<S, H, T>(
&self,
signer: &mut dyn Signer,
cert: &Cert,
signature_type: S,
hash_algo: H,
creation_time: T
) -> Result<Signature> where
S: Into<Option<SignatureType>>,
H: Into<Option<HashAlgorithm>>,
T: Into<Option<SystemTime>>,
pub fn certify<S, H, T>(
&self,
signer: &mut dyn Signer,
cert: &Cert,
signature_type: S,
hash_algo: H,
creation_time: T
) -> Result<Signature> where
S: Into<Option<SignatureType>>,
H: Into<Option<HashAlgorithm>>,
T: Into<Option<SystemTime>>,
Returns a certification for the user attribute.
The signature binds this user attribute to cert
. signer
will be
used to create a certification signature of type
signature_type
. signature_type
defaults to
SignatureType::GenericCertification
, hash_algo
to SHA512,
creation_time
to the current time.
This function adds a creation time subpacket, a issuer fingerprint subpacket, and a issuer subpacket to the signature.
Errors
Returns Error::InvalidArgument
if signature_type
is not
one of SignatureType::{Generic, Persona, Casual, Positive}Certification
Examples
This example demonstrates how to certify a User ID.
// Generate a Cert, and create a keypair from the primary key.
let (alice, _) = CertBuilder::new()
.add_userid("alice@example.org")
.generate()?;
let mut keypair = alice.primary_key().key().clone()
.parts_into_secret()?.into_keypair()?;
// Generate a Cert for Bob.
let user_attr = UserAttribute::new(&[
Subpacket::Image(
Image::Private(100, vec![0, 1, 2].into_boxed_slice())),
])?;
let (bob, _) = CertBuilder::new()
.set_primary_key_flags(KeyFlags::empty().set_certification())
.add_user_attribute(user_attr)
.generate()?;
// Alice now certifies the binding between `bob@example.org` and `bob`.
let certification =
bob.user_attributes().nth(0).unwrap()
.certify(&mut keypair, &bob, SignatureType::PositiveCertification,
None, None)?;
// `certification` can now be used, e.g. by merging it into `bob`.
let bob = bob.insert_packets(certification)?;
// Check that we have a certification on the User ID.
assert_eq!(bob.user_attributes().nth(0).unwrap()
.certifications().count(),
1);
Trait Implementations
sourceimpl Any<UserAttribute> for Packet
impl Any<UserAttribute> for Packet
sourcefn downcast(self) -> Result<UserAttribute, Packet>
fn downcast(self) -> Result<UserAttribute, Packet>
Attempts to downcast to T
, returning the packet if it fails. Read more
sourcefn downcast_ref(&self) -> Option<&UserAttribute>
fn downcast_ref(&self) -> Option<&UserAttribute>
Attempts to downcast to &T
, returning None
if it fails. Read more
sourcefn downcast_mut(&mut self) -> Option<&mut UserAttribute>
fn downcast_mut(&mut self) -> Option<&mut UserAttribute>
Attempts to downcast to &mut T
, returning None
if it fails. Read more
sourceimpl Clone for UserAttribute
impl Clone for UserAttribute
sourcefn clone(&self) -> UserAttribute
fn clone(&self) -> UserAttribute
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for UserAttribute
impl Debug for UserAttribute
sourceimpl From<UserAttribute> for Packet
impl From<UserAttribute> for Packet
sourcefn from(s: UserAttribute) -> Self
fn from(s: UserAttribute) -> Self
Converts to this type from the input type.
sourceimpl Hash for UserAttribute
impl Hash for UserAttribute
sourceimpl Hash for UserAttribute
impl Hash for UserAttribute
sourceimpl IntoIterator for UserAttribute
impl IntoIterator for UserAttribute
Implement IntoIterator
so that
cert::insert_packets(sig)
just works.
type Item = UserAttribute
type Item = UserAttribute
The type of the elements being iterated over.
type IntoIter = Once<UserAttribute>
type IntoIter = Once<UserAttribute>
Which kind of iterator are we turning this into?
sourceimpl Marshal for UserAttribute
impl Marshal for UserAttribute
sourceimpl MarshalInto for UserAttribute
impl MarshalInto for UserAttribute
sourcefn serialized_len(&self) -> usize
fn serialized_len(&self) -> usize
Computes the maximal length of the serialized representation. Read more
sourcefn serialize_into(&self, buf: &mut [u8]) -> Result<usize>
fn serialize_into(&self, buf: &mut [u8]) -> Result<usize>
Serializes into the given buffer. Read more
sourceimpl Ord for UserAttribute
impl Ord for UserAttribute
sourceimpl<'a> Parse<'a, UserAttribute> for UserAttribute
impl<'a> Parse<'a, UserAttribute> for UserAttribute
sourceimpl PartialEq<UserAttribute> for UserAttribute
impl PartialEq<UserAttribute> for UserAttribute
sourcefn eq(&self, other: &UserAttribute) -> bool
fn eq(&self, other: &UserAttribute) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &UserAttribute) -> bool
fn ne(&self, other: &UserAttribute) -> bool
This method tests for !=
.
sourceimpl PartialOrd<UserAttribute> for UserAttribute
impl PartialOrd<UserAttribute> for UserAttribute
sourcefn partial_cmp(&self, other: &UserAttribute) -> Option<Ordering>
fn partial_cmp(&self, other: &UserAttribute) -> 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 UserAttribute
impl StructuralEq for UserAttribute
impl StructuralPartialEq for UserAttribute
Auto Trait Implementations
impl RefUnwindSafe for UserAttribute
impl Send for UserAttribute
impl Sync for UserAttribute
impl Unpin for UserAttribute
impl UnwindSafe for UserAttribute
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