Skip to content

Commit

Permalink
get_public_key_interal test successful
Browse files Browse the repository at this point in the history
  • Loading branch information
mlitchard committed May 17, 2022
1 parent f13cb13 commit efa79bb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
9 changes: 5 additions & 4 deletions rustbits/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ pub extern "C" fn put_ed_key(
&& object_info.object_type == object::Type::AsymmetricKey
}

Err(_) => panic!("get public key failed in testing"),
Err(_) => panic!("put asymmetric key failed in testing"),
}
} else {
true
Expand Down Expand Up @@ -152,12 +152,13 @@ pub fn put_ed_key_internal(
.expect("could not put the key");
}


/// # Safety
///
/// To Do -mlitchard
pub unsafe fn get_public_key(kid: u16,result: *mut u8, testing_mock: bool ) {
let connector = make_connector(testing_mock);
let client: Client = create_client(connector).expect("could not connect to YubiHSM");
pub unsafe fn get_public_key_internal(client: &Client,kid: u16,result: *mut u8 ) {
// let connector = make_connector(testing_mock);
// let client: Client = create_client(connector).expect("could not connect to YubiHSM");
let mut err_result: Vec<u8> = zeroes(KEY_SIZE);

match client.get_public_key(kid) {
Expand Down
25 changes: 23 additions & 2 deletions rustbits/src/test.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#[cfg(test)]
mod tests {
use crate::create_client;
use crate::get_public_key_internal;
use crate::hello_world;
use crate::make_connector;
use crate::sign_with_ed_key_internal;
Expand Down Expand Up @@ -47,9 +48,7 @@ mod tests {
#[test]
fn test_sign_with_ed_key() {
use yubihsm::asymmetric;

let mut res = [0u8; 64];

let connector: Connector = make_connector(true);
let client: Client = create_client(connector).expect("could not connect to YubiHSM");

Expand All @@ -68,4 +67,26 @@ mod tests {

assert_eq!(SIGNATURE, &res);
}

#[test]
fn test_get_pub_key() {
use yubihsm::asymmetric;

let connector: Connector = make_connector(true);
let client: Client = create_client(connector).expect("could not connect to YubiHSM");
let mut res = [0u8; 32];
client
.put_asymmetric_key(
TEST_KEY_ID,
TEST_SIGNING_KEY_LABEL.into(),
TEST_SIGNING_KEY_DOMAINS,
Capability::SIGN_EDDSA,
asymmetric::Algorithm::Ed25519,
SECRETKEY.to_vec(),
)
.expect("test_get_pub_key failed to put_asymmetric_key()");

unsafe {get_public_key_internal(&client, TEST_KEY_ID, res.as_mut_ptr())};
assert_eq!(PUBLICKEY,&res);
}
}

0 comments on commit efa79bb

Please sign in to comment.