pub fn stringify_pem_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();
        let passphrase = passphrase.as_bytes();
        match &keypair.key {
            KeyPairType::RSA(key) => key
                .ossl_rsa()
                .private_key_to_pem_passphrase(cipher, passphrase)?,
            KeyPairType::DSA(key) => key
                .ossl_dsa()
                .private_key_to_pem_passphrase(cipher, passphrase)?,
            KeyPairType::ECDSA(key) => key
                .ossl_ec()
                .private_key_to_pem_passphrase(cipher, passphrase)?,
            _ => return Err(ErrorKind::UnsupportType.into()),
        }
    } else {
        match &keypair.key {
            KeyPairType::RSA(key) => key.ossl_rsa().private_key_to_pem()?,
            KeyPairType::DSA(key) => key.ossl_dsa().private_key_to_pem()?,
            KeyPairType::ECDSA(key) => key.ossl_ec().private_key_to_pem()?,
            _ => return Err(ErrorKind::UnsupportType.into()),
        }
    };

    String::from_utf8(pem).map_err(|e| Error::with_error(ErrorKind::InvalidPemFormat, e))
}
//TODO: Not to depend on openssl to parse pem file in the future
Not to depend on openssl to parse pem file in the future
Not to depend on openssl to parse pem file in the future
pub fn stringify_pem_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();
        let passphrase = passphrase.as_bytes();
        match &keypair.key {
            KeyPairType::RSA(key) => key
                .ossl_rsa()
                .private_key_to_pem_passphrase(cipher, passphrase)?,
            KeyPairType::DSA(key) => key
                .ossl_dsa()
                .private_key_to_pem_passphrase(cipher, passphrase)?,
            KeyPairType::ECDSA(key) => key
                .ossl_ec()
                .private_key_to_pem_passphrase(cipher, passphrase)?,
            _ => return Err(ErrorKind::UnsupportType.into()),
        }
    } else {
        match &keypair.key {
            KeyPairType::RSA(key) => key.ossl_rsa().private_key_to_pem()?,
            KeyPairType::DSA(key) => key.ossl_dsa().private_key_to_pem()?,
            KeyPairType::ECDSA(key) => key.ossl_ec().private_key_to_pem()?,
            _ => return Err(ErrorKind::UnsupportType.into()),
        }
    };
    String::from_utf8(pem).map_err(|e| Error::with_error(ErrorKind::InvalidPemFormat, e))
}
pub fn stringify_pem_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 ( ) ; let passphrase = passphrase . as_bytes ( ) ; match & keypair . key { KeyPairType :: RSA ( key ) => key . ossl_rsa ( ) . private_key_to_pem_passphrase ( cipher , passphrase ) ? , KeyPairType :: DSA ( key ) => key . ossl_dsa ( ) . private_key_to_pem_passphrase ( cipher , passphrase ) ? , KeyPairType :: ECDSA ( key ) => key . ossl_ec ( ) . private_key_to_pem_passphrase ( cipher , passphrase ) ? , _ => return Err ( ErrorKind :: UnsupportType . into ( ) ) , } } else { match & keypair . key { KeyPairType :: RSA ( key ) => key . ossl_rsa ( ) . private_key_to_pem ( ) ? , KeyPairType :: DSA ( key ) => key . ossl_dsa ( ) . private_key_to_pem ( ) ? , KeyPairType :: ECDSA ( key ) => key . ossl_ec ( ) . private_key_to_pem ( ) ? , _ => return Err ( ErrorKind :: UnsupportType . into ( ) ) , } } ; String :: from_utf8 ( pem ) . map_err ( | e | Error :: with_error ( ErrorKind :: InvalidPemFormat , e ) ) }
TODO: Not to depend on openssl to parse pem file in the future
TODO : Not to depend on openssl to parse pem file in the future
keypair
&KeyPair
passphrase
Option<&str>
keypair
&KeyPair
passphrase
Option<&str>