[−][src]Struct sequoia_openpgp::packet::prelude::UserID
Holds a UserID packet.
See Section 5.11 of RFC 4880 for details.
Implementations
impl UserID
[src]
pub fn from_address<O, S>(name: O, comment: O, email: S) -> Result<Self> where
S: AsRef<str>,
O: Into<Option<S>>,
[src]
S: AsRef<str>,
O: Into<Option<S>>,
Constructs a User ID.
This does a basic check and any necessary escaping to form a de facto User ID.
Only the address is required. If a comment is supplied, then a name is also required.
If you already have a User ID value, then you can just
use UserID::from()
.
assert_eq!(UserID::from_address( "John Smith".into(), None, "boat@example.org").unwrap().value(), &b"John Smith <boat@example.org>"[..]);
pub fn from_unchecked_address<O, S>(
name: O,
comment: O,
address: S
) -> Result<Self> where
S: AsRef<str>,
O: Into<Option<S>>,
[src]
name: O,
comment: O,
address: S
) -> Result<Self> where
S: AsRef<str>,
O: Into<Option<S>>,
Constructs a User ID.
This does a basic check and any necessary escaping to form a de facto User ID modulo the address, which is not checked.
This is useful when you want to specify a URI instead of an email address.
If you already have a User ID value, then you can just
use UserID::from()
.
assert_eq!(UserID::from_unchecked_address( "NAS".into(), None, "ssh://host.example.org").unwrap().value(), &b"NAS <ssh://host.example.org>"[..]);
pub fn value(&self) -> &[u8]
[src]
Gets the user ID packet's value.
pub fn name(&self) -> Result<Option<String>>
[src]
Parses the User ID according to de facto conventions, and returns the name component, if any.
pub fn comment(&self) -> Result<Option<String>>
[src]
Parses the User ID according to de facto conventions, and returns the comment field, if any.
pub fn email(&self) -> Result<Option<String>>
[src]
Parses the User ID according to de facto conventions, and returns the email address, if any.
pub fn uri(&self) -> Result<Option<String>>
[src]
Parses the User ID according to de facto conventions, and returns the URI, if any.
pub fn email_normalized(&self) -> Result<Option<String>>
[src]
Returns a normalized version of the UserID's email address.
Normalized email addresses are primarily needed when email addresses are compared.
Note: normalized email addresses are still valid email addresses.
This function normalizes an email address by doing puny-code normalization on the domain, and lowercasing the local part in the so-called empty locale.
Note: this normalization procedure is the same as the normalization procedure recommended by Autocrypt.
impl UserID
[src]
pub fn bind(
&self,
signer: &mut dyn Signer,
cert: &Cert,
signature: SignatureBuilder
) -> Result<Signature>
[src]
&self,
signer: &mut dyn Signer,
cert: &Cert,
signature: SignatureBuilder
) -> Result<Signature>
Creates a binding signature.
The signature binds this userid 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 userid to a Cert.
Note that in general, the CertBuilder
is a better way to add
userids 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 userid and a binding signature. let userid = UserID::from("test@example.org"); let builder = signature::SignatureBuilder::new(SignatureType::PositiveCertification); let binding = userid.bind(&mut keypair, &cert, builder)?; // Now merge the userid and binding signature into the Cert. let cert = cert.merge_packets(vec![Packet::from(userid), binding.into()])?; // Check that we have a userid. assert_eq!(cert.userids().len(), 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 id.
The signature binds this userid 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.
// Generate a Cert, and create a keypair from the primary key. let (alice, _) = CertBuilder::new() .set_primary_key_flags(KeyFlags::empty().set_certification()) .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 (bob, _) = CertBuilder::new() .set_primary_key_flags(KeyFlags::empty().set_certification()) .add_userid("bob@example.org") .generate()?; // Alice now certifies the binding between `bob@example.org` and `bob`. let certificate = bob.userids().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(certificate)?; // Check that we have a certification on the userid. assert_eq!(bob.userids().nth(0).unwrap() .certifications().len(), 1);
Trait Implementations
impl Clone for UserID
[src]
fn clone(&self) -> Self
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Debug for UserID
[src]
impl Display for UserID
[src]
impl Eq for UserID
[src]
impl<'_> From<&'_ [u8]> for UserID
[src]
impl<'a> From<&'a str> for UserID
[src]
impl<'a> From<Cow<'a, str>> for UserID
[src]
impl From<String> for UserID
[src]
impl From<UserID> for Packet
[src]
impl From<Vec<u8>> for UserID
[src]
impl Hash for UserID
[src]
impl Hash for UserID
[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 IntoIterator for UserID
[src]
Implement IntoIterator
so that
cert::merge_packets(sig)
just works.
type Item = UserID
The type of the elements being iterated over.
type IntoIter = Once<UserID>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
impl Marshal for UserID
[src]
fn serialize(&self, o: &mut dyn Write) -> Result<()>
[src]
fn export(&self, o: &mut dyn Write) -> Result<()>
[src]
impl MarshalInto for UserID
[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 UserID
[src]
fn cmp(&self, other: &Self) -> Ordering
[src]
#[must_use]fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn clamp(self, min: Self, max: Self) -> Self
[src]
impl<'a> Parse<'a, UserID> for UserID
[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<UserID> for UserID
[src]
impl PartialOrd<UserID> for UserID
[src]
Auto Trait Implementations
impl RefUnwindSafe for UserID
impl Send for UserID
impl Sync for UserID
impl Unpin for UserID
impl UnwindSafe for UserID
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> DynClone for T where
T: Clone,
[src]
T: Clone,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<I> IntoIterator for I where
I: Iterator,
[src]
I: Iterator,
type Item = <I as Iterator>::Item
The type of the elements being iterated over.
type IntoIter = I
Which kind of iterator are we turning this into?
fn into_iter(self) -> I
[src]
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> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
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>,