kanidm_proto::internal

Struct SshPublicKey

pub struct SshPublicKey {
    pub key_type: KeyType,
    pub kind: PublicKeyKind,
    pub comment: Option<String>,
}
Expand description

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

pub fn from_path<P>(path: P) -> Result<PublicKey, Error>
where P: AsRef<Path>,

Reads an OpenSSH public key from a given path.

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

pub fn from_string(contents: &str) -> Result<PublicKey, Error>

Reads an OpenSSH public key from a given string.

§Examples
let key = sshkeys::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>(data: &T) -> Result<PublicKey, Error>
where T: AsRef<[u8]> + ?Sized,

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 = sshkeys::PublicKey::from_bytes(&data).unwrap();
let fp = key.fingerprint();
assert_eq!(fp.hash, "ciQkdxjFUhk2E2vRkWJD9kB8pi+EneOkaCJJHNWzPC4");

pub fn bits(&self) -> usize

Returns the number of bits of the public key.

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

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

Encodes the public key in an OpenSSH compatible format.

§Example
let key = sshkeys::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

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

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

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

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

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

pub fn write<W>(&self, w: &mut W) -> Result<(), Error>
where W: Write,

Writes the public key to a given writer.

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

Trait Implementations§

§

impl Clone for PublicKey

§

fn clone(&self) -> PublicKey

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for PublicKey

§

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

Formats the value using the given formatter. Read more
§

impl<'de> Deserialize<'de> for PublicKey

§

fn deserialize<D>( deserializer: D, ) -> Result<PublicKey, <D as Deserializer<'de>>::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
§

impl Display for PublicKey

§

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

Formats the value using the given formatter. Read more
§

impl PartialEq for PublicKey

§

fn eq(&self, other: &PublicKey) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl Serialize for PublicKey

§

fn serialize<S>( &self, serializer: S, ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
§

impl StructuralPartialEq for PublicKey

Auto Trait Implementations§

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
§

impl<'a, T> AsTaggedExplicit<'a> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self>

§

impl<'a, T> AsTaggedImplicit<'a> for T
where T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self>

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> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,