Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Object ID attribute #26

Merged
merged 1 commit into from
Jun 17, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions cryptoki/src/types/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ pub enum AttributeType {
Modulus,
/// Length in bits of the modulus of a key
ModulusBits,
/// Object ID
ObjectId,
/// Prime number value of a key
Prime,
/// Determines if the object is private
Expand Down Expand Up @@ -95,6 +97,7 @@ impl From<AttributeType> for CK_ATTRIBUTE_TYPE {
AttributeType::Modifiable => CKA_MODIFIABLE,
AttributeType::Modulus => CKA_MODULUS,
AttributeType::ModulusBits => CKA_MODULUS_BITS,
AttributeType::ObjectId => CKA_OBJECT_ID,
AttributeType::Prime => CKA_PRIME,
AttributeType::Private => CKA_PRIVATE,
AttributeType::PublicExponent => CKA_PUBLIC_EXPONENT,
Expand Down Expand Up @@ -133,6 +136,7 @@ impl TryFrom<CK_ATTRIBUTE_TYPE> for AttributeType {
CKA_MODIFIABLE => Ok(AttributeType::Modifiable),
CKA_MODULUS => Ok(AttributeType::Modulus),
CKA_MODULUS_BITS => Ok(AttributeType::ModulusBits),
CKA_OBJECT_ID => Ok(AttributeType::ObjectId),
CKA_PRIME => Ok(AttributeType::Prime),
CKA_PRIVATE => Ok(AttributeType::Private),
CKA_PUBLIC_EXPONENT => Ok(AttributeType::PublicExponent),
Expand Down Expand Up @@ -190,6 +194,8 @@ pub enum Attribute {
Modulus(Vec<u8>),
/// Length in bits of the modulus of a key
ModulusBits(Ulong),
/// Object ID
ObjectId(Vec<u8>),
/// Prime number value of a key
Prime(Vec<u8>),
/// Determines if the object is private
Expand Down Expand Up @@ -238,6 +244,7 @@ impl Attribute {
Attribute::Modifiable(_) => AttributeType::Modifiable,
Attribute::Modulus(_) => AttributeType::Modulus,
Attribute::ModulusBits(_) => AttributeType::ModulusBits,
Attribute::ObjectId(_) => AttributeType::ObjectId,
Attribute::Prime(_) => AttributeType::Prime,
Attribute::Private(_) => AttributeType::Private,
Attribute::PublicExponent(_) => AttributeType::PublicExponent,
Expand Down Expand Up @@ -279,6 +286,7 @@ impl Attribute {
Attribute::KeyType(_) => std::mem::size_of::<CK_KEY_TYPE>(),
Attribute::Label(label) => std::mem::size_of::<CK_UTF8CHAR>() * label.len(),
Attribute::ModulusBits(_) => std::mem::size_of::<CK_ULONG>(),
Attribute::ObjectId(bytes) => bytes.len(),
Attribute::Prime(bytes) => bytes.len(),
Attribute::PublicExponent(bytes) => bytes.len(),
Attribute::Modulus(bytes) => bytes.len(),
Expand Down Expand Up @@ -326,6 +334,7 @@ impl Attribute {
| Attribute::EcParams(bytes)
| Attribute::EcPoint(bytes)
| Attribute::Label(bytes)
| Attribute::ObjectId(bytes)
| Attribute::Prime(bytes)
| Attribute::PublicExponent(bytes)
| Attribute::Modulus(bytes)
Expand Down Expand Up @@ -397,6 +406,7 @@ impl TryFrom<CK_ATTRIBUTE> for Attribute {
AttributeType::Prime => Ok(Attribute::Prime(val.to_vec())),
AttributeType::PublicExponent => Ok(Attribute::PublicExponent(val.to_vec())),
AttributeType::Modulus => Ok(Attribute::Modulus(val.to_vec())),
AttributeType::ObjectId => Ok(Attribute::ObjectId(val.to_vec())),
AttributeType::Value => Ok(Attribute::Value(val.to_vec())),
AttributeType::Id => Ok(Attribute::Id(val.to_vec())),
// Unique types
Expand Down