Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update existing crypto bindings to return custom KeylimeCryptoError #52

Merged
merged 1 commit into from
Feb 26, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use std::string::String;
pub fn do_hmac(
input_key: String,
input_message: String,
) -> Result<String, ErrorStack> {
) -> Result<String, KeylimeCryptoError> {
let key = PKey::hmac(input_key.as_bytes())?;
let message = input_message.as_bytes();
let mut signer = Signer::new(MessageDigest::sha384(), &key)?;
Expand All @@ -43,11 +43,10 @@ pub fn do_hmac(
*/
pub fn rsa_import_pubkey(
input_key_path: String,
) -> Result<Rsa<Public>, ErrorStack> {
) -> Result<Rsa<Public>, KeylimeCryptoError> {
let mut key_buffer = vec![0; 1];
if let Ok(mut input_key) = File::open(input_key_path) {
input_key.read_to_end(&mut key_buffer);
}
let mut input_key = File::open(input_key_path)?;
input_key.read_to_end(&mut key_buffer)?;
Ok(Rsa::public_key_from_pem(&key_buffer)?)
}

Expand All @@ -57,7 +56,9 @@ pub fn rsa_import_pubkey(
*
* Randomly generate a callable OpenSSL RSA key object with desired key size.
*/
pub fn rsa_generate(key_size: u32) -> Result<Rsa<Private>, ErrorStack> {
pub fn rsa_generate(
key_size: u32,
) -> Result<Rsa<Private>, KeylimeCryptoError> {
Ok(Rsa::generate(key_size)?)
}

Expand All @@ -78,7 +79,7 @@ pub fn rsa_generate(key_size: u32) -> Result<Rsa<Private>, ErrorStack> {
pub fn kdf(
input_password: String,
input_salt: String,
) -> Result<String, ErrorStack> {
) -> Result<String, KeylimeCryptoError> {
let password = input_password.as_bytes();
let salt = input_salt.as_bytes();
let count = 2000;
Expand Down