Skip to content

Commit ef90e71

Browse files
committed
Rename MAX_CK_ULONG + move to crate root
Signed-off-by: Thore Goebel <git@thore.io>
1 parent 868a6d8 commit ef90e71

2 files changed

Lines changed: 7 additions & 6 deletions

File tree

cryptoki/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ pub mod types;
4949

5050
use cryptoki_sys::CK_UTF8CHAR;
5151

52+
const MAX_CK_ULONG: cryptoki_sys::CK_ULONG = !0;
53+
5254
fn string_from_blank_padded(field: &[CK_UTF8CHAR]) -> String {
5355
let decoded_str = String::from_utf8_lossy(field);
5456
decoded_str.trim_end_matches(' ').to_string()

cryptoki/src/object.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use crate::error::{Error, Result};
66
use crate::mechanism::MechanismType;
77
use crate::types::{Date, Ulong};
8+
use crate::MAX_CK_ULONG;
89
use cryptoki_sys::*;
910
use log::error;
1011
use std::convert::TryFrom;
@@ -14,8 +15,6 @@ use std::fmt::Formatter;
1415
use std::mem::size_of;
1516
use std::ops::Deref;
1617

17-
const MAX_CU_ULONG: CK_ULONG = !0;
18-
1918
#[derive(Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
2019
#[non_exhaustive]
2120
/// Type of an attribute
@@ -261,7 +260,7 @@ impl AttributeType {
261260
CKA_DERIVE_TEMPLATE => String::from(stringify!(CKA_DERIVE_TEMPLATE)),
262261
CKA_ALLOWED_MECHANISMS => String::from(stringify!(CKA_ALLOWED_MECHANISMS)),
263262
CKA_UNIQUE_ID => String::from(stringify!(CKA_UNIQUE_ID)),
264-
CKA_VENDOR_DEFINED..=MAX_CU_ULONG => {
263+
CKA_VENDOR_DEFINED..=MAX_CK_ULONG => {
265264
format!("{}_{}", stringify!(CKA_VENDOR_DEFINED), val)
266265
}
267266
_ => format!("unknown ({val:08x})"),
@@ -409,7 +408,7 @@ impl TryFrom<CK_ATTRIBUTE_TYPE> for AttributeType {
409408
CKA_VERIFY_RECOVER => Ok(AttributeType::VerifyRecover),
410409
CKA_WRAP => Ok(AttributeType::Wrap),
411410
CKA_WRAP_WITH_TRUSTED => Ok(AttributeType::WrapWithTrusted),
412-
CKA_VENDOR_DEFINED..=MAX_CU_ULONG => Ok(AttributeType::VendorDefined(attribute_type)),
411+
CKA_VENDOR_DEFINED..=MAX_CK_ULONG => Ok(AttributeType::VendorDefined(attribute_type)),
413412
attr_type => {
414413
error!("Attribute type {} not supported.", attr_type);
415414
Err(Error::NotSupported)
@@ -1296,7 +1295,7 @@ impl KeyType {
12961295
CKK_EC_EDWARDS => String::from(stringify!(CKK_EC_EDWARDS)),
12971296
CKK_EC_MONTGOMERY => String::from(stringify!(CKK_EC_MONTGOMERY)),
12981297
CKK_HKDF => String::from(stringify!(CKK_HKDF)),
1299-
CKK_VENDOR_DEFINED..=MAX_CU_ULONG => String::from(stringify!(key_type)),
1298+
CKK_VENDOR_DEFINED..=MAX_CK_ULONG => String::from(stringify!(key_type)),
13001299
_ => format!("unknown ({key_type:08x})"),
13011300
}
13021301
}
@@ -1371,7 +1370,7 @@ impl TryFrom<CK_KEY_TYPE> for KeyType {
13711370
CKK_EC_EDWARDS => Ok(KeyType::EC_EDWARDS),
13721371
CKK_EC_MONTGOMERY => Ok(KeyType::EC_MONTGOMERY),
13731372
CKK_HKDF => Ok(KeyType::HKDF),
1374-
CKK_VENDOR_DEFINED..=MAX_CU_ULONG => KeyType::new_vendor_defined(key_type),
1373+
CKK_VENDOR_DEFINED..=MAX_CK_ULONG => KeyType::new_vendor_defined(key_type),
13751374
_ => {
13761375
error!("Key type {} is not supported.", key_type);
13771376
Err(Error::NotSupported)

0 commit comments

Comments
 (0)