Skip to content

Commit 6c82a57

Browse files
committed
Fix StartDate conversion
Signed-off-by: Ionut Mihalcea <ionut.mihalcea@arm.com>
1 parent ec34b80 commit 6c82a57

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

cryptoki/src/object.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -877,8 +877,8 @@ impl TryFrom<CK_ATTRIBUTE> for Attribute {
877877
)
878878
};
879879
let types: Vec<MechanismType> = val
880-
.to_vec()
881-
.into_iter()
880+
.iter()
881+
.copied()
882882
.map(|t| t.try_into())
883883
.collect::<Result<Vec<MechanismType>>>()?;
884884
Ok(Attribute::AllowedMechanisms(types))
@@ -908,7 +908,7 @@ impl TryFrom<CK_ATTRIBUTE> for Attribute {
908908
}
909909
AttributeType::StartDate => {
910910
if val.is_empty() {
911-
Ok(Attribute::EndDate(Date::new_empty()))
911+
Ok(Attribute::StartDate(Date::new_empty()))
912912
} else {
913913
let date = val.as_ptr() as *const CK_DATE;
914914
unsafe {

cryptoki/tests/basic.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -706,8 +706,20 @@ fn aes_key_attributes_test() -> Result<()> {
706706
// generate a key pair
707707
let key = session.generate_key(&mechanism, &key_template)?;
708708

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

712+
if let Some(Attribute::StartDate(date)) = attributes_result.pop() {
713+
assert!(date.is_empty());
714+
} else {
715+
panic!("Last attribute was not a start date");
716+
}
717+
718+
if let Some(Attribute::EndDate(date)) = attributes_result.pop() {
719+
assert!(date.is_empty());
720+
} else {
721+
panic!("First attribute was not an end date");
722+
}
723+
712724
Ok(())
713725
}

0 commit comments

Comments
 (0)