osshkeys 0.7.0

A library to read and write OpenSSH public and private keys
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use crate::error::*;
use crate::keys::*;

//TODO: Not to depend on openssl to parse pem file in the future
pub fn serialize_pkcs8_privkey(keypair: &KeyPair, passphrase: Option<&str>) -> OsshResult<String> {
    let pem = if let Some(passphrase) = passphrase {
        //TODO: Allow for cipher selection
        let cipher = openssl::symm::Cipher::aes_128_cbc();
        keypair
            .ossl_pkey()?
            .private_key_to_pem_pkcs8_passphrase(cipher, passphrase.as_bytes())?
    } else {
        keypair.ossl_pkey()?.private_key_to_pem_pkcs8()?
    };

    String::from_utf8(pem).map_err(|e| Error::with_error(ErrorKind::InvalidPemFormat, e))
}