Skip to content

Commit

Permalink
tests: Reproducer for reading certificate object
Browse files Browse the repository at this point in the history
Signed-off-by: Jakub Jelen <[email protected]>
  • Loading branch information
Jakuje authored and simo5 committed Dec 12, 2024
1 parent 97ae9ea commit abfb25c
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/tests/nssdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ fn test_nssdb_init_token() {

/* add a public object to ensure attributes are handled correctly
* CKA_VALUE is encrypted only for private objects */
let _ = ret_or_panic!(import_object(
let cert_handle = ret_or_panic!(import_object(
session,
CKO_CERTIFICATE,
&[(CKA_CERTIFICATE_TYPE, CKC_X_509)],
Expand All @@ -218,6 +218,28 @@ fn test_nssdb_init_token() {
&[(CKA_TOKEN, true), (CKA_TRUSTED, false)],
));

/* Read the cert back */
let mut template =
make_ptrs_template(&[(CKA_VALUE, std::ptr::null_mut(), 0)]);
let ret = fn_get_attribute_value(
session,
cert_handle,
template.as_mut_ptr(),
template.len() as CK_ULONG,
);
assert_eq!(ret, CKR_OK);
assert_eq!(template[0].ulValueLen, 5);
let mut value = vec![0u8; 5];
template[0].pValue = void_ptr!(value.as_mut_ptr());
let ret = fn_get_attribute_value(
session,
cert_handle,
template.as_mut_ptr(),
template.len() as CK_ULONG,
);
assert_eq!(ret, CKR_OK);
assert_eq!(value.as_slice(), "value".as_bytes());

let ret = fn_logout(session);
assert_eq!(ret, CKR_OK);

Expand Down

0 comments on commit abfb25c

Please sign in to comment.