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 moresource§impl Debug for OpenPgpUserId
impl Debug for OpenPgpUserId
source§impl<'de> Deserialize<'de> for OpenPgpUserId
impl<'de> Deserialize<'de> for OpenPgpUserId
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl Display for OpenPgpUserId
impl Display for OpenPgpUserId
source§impl From<OpenPgpUserId> for String
impl From<OpenPgpUserId> for String
source§fn from(value: OpenPgpUserId) -> Self
fn from(value: OpenPgpUserId) -> Self
source§impl FromStr for OpenPgpUserId
impl FromStr for OpenPgpUserId
source§impl Hash for OpenPgpUserId
impl Hash for OpenPgpUserId
source§impl PartialEq for OpenPgpUserId
impl PartialEq for OpenPgpUserId
source§impl Serialize for OpenPgpUserId
impl Serialize for OpenPgpUserId
source§impl TryFrom<String> for OpenPgpUserId
impl TryFrom<String> for OpenPgpUserId
impl Eq for OpenPgpUserId
impl StructuralPartialEq for OpenPgpUserId
Auto Trait Implementations§
impl Freeze for OpenPgpUserId
impl RefUnwindSafe for OpenPgpUserId
impl Send for OpenPgpUserId
impl Sync for OpenPgpUserId
impl Unpin for OpenPgpUserId
impl UnwindSafe for OpenPgpUserId
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)