pub struct OpenPGPv4Fingerprint(String);Expand description
An OpenPGP v4 fingerprint.
The OpenPGPv4Fingerprint type wraps a String representing an OpenPGP v4 fingerprint,
ensuring that it consists of 40 uppercase hexadecimal characters with optional whitespace
separators.
§Note
-
This type supports constructing from both uppercase and lowercase hexadecimal characters, with and without whitespace separators, but guarantees to return the fingerprint in uppercase and with no whitespaces.
-
Whitespaces are only allowed between hexadecimal characters, not at the start or end of the fingerprint.
§Examples
use std::str::FromStr;
use alpm_types::{Error, OpenPGPv4Fingerprint};
// Create OpenPGPv4Fingerprint from a valid OpenPGP v4 fingerprint
let key = OpenPGPv4Fingerprint::from_str("4A0C4DFFC02E1A7ED969ED231C2358A25A10D94E")?;
assert_eq!(key.as_str(), "4A0C4DFFC02E1A7ED969ED231C2358A25A10D94E");
// Space separated fingerprint is also valid
let key = OpenPGPv4Fingerprint::from_str("4A0C 4DFF C02E 1A7E D969 ED23 1C23 58A2 5A10 D94E")?;
assert_eq!(key.as_str(), "4A0C4DFFC02E1A7ED969ED231C2358A25A10D94E");
// Attempting to create a OpenPGPv4Fingerprint from an invalid fingerprint will fail
assert!(OpenPGPv4Fingerprint::from_str("INVALIDKEY").is_err());
// Format as String
assert_eq!(
format!("{}", key),
"4A0C4DFFC02E1A7ED969ED231C2358A25A10D94E"
);Tuple Fields§
§0: StringImplementations§
Source§impl OpenPGPv4Fingerprint
impl OpenPGPv4Fingerprint
Sourcepub fn new(fingerprint: String) -> Result<Self, Error>
pub fn new(fingerprint: String) -> Result<Self, Error>
Creates a new OpenPGPv4Fingerprint instance
See OpenPGPv4Fingerprint::from_str for more information on how the OpenPGP v4
fingerprint is validated.
Sourcepub fn as_str(&self) -> &str
pub fn as_str(&self) -> &str
Returns a reference to the inner OpenPGP v4 fingerprint as a &str.
Sourcepub fn into_inner(self) -> String
pub fn into_inner(self) -> String
Consumes the OpenPGPv4Fingerprint and returns the inner String.
Trait Implementations§
Source§impl Clone for OpenPGPv4Fingerprint
impl Clone for OpenPGPv4Fingerprint
Source§fn clone(&self) -> OpenPGPv4Fingerprint
fn clone(&self) -> OpenPGPv4Fingerprint
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for OpenPGPv4Fingerprint
impl Debug for OpenPGPv4Fingerprint
Source§impl<'de> Deserialize<'de> for OpenPGPv4Fingerprint
impl<'de> Deserialize<'de> for OpenPGPv4Fingerprint
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 OpenPGPv4Fingerprint
impl Display for OpenPGPv4Fingerprint
Source§impl From<OpenPGPv4Fingerprint> for OpenPGPIdentifier
impl From<OpenPGPv4Fingerprint> for OpenPGPIdentifier
Source§fn from(fingerprint: OpenPGPv4Fingerprint) -> Self
fn from(fingerprint: OpenPGPv4Fingerprint) -> Self
Source§impl FromStr for OpenPGPv4Fingerprint
impl FromStr for OpenPGPv4Fingerprint
Source§fn from_str(s: &str) -> Result<Self, Self::Err>
fn from_str(s: &str) -> Result<Self, Self::Err>
Creates a new OpenPGPv4Fingerprint instance after validating that it follows the correct
format.
A valid OpenPGP v4 fingerprint should be a 40 characters long string of digits (0-9)
and hexadecimal letters (A-F) optionally separated by whitespaces.
§Errors
Returns an error if the OpenPGP v4 fingerprint is not valid.