pub fn load_key_from_filename(key_filename: &str) -> Result<PKey<Private>, String> {
    let mut f = match File::open(key_filename) {
        Ok(value) => value,
        Err(error) => return Err(format!("Error loading file {}: {:?}", &key_filename, error)),
    };
    let mut pkey_buffer = Vec::new();
    // read the whole file
    match f.read_to_end(&mut pkey_buffer) {
        Ok(_) => eprintln!("Read private key OK"),
        Err(error) => {
            return Err(format!("Failed to read private key? {:?}", error));
        }
    }

    debug!("key:  {}", key_filename);
    let keypair = match Rsa::private_key_from_pem(&pkey_buffer) {
        Ok(value) => value,
        Err(error) => {
            return Err(format!("Failed to load pkey from pem bytes: {:?}", error));
        }
    };
    // let keypair = Rsa::generate(2048).unwrap();
    match PKey::from_rsa(keypair) {
        Ok(value) => Ok(value),
        Err(error) => Err(format!("Failed to convert into PKey object: {:?}", error)),
    }
}
/// Loads a PEM-encoded public key into a PKey object
Loads a PEM-encoded public key into a PKey object
Loads a PEM - encoded public key into a PKey object
pub fn load_key_from_filename(key_filename: &str) -> Result<PKey<Private>, String> {
    let mut f = match File::open(key_filename) {
        Ok(value) => value,
        Err(error) => return Err(format!("Error loading file {}: {:?}", &key_filename, error)),
    };
    let mut pkey_buffer = Vec::new();
    // read the whole file
    match f.read_to_end(&mut pkey_buffer) {
        Ok(_) => eprintln!("Read private key OK"),
        Err(error) => {
            return Err(format!("Failed to read private key? {:?}", error));
        }
    }
    debug!("key:  {}", key_filename);
    let keypair = match Rsa::private_key_from_pem(&pkey_buffer) {
        Ok(value) => value,
        Err(error) => {
            return Err(format!("Failed to load pkey from pem bytes: {:?}", error));
        }
    };
    // let keypair = Rsa::generate(2048).unwrap();
    match PKey::from_rsa(keypair) {
        Ok(value) => Ok(value),
        Err(error) => Err(format!("Failed to convert into PKey object: {:?}", error)),
    }
}
pub fn load_key_from_filename ( key_filename : & str ) -> Result < PKey < Private > , String > { let mut f = match File :: open ( key_filename ) { Ok ( value ) => value , Err ( error ) => return Err ( format ! ( " " key_filename error ) ) , } ; let mut pkey_buffer = Vec :: new ( ) ; // read the whole file match f . read_to_end ( & mut pkey_buffer ) { Ok ( _ ) => eprintln ! ( " " ) , Err ( error ) => { return Err ( format ! ( " " error ) ) ; } } debug ! ( " " key_filename ) ; let keypair = match Rsa :: private_key_from_pem ( & pkey_buffer ) { Ok ( value ) => value , Err ( error ) => { return Err ( format ! ( " " error ) ) ; } } ; // let keypair = Rsa::generate(2048).unwrap(); match PKey :: from_rsa ( keypair ) { Ok ( value ) => Ok ( value ) , Err ( error ) => Err ( format ! ( " " error ) ) , } }
Loads a PEM-encoded public key into a PKey object
Loads a PEM - encoded public key into a PKey object
key_filename
&str
key_filename
&str