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§

source§

impl UserAttribute

source

pub fn new(subpackets: &[Subpacket]) -> Result<Self>

Returns a new UserAttribute packet.

Note: a valid UserAttribute has at least one subpacket.

source

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.

source

pub fn value(&self) -> &[u8]

Gets the user attribute packet’s raw, unparsed value.

Most likely you will want to use subpackets() to iterate over the subpackets.

source

pub fn value_mut(&mut self) -> &mut Vec<u8>

Gets a mutable reference to the user attribute packet’s raw value.

source

pub fn subpackets(&self) -> SubpacketIterator<'_>

Iterates over the subpackets.

source§

impl UserAttribute

source

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);
source

pub fn certify<S, H, T>( &self, signer: &mut dyn Signer, cert: &Cert, signature_type: S, hash_algo: H, creation_time: T, ) -> Result<Signature>

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§

source§

impl Any<UserAttribute> for Packet

source§

fn downcast(self) -> Result<UserAttribute, Packet>

Attempts to downcast to T, returning the packet if it fails. Read more
source§

fn downcast_ref(&self) -> Option<&UserAttribute>

Attempts to downcast to &T, returning None if it fails. Read more
source§

fn downcast_mut(&mut self) -> Option<&mut UserAttribute>

Attempts to downcast to &mut T, returning None if it fails. Read more
source§

impl Clone for UserAttribute

source§

fn clone(&self) -> UserAttribute

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for UserAttribute

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<UserAttribute> for Packet

source§

fn from(s: UserAttribute) -> Self

Converts to this type from the input type.
source§

impl From<Vec<u8>> for UserAttribute

source§

fn from(u: Vec<u8>) -> Self

Converts to this type from the input type.
source§

impl Hash for UserAttribute

source§

fn hash(&self, hash: &mut dyn Digest)

Updates the given hash with this object.
source§

impl Hash for UserAttribute

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl IntoIterator for UserAttribute

Implement IntoIterator so that cert::insert_packets(sig) just works.

§

type Item = UserAttribute

The type of the elements being iterated over.
§

type IntoIter = Once<UserAttribute>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl Marshal for UserAttribute

source§

fn serialize(&self, o: &mut dyn Write) -> Result<()>

Writes a serialized version of the object to o.
source§

fn export(&self, o: &mut dyn Write) -> Result<()>

Exports a serialized version of the object to o. Read more
source§

impl MarshalInto for UserAttribute

source§

fn serialized_len(&self) -> usize

Computes the maximal length of the serialized representation. Read more
source§

fn serialize_into(&self, buf: &mut [u8]) -> Result<usize>

Serializes into the given buffer. Read more
source§

fn to_vec(&self) -> Result<Vec<u8>>

Serializes the packet to a vector.
source§

fn export_into(&self, buf: &mut [u8]) -> Result<usize>

Exports into the given buffer. Read more
source§

fn export_to_vec(&self) -> Result<Vec<u8>>

Exports to a vector. Read more
source§

impl Ord for UserAttribute

source§

fn cmp(&self, other: &UserAttribute) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl<'a> Parse<'a, UserAttribute> for UserAttribute

source§

fn from_buffered_reader<R>(reader: R) -> Result<Self>
where R: BufferedReader<Cookie> + 'a,

Reads from the given buffered reader.
source§

fn from_reader<R: 'a + Read + Send + Sync>(reader: R) -> Result<Self>

Reads from the given reader.
source§

fn from_bytes<D: AsRef<[u8]> + ?Sized + Send + Sync>( data: &'a D, ) -> Result<Self>

Reads from the given slice. Read more
source§

fn from_file<P: AsRef<Path>>(path: P) -> Result<T>

Reads from the given file. Read more
source§

impl PartialEq for UserAttribute

source§

fn eq(&self, other: &UserAttribute) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for UserAttribute

source§

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 · source§

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 · source§

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
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Eq for UserAttribute

source§

impl StructuralPartialEq for UserAttribute

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> DynClone for T
where T: Clone,

source§

fn __clone_box(&self, _: Private) -> *mut ()

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> ErasedDestructor for T
where T: 'static,

source§

impl<T> MaybeSendSync for T