Skip to content

Commit 8aee5bd

Browse files
committed
Add fixes for feedback
Signed-off-by: Joe Rozner <[email protected]>
1 parent 697a4bf commit 8aee5bd

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

cryptoki/src/object.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ use std::fmt::Formatter;
1414
use std::mem::size_of;
1515
use std::ops::Deref;
1616

17+
const MAX_CU_ULONG: CK_ULONG = !0;
18+
1719
#[derive(Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
1820
/// Type of an attribute
1921
pub enum AttributeType {
@@ -255,7 +257,9 @@ impl AttributeType {
255257
CKA_UNWRAP_TEMPLATE => String::from(stringify!(CKA_UNWRAP_TEMPLATE)),
256258
CKA_DERIVE_TEMPLATE => String::from(stringify!(CKA_DERIVE_TEMPLATE)),
257259
CKA_ALLOWED_MECHANISMS => String::from(stringify!(CKA_ALLOWED_MECHANISMS)),
258-
CKA_VENDOR_DEFINED => String::from(stringify!(CKA_VENDOR_DEFINED)),
260+
CKA_VENDOR_DEFINED..=MAX_CU_ULONG => {
261+
format!("{}_{}", stringify!(CKA_VENDOR_DEFINED), val)
262+
}
259263
_ => format!("unknown ({val:08x})"),
260264
}
261265
}
@@ -399,7 +403,7 @@ impl TryFrom<CK_ATTRIBUTE_TYPE> for AttributeType {
399403
CKA_VERIFY_RECOVER => Ok(AttributeType::VerifyRecover),
400404
CKA_WRAP => Ok(AttributeType::Wrap),
401405
CKA_WRAP_WITH_TRUSTED => Ok(AttributeType::WrapWithTrusted),
402-
0x8000_0000..=0xffff_ffff => Ok(AttributeType::VendorDefined(attribute_type)),
406+
CKA_VENDOR_DEFINED..=MAX_CU_ULONG => Ok(AttributeType::VendorDefined(attribute_type)),
403407
attr_type => {
404408
error!("Attribute type {} not supported.", attr_type);
405409
Err(Error::NotSupported)
@@ -937,7 +941,7 @@ impl TryFrom<CK_ATTRIBUTE> for Attribute {
937941
)?))
938942
}
939943
}
940-
},
944+
}
941945
AttributeType::VendorDefined(t) => Ok(Attribute::VendorDefined((t, val.to_vec()))),
942946
}
943947
}

0 commit comments

Comments
 (0)