[−][src]Struct osshkeys::keys::KeyPair
General key pair type
This is a type to make it easy to store different types of key pair in the container. Each can contain one of the types supported in this crate.
Key pair is the so-called "private key" which contains both public and private parts of an asymmetry key.
Methods
impl KeyPair
[src]
pub fn from_keystr(pem: &str, passphrase: Option<&[u8]>) -> OsshResult<Self>
[src]
Parse a keypair from supporting file types
The passphrase is required if the keypair is encrypted.
OpenSSL PEM
- Begin with
-----BEGIN DSA PRIVATE KEY-----
for dsa key. - Begin with
-----BEGIN RSA PRIVATE KEY-----
for rsa key. - Begin with
-----BEGIN EC PRIVATE KEY-----
for ecdsa key. - This file type doesn't support Ed25519
PKCS#8 Format
- Begin with
-----BEGIN PRIVATE KEY-----
Openssh
- Begin with
-----BEGIN OPENSSH PRIVATE KEY-----
This is the new format which is supported since OpenSSH 6.5, and it became the default format in OpenSSH 7.8. The Ed25519 key can only be stored in this type.
pub fn generate(keytype: KeyType, bits: usize) -> OsshResult<Self>
[src]
Generate a key of the specified type and size
Key Size
There are some limitations to the key size:
- RSA: the size should
>= 1024
and<= 16384
bits. - DSA: the size should be
1024
bits. - EcDSA: the size should be
256
,384
, or521
bits. - Ed25519: the size should be
256
bits.
If the key size parameter is zero, then it will use the default size to generate the key
- RSA:
2048
bits - DSA:
1024
bits - EcDSA:
256
bits - Ed25519:
256
bits
pub fn keytype(&self) -> KeyType
[src]
Indicate the key type being stored
pub fn serialize_pem(&self, passphrase: Option<&[u8]>) -> OsshResult<String>
[src]
Serialize the keypair to the OpenSSL PEM format
If the passphrase is given (set to Some(...)
), then the generated PEM key will be encrypted.
pub fn comment(&self) -> &str
[src]
Get the comment of the key
pub fn comment_mut(&mut self) -> &mut String
[src]
Get the mutable comment of the key
pub fn clone_public_key(&self) -> Result<PublicKey, Error>
[src]
Clone the public parts of the key pair
Trait Implementations
impl Key for KeyPair
[src]
impl PublicPart for KeyPair
[src]
fn verify(&self, data: &[u8], sig: &[u8]) -> Result<bool, Error>
[src]
fn blob(&self) -> Result<Vec<u8>, Error>
[src]
fn fingerprint(&self, hash: FingerprintHash) -> OsshResult<Vec<u8>>
[src]
Hash the blob of the public key to generate the fingerprint
impl PrivatePart for KeyPair
[src]
impl From<RsaKeyPair> for KeyPair
[src]
fn from(inner: RsaKeyPair) -> KeyPair
[src]
impl From<DsaKeyPair> for KeyPair
[src]
fn from(inner: DsaKeyPair) -> KeyPair
[src]
impl From<EcDsaKeyPair> for KeyPair
[src]
fn from(inner: EcDsaKeyPair) -> KeyPair
[src]
impl From<Ed25519KeyPair> for KeyPair
[src]
fn from(inner: Ed25519KeyPair) -> KeyPair
[src]
Auto Trait Implementations
impl Sync for KeyPair
impl Send for KeyPair
impl Unpin for KeyPair
impl RefUnwindSafe for KeyPair
impl UnwindSafe for KeyPair
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Same<T> for T
type Output = T
Should always be Self