[−][src]Struct sequoia_openpgp::packet::user_attribute::UserAttribute
Holds a UserAttribute packet.
See Section 5.12 of RFC 4880 for details.
Implementations
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.
pub fn subpackets(&self) -> SubpacketIterator[src]
Iterates over the subpackets.
impl UserAttribute[src]
pub fn bind(
&self,
signer: &mut dyn Signer,
cert: &Cert,
signature: Builder
) -> Result<Signature>[src]
&self,
signer: &mut dyn Signer,
cert: &Cert,
signature: Builder
) -> 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.
Example
This example demonstrates how to bind this user attribute to a
Cert. Note that in general, the CertBuilder is a better way
to add userids to a Cert.
packet::user_attribute::*};
// 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::Builder::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.merge_packets(vec![user_attr.into(), binding.into()])?;
// Check that we have a user attribute.
assert_eq!(cert.user_attributes().count(), 1);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>>, [src]
&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 certificate 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}Certificate
Example
This example demonstrates how to certify a userid.
packet::user_attribute::*};
// 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::default().set_certification(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()
.certify(&mut keypair, &bob, SignatureType::PositiveCertification,
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 Arbitrary for UserAttribute[src]
fn arbitrary<G: Gen>(g: &mut G) -> Self[src]
fn shrink(&self) -> Box<dyn Iterator<Item = Self> + 'static>[src]
impl Clone for UserAttribute[src]
fn clone(&self) -> UserAttribute[src]
fn clone_from(&mut self, source: &Self)1.0.0[src]
impl Debug for UserAttribute[src]
impl Eq for UserAttribute[src]
impl From<UserAttribute> for Packet[src]
fn from(s: UserAttribute) -> Self[src]
impl From<Vec<u8>> for UserAttribute[src]
impl Hash for UserAttribute[src]
impl Hash for UserAttribute[src]
fn hash<__H: Hasher>(&self, state: &mut __H)[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher, 1.3.0[src]
H: Hasher,
impl Marshal for UserAttribute[src]
fn serialize(&self, o: &mut dyn Write) -> Result<()>[src]
fn export(&self, o: &mut dyn Write) -> Result<()>[src]
impl MarshalInto for UserAttribute[src]
fn serialized_len(&self) -> usize[src]
fn serialize_into(&self, buf: &mut [u8]) -> Result<usize>[src]
fn to_vec(&self) -> Result<Vec<u8>>[src]
fn export_into(&self, buf: &mut [u8]) -> Result<usize>[src]
fn export_to_vec(&self) -> Result<Vec<u8>>[src]
impl Ord for UserAttribute[src]
fn cmp(&self, other: &UserAttribute) -> Ordering[src]
#[must_use]fn max(self, other: Self) -> Self1.21.0[src]
#[must_use]fn min(self, other: Self) -> Self1.21.0[src]
#[must_use]fn clamp(self, min: Self, max: Self) -> Self[src]
impl<'a> Parse<'a, UserAttribute> for UserAttribute[src]
fn from_reader<R: 'a + Read>(reader: R) -> Result<Self>[src]
fn from_file<P: AsRef<Path>>(path: P) -> Result<T>[src]
fn from_bytes<D: AsRef<[u8]> + ?Sized>(data: &'a D) -> Result<T>[src]
impl PartialEq<UserAttribute> for UserAttribute[src]
fn eq(&self, other: &UserAttribute) -> bool[src]
fn ne(&self, other: &UserAttribute) -> bool[src]
impl PartialOrd<UserAttribute> for UserAttribute[src]
fn partial_cmp(&self, other: &UserAttribute) -> Option<Ordering>[src]
fn lt(&self, other: &UserAttribute) -> bool[src]
fn le(&self, other: &UserAttribute) -> bool[src]
fn gt(&self, other: &UserAttribute) -> bool[src]
fn ge(&self, other: &UserAttribute) -> bool[src]
impl StructuralEq for UserAttribute[src]
impl StructuralPartialEq for UserAttribute[src]
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
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T[src]
impl<T> From<T> for T[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone, [src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T[src]
fn clone_into(&self, target: &mut T)[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,