Struct ssh_key::private::PrivateKey
source · pub struct PrivateKey { /* private fields */ }
Expand description
SSH private key.
Implementations§
source§impl PrivateKey
impl PrivateKey
sourcepub fn new(key_data: KeypairData, comment: impl Into<String>) -> Result<Self>
pub fn new(key_data: KeypairData, comment: impl Into<String>) -> Result<Self>
Create a new unencrypted private key with the given keypair data and comment.
On no_std
platforms, use PrivateKey::from(key_data)
instead.
sourcepub fn from_openssh(input: impl AsRef<[u8]>) -> Result<Self>
pub fn from_openssh(input: impl AsRef<[u8]>) -> Result<Self>
Parse an OpenSSH-formatted PEM private key.
OpenSSH-formatted private keys begin with the following:
-----BEGIN OPENSSH PRIVATE KEY-----
sourcepub fn from_bytes(bytes: &[u8]) -> Result<Self>
pub fn from_bytes(bytes: &[u8]) -> Result<Self>
Parse a raw binary SSH private key.
sourcepub fn encode_openssh<'o>(
&self,
line_ending: LineEnding,
out: &'o mut [u8],
) -> Result<&'o str>
pub fn encode_openssh<'o>( &self, line_ending: LineEnding, out: &'o mut [u8], ) -> Result<&'o str>
Encode OpenSSH-formatted (PEM) private key.
sourcepub fn to_openssh(&self, line_ending: LineEnding) -> Result<Zeroizing<String>>
pub fn to_openssh(&self, line_ending: LineEnding) -> Result<Zeroizing<String>>
Encode an OpenSSH-formatted PEM private key, allocating a
self-zeroizing String
for the result.
sourcepub fn read_openssh_file(path: &Path) -> Result<Self>
pub fn read_openssh_file(path: &Path) -> Result<Self>
Read private key from an OpenSSH-formatted PEM file.
sourcepub fn write_openssh_file(
&self,
path: &Path,
line_ending: LineEnding,
) -> Result<()>
pub fn write_openssh_file( &self, path: &Path, line_ending: LineEnding, ) -> Result<()>
Write private key as an OpenSSH-formatted PEM file.
sourcepub fn fingerprint(&self, hash_alg: HashAlg) -> Fingerprint
pub fn fingerprint(&self, hash_alg: HashAlg) -> Fingerprint
Compute key fingerprint.
Use Default::default()
to use the default hash function (SHA-256).
sourcepub fn is_encrypted(&self) -> bool
pub fn is_encrypted(&self) -> bool
Is this key encrypted?
sourcepub fn kdf(&self) -> &Kdf
pub fn kdf(&self) -> &Kdf
Key Derivation Function (KDF) used to encrypt this key.
Returns Kdf::None
if this key is not encrypted.
sourcepub fn key_data(&self) -> &KeypairData
pub fn key_data(&self) -> &KeypairData
Keypair data.
sourcepub fn public_key(&self) -> &PublicKey
pub fn public_key(&self) -> &PublicKey
Get the PublicKey
which corresponds to this private key.
sourcepub fn random(
rng: impl CryptoRng + RngCore,
algorithm: Algorithm,
) -> Result<Self>
pub fn random( rng: impl CryptoRng + RngCore, algorithm: Algorithm, ) -> Result<Self>
Generate a random key which uses the given algorithm.
§Returns
Error::Algorithm
if the algorithm is unsupported.
sourcepub fn set_comment(&mut self, comment: impl Into<String>)
pub fn set_comment(&mut self, comment: impl Into<String>)
Set the comment on the key.
Trait Implementations§
source§impl Clone for PrivateKey
impl Clone for PrivateKey
source§fn clone(&self) -> PrivateKey
fn clone(&self) -> PrivateKey
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for PrivateKey
impl Debug for PrivateKey
source§impl From<&PrivateKey> for KeyData
impl From<&PrivateKey> for KeyData
source§fn from(private_key: &PrivateKey) -> KeyData
fn from(private_key: &PrivateKey) -> KeyData
source§impl From<&PrivateKey> for PublicKey
impl From<&PrivateKey> for PublicKey
source§fn from(private_key: &PrivateKey) -> PublicKey
fn from(private_key: &PrivateKey) -> PublicKey
source§impl From<DsaKeypair> for PrivateKey
impl From<DsaKeypair> for PrivateKey
source§fn from(keypair: DsaKeypair) -> PrivateKey
fn from(keypair: DsaKeypair) -> PrivateKey
source§impl From<EcdsaKeypair> for PrivateKey
impl From<EcdsaKeypair> for PrivateKey
source§fn from(keypair: EcdsaKeypair) -> PrivateKey
fn from(keypair: EcdsaKeypair) -> PrivateKey
source§impl From<Ed25519Keypair> for PrivateKey
impl From<Ed25519Keypair> for PrivateKey
source§fn from(keypair: Ed25519Keypair) -> PrivateKey
fn from(keypair: Ed25519Keypair) -> PrivateKey
source§impl From<PrivateKey> for KeyData
impl From<PrivateKey> for KeyData
source§fn from(private_key: PrivateKey) -> KeyData
fn from(private_key: PrivateKey) -> KeyData
source§impl From<PrivateKey> for PublicKey
impl From<PrivateKey> for PublicKey
source§fn from(private_key: PrivateKey) -> PublicKey
fn from(private_key: PrivateKey) -> PublicKey
source§impl From<RsaKeypair> for PrivateKey
impl From<RsaKeypair> for PrivateKey
source§fn from(keypair: RsaKeypair) -> PrivateKey
fn from(keypair: RsaKeypair) -> PrivateKey
source§impl From<SkEcdsaSha2NistP256> for PrivateKey
impl From<SkEcdsaSha2NistP256> for PrivateKey
source§fn from(keypair: SkEcdsaSha2NistP256) -> PrivateKey
fn from(keypair: SkEcdsaSha2NistP256) -> PrivateKey
source§impl From<SkEd25519> for PrivateKey
impl From<SkEd25519> for PrivateKey
source§fn from(keypair: SkEd25519) -> PrivateKey
fn from(keypair: SkEd25519) -> PrivateKey
source§impl FromStr for PrivateKey
impl FromStr for PrivateKey
source§impl PemLabel for PrivateKey
impl PemLabel for PrivateKey
source§impl Signer<Signature> for PrivateKey
impl Signer<Signature> for PrivateKey
source§impl TryFrom<KeypairData> for PrivateKey
impl TryFrom<KeypairData> for PrivateKey
source§fn try_from(key_data: KeypairData) -> Result<PrivateKey>
fn try_from(key_data: KeypairData) -> Result<PrivateKey>
Auto Trait Implementations§
impl Freeze for PrivateKey
impl RefUnwindSafe for PrivateKey
impl Send for PrivateKey
impl Sync for PrivateKey
impl Unpin for PrivateKey
impl UnwindSafe for PrivateKey
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T, S> SignerMut<S> for T
impl<T, S> SignerMut<S> for T
source§impl<T> SigningKey for T
impl<T> SigningKey for T
source§fn public_key(&self) -> KeyData
fn public_key(&self) -> KeyData
public::KeyData
for this signing key.