Skip to content

Commit 0b0a91f

Browse files
Manage attributes through AttributeMapper class
- Provide entry point for user overrides in object templates - Allow user-supplied support for extra attributes in a forward-compatible manner
1 parent d7e9098 commit 0b0a91f

File tree

5 files changed

+249
-213
lines changed

5 files changed

+249
-213
lines changed

pkcs11/_pkcs11.pxd

Lines changed: 0 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -626,83 +626,6 @@ cdef inline CK_ULONG_buffer(length):
626626
return array(shape=(length,), itemsize=sizeof(CK_ULONG), format='L')
627627

628628

629-
cdef inline bytes _pack_attribute(key, value):
630-
"""Pack a Attribute value into a bytes array."""
631-
632-
try:
633-
pack, _ = ATTRIBUTE_TYPES[key]
634-
return pack(value)
635-
except KeyError:
636-
raise NotImplementedError("Can't pack this %s. "
637-
"Expand ATTRIBUTE_TYPES!" % key)
638-
639-
640-
cdef inline _unpack_attributes(key, value):
641-
"""Unpack a Attribute bytes array into a Python value."""
642-
643-
try:
644-
_, unpack = ATTRIBUTE_TYPES[key]
645-
return unpack(value)
646-
except KeyError:
647-
raise NotImplementedError("Can't unpack this %s. "
648-
"Expand ATTRIBUTE_TYPES!" % key)
649-
650-
651-
cdef inline _default_public_key_template(
652-
capabilities, id, label, store,
653-
):
654-
# Build attributes
655-
return {
656-
Attribute.CLASS: ObjectClass.PUBLIC_KEY,
657-
Attribute.ID: id or b'',
658-
Attribute.LABEL: label or '',
659-
Attribute.TOKEN: store,
660-
# Capabilities
661-
Attribute.ENCRYPT: MechanismFlag.ENCRYPT & capabilities,
662-
Attribute.WRAP: MechanismFlag.WRAP & capabilities,
663-
Attribute.VERIFY: MechanismFlag.VERIFY & capabilities,
664-
}
665-
666-
667-
cdef inline _default_private_key_template(
668-
capabilities, id, label, store,
669-
):
670-
return {
671-
Attribute.CLASS: ObjectClass.PRIVATE_KEY,
672-
Attribute.ID: id or b'',
673-
Attribute.LABEL: label or '',
674-
Attribute.TOKEN: store,
675-
Attribute.PRIVATE: True,
676-
Attribute.SENSITIVE: True,
677-
# Capabilities
678-
Attribute.DECRYPT: MechanismFlag.DECRYPT & capabilities,
679-
Attribute.UNWRAP: MechanismFlag.UNWRAP & capabilities,
680-
Attribute.SIGN: MechanismFlag.SIGN & capabilities,
681-
Attribute.DERIVE: MechanismFlag.DERIVE & capabilities,
682-
}
683-
684-
685-
cdef inline _default_secret_key_template(
686-
capabilities, id, label, store,
687-
):
688-
return {
689-
Attribute.CLASS: ObjectClass.SECRET_KEY,
690-
Attribute.ID: id or b'',
691-
Attribute.LABEL: label or '',
692-
Attribute.TOKEN: store,
693-
Attribute.PRIVATE: True,
694-
Attribute.SENSITIVE: True,
695-
# Capabilities
696-
Attribute.ENCRYPT: MechanismFlag.ENCRYPT & capabilities,
697-
Attribute.DECRYPT: MechanismFlag.DECRYPT & capabilities,
698-
Attribute.WRAP: MechanismFlag.WRAP & capabilities,
699-
Attribute.UNWRAP: MechanismFlag.UNWRAP & capabilities,
700-
Attribute.SIGN: MechanismFlag.SIGN & capabilities,
701-
Attribute.VERIFY: MechanismFlag.VERIFY & capabilities,
702-
Attribute.DERIVE: MechanismFlag.DERIVE & capabilities,
703-
}
704-
705-
706629
cdef inline object map_rv_to_error(
707630
CK_RV rv
708631
):

0 commit comments

Comments
 (0)