[][src]Struct sequoia_openpgp::packet::user_attribute::UserAttribute

pub struct UserAttribute { /* fields omitted */ }

Holds a UserAttribute packet.

See Section 5.12 of RFC 4880 for details.

Methods

impl UserAttribute[src]

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

Returns a new UserAttribute packet.

Note: a valid UserAttribute has at least one subpacket.

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

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

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

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

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

Important traits for SubpacketIterator<'a>
pub fn subpackets(&self) -> SubpacketIterator[src]

Iterates over the subpackets.

impl UserAttribute[src]

pub fn bind<H, T, R>(
    &self,
    signer: &mut dyn Signer<R>,
    tpk: &TPK,
    signature: Builder,
    hash_algo: H,
    creation_time: T
) -> Result<Signature> where
    H: Into<Option<HashAlgorithm>>,
    T: Into<Option<Tm>>,
    R: KeyRole
[src]

Creates a binding signature.

The signature binds this user attribute to tpk. 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.

Example

This example demonstrates how to bind this user attribute to a TPK. Note that in general, the TPKBuilder is a better way to add userids to a TPK.

                        packet::user_attribute::*};
// Generate a TPK, and create a keypair from the primary key.
let (tpk, _) = TPKBuilder::new()
    .generate()?;
let mut keypair = tpk.primary().clone()
    .mark_parts_secret().into_keypair()?;
assert_eq!(tpk.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::Builder::new(SignatureType::PositiveCertificate);
let binding = user_attr.bind(&mut keypair, &tpk, builder, None, None)?;

// Now merge the user attribute and binding signature into the TPK.
let tpk = tpk.merge_packets(vec![user_attr.into(), binding.into()])?;

// Check that we have a user attribute.
assert_eq!(tpk.user_attributes().len(), 1);

pub fn certify<S, H, T, R>(
    &self,
    signer: &mut dyn Signer<R>,
    tpk: &TPK,
    signature_type: S,
    hash_algo: H,
    creation_time: T
) -> Result<Signature> where
    S: Into<Option<SignatureType>>,
    H: Into<Option<HashAlgorithm>>,
    T: Into<Option<Tm>>,
    R: KeyRole
[src]

Returns a certificate for the user attribute.

The signature binds this user attribute to tpk. signer will be used to create a certification signature of type signature_type. signature_type defaults to SignatureType::GenericCertificate, 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}Certificate

Example

This example demonstrates how to certify a userid.

                        packet::user_attribute::*};
// Generate a TPK, and create a keypair from the primary key.
let (alice, _) = TPKBuilder::new()
    .add_userid("alice@example.org")
    .generate()?;
let mut keypair = alice.primary().clone()
    .mark_parts_secret().into_keypair()?;

// Generate a TPK for Bob.
let user_attr = UserAttribute::new(&[
    Subpacket::Image(
        Image::Private(100, vec![0, 1, 2].into_boxed_slice())),
])?;
let (bob, _) = TPKBuilder::new()
    .primary_keyflags(KeyFlags::default().set_certify(true))
    .add_user_attribute(user_attr)
    .generate()?;

// Alice now certifies the binding between `bob@example.org` and `bob`.
let certificate =
    bob.user_attributes().nth(0).unwrap().user_attribute()
    .certify(&mut keypair, &bob, SignatureType::PositiveCertificate,
             None, None)?;

// `certificate` can now be used, e.g. by merging it into `bob`.
let bob = bob.merge_packets(vec![certificate.into()])?;

// Check that we have a certification on the userid.
assert_eq!(bob.user_attributes().nth(0).unwrap().certifications().len(),
           1);

Trait Implementations

impl Hash for UserAttribute[src]

fn hash(&self, hash: &mut Context)[src]

Update the Hash with a hash of the user attribute.

impl Serialize for UserAttribute[src]

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

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

impl SerializeInto for UserAttribute[src]

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

Serializes the packet to a vector.

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

Exports into the given buffer. Read more

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

Exports to a vector. Read more

impl<'a> Parse<'a, UserAttribute> for UserAttribute[src]

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

Reads from the given file. Read more

fn from_bytes<D: AsRef<[u8]> + ?Sized>(data: &'a D) -> Result<T>[src]

Reads from the given slice. Read more

impl From<Vec<u8>> for UserAttribute[src]

impl From<UserAttribute> for Packet[src]

impl Eq for UserAttribute[src]

impl PartialOrd<UserAttribute> for UserAttribute[src]

#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0
[src]

This method tests less than (for self and other) and is used by the < operator. Read more

#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0
[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0
[src]

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

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0
[src]

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

impl PartialEq<UserAttribute> for UserAttribute[src]

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0
[src]

This method tests for !=.

impl Clone for UserAttribute[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl Ord for UserAttribute[src]

fn max(self, other: Self) -> Self
1.21.0
[src]

Compares and returns the maximum of two values. Read more

fn min(self, other: Self) -> Self
1.21.0
[src]

Compares and returns the minimum of two values. Read more

impl Hash for UserAttribute[src]

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

Feeds a slice of this type into the given [Hasher]. Read more

impl Debug for UserAttribute[src]

impl Arbitrary for UserAttribute[src]

fn shrink(&self) -> Box<dyn Iterator<Item = Self> + 'static>

Auto Trait Implementations

Blanket Implementations

impl<T> From for T[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<V, T> VZip for T where
    V: MultiLane<T>,