Skip to content

Commit

Permalink
Adjusted interface to remove Option<> enum around template
Browse files Browse the repository at this point in the history
Signed-off-by: Eric Devolder <[email protected]>
  • Loading branch information
keldonin committed Aug 28, 2024
1 parent 5bd3664 commit 9fe0885
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
13 changes: 4 additions & 9 deletions cryptoki/src/session/object_management.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,24 +97,19 @@ impl Session {
}

/// Copy an object
/// A optional template can be provided to change some attributes of the new object, when allowed.
/// A template can be provided to change some attributes of the new object, when allowed.
///
/// # Arguments
///
/// * `object` - The [ObjectHandle] used to reference the object to copy
/// * `template` - an optional reference to a slice of attributes, in the form of `Some(&[Attribute])`,
/// or set to `None`` if not needed.
/// * `template` - a reference to a slice of attributes
///
/// # Returns
///
/// This function will return a new [ObjectHandle] that references the newly created object.
///
pub fn copy_object(&self, object: ObjectHandle, template: Option<&[Attribute]>) -> Result<ObjectHandle> {
let mut template: Vec<CK_ATTRIBUTE> = match template {
Some(template) => template.iter().map(|attr| attr.into()).collect(),
None => Vec::new(),
};

pub fn copy_object(&self, object: ObjectHandle, template: &[Attribute]) -> Result<ObjectHandle> {
let mut template: Vec<CK_ATTRIBUTE> = template.iter().map(|attr| attr.into()).collect();
let mut object_handle = 0;

unsafe {
Expand Down
6 changes: 3 additions & 3 deletions cryptoki/tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -873,15 +873,15 @@ fn session_copy_object() -> TestResult {
let object = rw_session.generate_key(&Mechanism::AesKeyGen, &aes128_template)?;

// copy the object without a template
let copy = rw_session.copy_object(object, None)?;
let copy = rw_session.copy_object(object, &[])?;
rw_session.destroy_object(copy)?;

// copy the object with a template
let copy = rw_session.copy_object(object, Some(&copy_template))?;
let copy = rw_session.copy_object(object, &copy_template)?;
rw_session.destroy_object(copy)?;

// try the copy with the insecure template. It should fail. Returning CKR_OK is considered a failure.
rw_session.copy_object(object, Some(&insecure_copy_template)).unwrap_err();
rw_session.copy_object(object, &insecure_copy_template).unwrap_err();

// delete keys
rw_session.destroy_object(object)?;
Expand Down

0 comments on commit 9fe0885

Please sign in to comment.