pub struct OpenPgpUserId(OpenPgpUserIdType);
Expand description
A basic representation of a User ID for OpenPGP
While OpenPGP User IDs are loosely defined to be UTF-8 strings, they do not enforce particular rules around the use of e-mail addresses or their general length. This type allows to distinguish between plain UTF-8 strings and valid e-mail addresses. Valid e-mail addresses must provide a display part, use a top-level domain (TLD) and not rely on domain literals (e.g. IP address). The length of a User ID is implicitly limited by the maximum length of an OpenPGP packet (8192 bytes). As such, this type only allows a maximum length of 4096 bytes as middle ground.
Tuple Fields§
§0: OpenPgpUserIdType
Implementations§
Source§impl OpenPgpUserId
impl OpenPgpUserId
Sourcepub fn new(user_id: String) -> Result<Self, Error>
pub fn new(user_id: String) -> Result<Self, Error>
Creates a new OpenPgpUserId
from a String
§Errors
Returns an Error::Key
if the chars of the provided String exceed
4096 bytes. This ensures to stay below the valid upper limit defined by the maximum OpenPGP
packet size of 8192 bytes.
§Examples
use std::str::FromStr;
use nethsm::OpenPgpUserId;
assert!(!OpenPgpUserId::new("🤡".to_string())?.is_email());
assert!(OpenPgpUserId::new("🤡 <foo@xn--rl8h.org>".to_string())?.is_email());
// an e-mail without a display name is not considered a valid e-mail
assert!(!OpenPgpUserId::new("<foo@xn--rl8h.org>".to_string())?.is_email());
// this fails because the provided String is too long
assert!(OpenPgpUserId::new("U".repeat(4097)).is_err());
Sourcepub fn is_email(&self) -> bool
pub fn is_email(&self) -> bool
Returns whether the OpenPgpUserId
is a valid e-mail address
§Examples
use nethsm::OpenPgpUserId;
assert!(!OpenPgpUserId::new("🤡".to_string())?.is_email());
assert!(OpenPgpUserId::new("🤡 <foo@xn--rl8h.org>".to_string())?.is_email());
Trait Implementations§
Source§impl AsRef<str> for OpenPgpUserId
impl AsRef<str> for OpenPgpUserId
Source§impl Clone for OpenPgpUserId
impl Clone for OpenPgpUserId
Source§fn clone(&self) -> OpenPgpUserId
fn clone(&self) -> OpenPgpUserId
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more