[][src]Struct rustica_keys::PublicKey

pub struct PublicKey {
    pub key_type: KeyType,
    pub kind: PublicKeyKind,
    pub comment: Option<String>,
}

A type which represents an OpenSSH public key.

Fields

key_type: KeyType

Key type.

kind: PublicKeyKind

The kind of public key.

comment: Option<String>

Associated comment, if any.

Implementations

impl PublicKey[src]

pub fn from_path<P: AsRef<Path>>(path: P) -> Result<PublicKey>[src]

Reads an OpenSSH public key from a given path.

Examples

let key = PublicKey::from_path("/path/to/id_ed25519.pub");

pub fn from_string(contents: &str) -> Result<PublicKey>[src]

Reads an OpenSSH public key from a given string.

Examples

let key = PublicKey::from_string("ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHkbe7gwx7s0dlApEEzpUyOAPrzPLy4czEZw/sh8m8rd me@home").unwrap();
let fp = key.fingerprint();
assert_eq!(fp.hash, "ciQkdxjFUhk2E2vRkWJD9kB8pi+EneOkaCJJHNWzPC4");

pub fn from_bytes<T: ?Sized + AsRef<[u8]>>(data: &T) -> Result<PublicKey>[src]

Reads a public key from a given byte sequence.

The byte sequence is expected to be the base64 decoded body of the public key.

Example

let data = vec![0, 0, 0, 11, 115, 115, 104, 45,
                101, 100, 50, 53, 53, 49, 57,
                0, 0, 0, 32, 121, 27, 123, 184,
                48, 199, 187, 52, 118, 80, 41, 16,
                76, 233, 83, 35, 128, 62, 188,
                207, 47, 46, 28, 204, 70, 112,
                254, 200, 124, 155, 202, 221];

let key = PublicKey::from_bytes(&data).unwrap();
let fp = key.fingerprint();
assert_eq!(fp.hash, "ciQkdxjFUhk2E2vRkWJD9kB8pi+EneOkaCJJHNWzPC4");

pub fn bits(&self) -> usize[src]

Returns the number of bits of the public key.

Example

let key = PublicKey::from_string("ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHkbe7gwx7s0dlApEEzpUyOAPrzPLy4czEZw/sh8m8rd me@home").unwrap();
assert_eq!(key.bits(), 256);

pub fn encode(&self) -> Vec<u8>[src]

Encodes the public key in an OpenSSH compatible format.

Example

let key = PublicKey::from_string("ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHkbe7gwx7s0dlApEEzpUyOAPrzPLy4czEZw/sh8m8rd me@home").unwrap();
assert_eq!(key.encode(), vec![0, 0, 0, 11, 115, 115, 104, 45, 101, 100, 50, 53, 53, 49, 57, 0, 0, 0, 32, 121, 27, 123, 184, 48, 199, 187, 52, 118, 80, 41, 16, 76, 233, 83, 35, 128, 62, 188, 207, 47, 46, 28, 204, 70, 112, 254, 200, 124, 155, 202, 221]);

pub fn fingerprint(&self) -> Fingerprint[src]

Computes the fingerprint of the public key using the default OpenSSH fingerprint representation with SHA256.

Example

let key = PublicKey::from_path("/path/to/id_ed25519.pub").unwrap();
let fp = key.fingerprint();
println!("{}", fp.hash);

pub fn fingerprint_with(&self, kind: FingerprintKind) -> Fingerprint[src]

Computes the fingerprint of the public key using a given fingerprint representation.

Example

let key = PublicKey::from_path("/path/to/id_ed25519.pub").unwrap();
let sha512fp = key.fingerprint_with(FingerprintKind::Sha512);
println!("{}", sha512fp.hash);

pub fn write<W: Write>(&self, w: &mut W) -> Result<()>[src]

Writes the public key to a given writer.

Example

use std::fs::File;
let key = PublicKey::from_string("ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAA...").unwrap();
let mut file = File::create("/path/to/id_ed25519.pub").unwrap();
key.write(&mut file).unwrap();

Trait Implementations

impl Clone for PublicKey[src]

impl Debug for PublicKey[src]

impl Display for PublicKey[src]

impl PartialEq<PublicKey> for PublicKey[src]

impl StructuralPartialEq for PublicKey[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Conv for T

impl<T> FmtForward for T

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Pipe for T

impl<T> PipeAsRef for T

impl<T> PipeBorrow for T

impl<T> PipeDeref for T

impl<T> PipeRef for T

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> Tap for T

impl<T, U> TapAsRef<U> for T where
    U: ?Sized

impl<T, U> TapBorrow<U> for T where
    U: ?Sized

impl<T> TapDeref for T

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T> TryConv for T

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,