feat: v1.1.11, piv sign works, add piv generate

This commit is contained in:
2022-04-09 19:57:32 +08:00
parent 27dca7af84
commit 51ba3d8500
9 changed files with 106 additions and 28 deletions

View File

@@ -35,4 +35,25 @@ pub fn sha512_bytes(input: &[u8]) -> Vec<u8> {
let mut challenge = Sha512::default();
Digest::update(&mut challenge, input);
challenge.finalize().to_vec()
}
}
macro_rules! define_copy_array {
($fn_name: ident, $len: tt) => (
pub fn $fn_name(in_arr: &[u8]) -> rust_util::XResult<[u8; $len]> {
if in_arr.len() != $len {
return simple_error!("Array length is not: {}, but is: {}", $len, in_arr.len());
}
let mut out_arr = [0_u8; $len];
for i in 0..$len {
out_arr[i] = in_arr[i];
}
Ok(out_arr)
}
)
}
define_copy_array!(copy_sha256, 0x20);
define_copy_array!(copy_sha384, 0x30);
define_copy_array!(copy_sha512, 0x40);
define_copy_array!(copy_rsa2048, 0x100);