Skip to main content

Key

Struct Key 

Source
pub struct Key { /* private fields */ }
Expand description

An Ed25519 key pair whose public half is rendered as a non-transferable AID.

Debug prints the AID and nothing else. The AID is public by construction — it is the verifying key — and the seed must never reach a log line by accident, which is exactly what a derived Debug would arrange.

Implementations§

Source§

impl Key

Source

pub fn generate() -> Self

Create a key from fresh randomness.

Source

pub fn from_seed(seed: &[u8]) -> Result<Self>

Recreate a key from its 32-byte Ed25519 seed.

Source

pub fn from_openssh(text: &str) -> Result<Self>

Load an unencrypted OpenSSH Ed25519 private key, as ssh-keygen writes it (this.i @0mvgkwnl).

text is the armored key, LF line endings, with or without the final newline. The key must be the only one in the file, its check integers must agree, its padding must be 1, 2, 3, …, and its public key must match in both places it is stored and be the one its seed derives. Anything else, including an encrypted key, is Kind::MalformedKey, and the error never carries any part of the key.

Use a key dedicated to fiki and never loaded into ssh-agent. Signatures do not cross between protocols – every base sign_request and sign_response build begins with a double quote, SSH user authentication signs data beginning with a length-prefixed session identifier (RFC 4252 section 7), and SSHSIG signs data beginning “SSHSIG” – but an agent signs whatever bytes it is asked to, so anyone able to use a forwarded agent could sign fiki requests with a login key. The separation is a property of sign_request, not of the key: Key::sign signs any bytes.

Source

pub fn aid(&self) -> String

The non-transferable AID: 44 characters, B prefixed, and also the verifying key.

Source

pub fn keyid(&self) -> String

The raw verifying key, base64url and unpadded — the RFC 8037 JWK “x” form (@7xrx5evg).

Source

pub fn seed(&self) -> [u8; 32]

The 32-byte seed, for a caller that has to persist the key somewhere.

Source

pub fn sign(&self, data: &[u8]) -> [u8; 64]

Sign bytes, returning the raw 64-byte Ed25519 signature.

Trait Implementations§

Source§

impl Debug for Key

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Key

§

impl RefUnwindSafe for Key

§

impl Send for Key

§

impl Sync for Key

§

impl Unpin for Key

§

impl UnsafeUnpin for Key

§

impl UnwindSafe for Key

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.