pub struct PublicKey(/* private fields */);Expand description
A validated age public key.
PublicKey is a thin wrapper around a String that ensures the contained
key starts with "age1". The validation is performed at construction time
via new, which delegates to
validate_age_prefix.
§Security
While this type guarantees the "age1" prefix, it does not perform
full Bech32 decoding or curve validation. The actual cryptographic checks
are left to the age crate when the key is used for encryption.
§Examples
use age_setup::PublicKey;
let pk = PublicKey::new("age1mykey".into())?;
println!("Public key: {}", pk); // uses Display
println!("Exposed value: {}", pk.expose());Implementations§
Source§impl PublicKey
impl PublicKey
Sourcepub fn new(raw: String) -> Result<Self>
pub fn new(raw: String) -> Result<Self>
Creates a new PublicKey after validating the raw string.
The string must be non‑empty and start with "age1" (case‑sensitive).
Validation is performed by [validate_age_prefix].
§Errors
Returns Error::Validation if the key
does not meet the prefix requirement.
§Examples
let valid = PublicKey::new("age1abcdef".into()).unwrap();
assert_eq!(valid.expose(), "age1abcdef");
let invalid = PublicKey::new("not-a-key".into());
assert!(invalid.is_err());Trait Implementations§
Source§impl AsRef<str> for PublicKey
Allows PublicKey to be used where a &str is expected.
impl AsRef<str> for PublicKey
Allows PublicKey to be used where a &str is expected.
fn print_key(key: &impl AsRef<str>) {
println!("{}", key.as_ref());
}
let pk = PublicKey::new("age1foo".into()).unwrap();
print_key(&pk);Auto Trait Implementations§
impl Freeze for PublicKey
impl RefUnwindSafe for PublicKey
impl Send for PublicKey
impl Sync for PublicKey
impl Unpin for PublicKey
impl UnsafeUnpin for PublicKey
impl UnwindSafe for PublicKey
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
Mutably borrows from an owned value. Read more