1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#![feature(rustc_private)]
#![feature(libc)]
extern crate libc;
mod native;
pub type Result<T> = std::result::Result<T, JhError>;
pub fn hash(hashbitlen: i32, data: &[u8], hashval: &mut [u8]) -> Result<()> {
match unsafe { native::jh_hash(hashbitlen, data.as_ptr(), data.len() as u64 * 8, hashval.as_mut_ptr()) } {
0 => Ok(()),
e => Err(JhError::from(e)),
}
}
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
pub enum JhError {
Fail,
BadHashbitlen,
}
impl From<i32> for JhError {
fn from(i: i32) -> Self {
match i {
0 => panic!("Not an error"),
1 => JhError::Fail,
2 => JhError::BadHashbitlen,
_ => panic!("Incorrect error number"),
}
}
}