use rpgp directly

This commit is contained in:
dignifiedquire
2019-04-26 21:58:58 +03:00
parent ff1d0ca445
commit 29993db512
16 changed files with 1143 additions and 204 deletions

19
src/pgp/hash.rs Normal file
View File

@@ -0,0 +1,19 @@
use sha2::{Digest, Sha256};
use std::slice;
use crate::pgp::cvec;
/// Calculate the SHA256 hash of the given bytes.
#[no_mangle]
pub unsafe extern "C" fn rpgp_hash_sha256(
bytes_ptr: *const u8,
bytes_len: libc::size_t,
) -> *mut cvec {
assert!(!bytes_ptr.is_null());
assert!(bytes_len > 0);
let bytes = slice::from_raw_parts(bytes_ptr, bytes_len);
let result = Sha256::digest(bytes);
Box::into_raw(Box::new(result.to_vec().into()))
}