Skip to content

Commit

Permalink
Fix StartDate conversion
Browse files Browse the repository at this point in the history
Signed-off-by: Ionut Mihalcea <[email protected]>
  • Loading branch information
ionut-arm committed Mar 2, 2022
1 parent a78d2be commit 904d88f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
6 changes: 3 additions & 3 deletions cryptoki/src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -877,8 +877,8 @@ impl TryFrom<CK_ATTRIBUTE> for Attribute {
)
};
let types: Vec<MechanismType> = val
.to_vec()
.into_iter()
.iter()
.copied()
.map(|t| t.try_into())
.collect::<Result<Vec<MechanismType>>>()?;
Ok(Attribute::AllowedMechanisms(types))
Expand Down Expand Up @@ -908,7 +908,7 @@ impl TryFrom<CK_ATTRIBUTE> for Attribute {
}
AttributeType::StartDate => {
if val.is_empty() {
Ok(Attribute::EndDate(Date::new_empty()))
Ok(Attribute::StartDate(Date::new_empty()))
} else {
let date = val.as_ptr() as *const CK_DATE;
unsafe {
Expand Down
14 changes: 13 additions & 1 deletion cryptoki/tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -706,8 +706,20 @@ fn aes_key_attributes_test() -> Result<()> {
// generate a key pair
let key = session.generate_key(&mechanism, &key_template)?;

let _attributes_result =
let mut attributes_result =
session.get_attributes(key, &[AttributeType::EndDate, AttributeType::StartDate])?;

if let Some(Attribute::StartDate(date)) = attributes_result.pop() {
assert!(date.is_empty());
} else {
panic!("Last attribute was not a start date");
}

if let Some(Attribute::EndDate(date)) = attributes_result.pop() {
assert!(date.is_empty());
} else {
panic!("First attribute was not an end date");
}

Ok(())
}

0 comments on commit 904d88f

Please sign in to comment.