#[non_exhaustive]pub enum Pubkey {
Ed25519(Ed25519Pubkey),
Rsa(RsaPubkey),
EcdsaP256(EcdsaPubkey<NistP256>),
EcdsaP384(EcdsaPubkey<NistP384>),
}
Expand description
Public key in one of supported formats.
This enum is marked as #[non_exhaustive]
, so we might add new variants without breaking
backwards compatibility.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Ed25519(Ed25519Pubkey)
Ed25519 public key.
Rsa(RsaPubkey)
RSA public key.
EcdsaP256(EcdsaPubkey<NistP256>)
ECDSA public key on NIST P-256 curve.
EcdsaP384(EcdsaPubkey<NistP384>)
ECDSA public key on NIST P-384 curve.
Implementations§
source§impl Pubkey
impl Pubkey
sourcepub fn algos(&self) -> &'static [&'static PubkeyAlgo]
pub fn algos(&self) -> &'static [&'static PubkeyAlgo]
Get all public key algorithms that work with this key.
Most key types work with just a single public key algorithm, but with RSA keys
(Pubkey::Rsa
), there are multiple algorithms that differ in the hash function. This
method returns all supported algorithms for this key.
sourcepub fn algos_secure(&self) -> &'static [&'static PubkeyAlgo]
👎Deprecated since 0.2.1: Disabling public key algorithms for authentication on the client does not increase security, the older, less secure algorithms must be disabled on the server. Please use Pubkey::algos()
instead.
pub fn algos_secure(&self) -> &'static [&'static PubkeyAlgo]
Pubkey::algos()
instead.Get best public key algorithms that work with this key.
Most key types work with just a single public key algorithm, but with RSA keys
(Pubkey::Rsa
), there are multiple algorithms that differ in the hash function. This
method returns only highly secure algorithms, but older servers may not support them.
sourcepub fn algos_compatible_less_secure(&self) -> &'static [&'static PubkeyAlgo]
👎Deprecated since 0.2.1: Please use Pubkey::algos()
instead.
pub fn algos_compatible_less_secure(&self) -> &'static [&'static PubkeyAlgo]
Pubkey::algos()
instead.Get all public key algorithms that work with this key.
Most key types work with just a single public key algorithm, but with RSA keys
(Pubkey::Rsa
), there are multiple algorithms that differ in the hash function. This
method returns all supported algorithms for maximum compatibility.
sourcepub fn decode(blob: Bytes) -> Result<Self>
pub fn decode(blob: Bytes) -> Result<Self>
Decode a public key from SSH wire encoding.
This is the encoding initially defined by RFC 4253. For keys other than RSA, the encoding is defined in the RFC that introduces the key type.
sourcepub fn encode(&self) -> Bytes
pub fn encode(&self) -> Bytes
Encode a public key into SSH encoding.
This is the encoding initially defined by RFC 4253. For keys other than RSA, the encoding is defined in the RFC that introduces the key type.
You can use this method to calculate a digest of the public key.
sourcepub fn type_str(&self) -> String
pub fn type_str(&self) -> String
Get the type of the key as a string.
Returns a string like "ssh-rsa"
or "ssh-ed25519"
, which is used in OpenSSH files like
authorized_keys
or known_hosts
as a human-readable description of the key type. It
corresponds to the string identifier of the key format that is present in the SSH encoding
of the key.
sourcepub fn fingerprint(&self) -> String
pub fn fingerprint(&self) -> String
Compute a fingerprint of the public key.
The fingerprint is in the SHA-256 digest of the public key encoded with base64 (not padded
with =
characters) and prefixed with SHA256:
(e.g.
"SHA256:eaBPG/rqx+IPa0Lc9KHypkG3UxjmUwerwq9CZ/xpPWM"
). If you need another format, use
encode()
to encode the key into bytes and apply a digest of your
choice.