forked from LudovicRousseau/PyKCS11
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_constants.py
More file actions
executable file
·64 lines (50 loc) · 1.56 KB
/
Copy pathgenerate_constants.py
File metadata and controls
executable file
·64 lines (50 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python3
"""
Generate the constants.py file
"""
import sys
import PyKCS11.LowLevel
HEADER = """# pylint: disable=missing-module-docstring, disable=too-many-lines
import PyKCS11.LowLevel
# This file is generated by "make constants"
# To not edit by hand
# redefine PKCS#11 constants
CK_TRUE = PyKCS11.LowLevel.CK_TRUE
CK_FALSE = PyKCS11.LowLevel.CK_FALSE
CK_UNAVAILABLE_INFORMATION = PyKCS11.LowLevel.CK_UNAVAILABLE_INFORMATION
CK_EFFECTIVELY_INFINITE = PyKCS11.LowLevel.CK_EFFECTIVELY_INFINITE
CK_INVALID_HANDLE = PyKCS11.LowLevel.CK_INVALID_HANDLE
"""
if __name__ == "__main__":
print(HEADER)
old_head = ""
# redefine PKCS#11 constants using well known prefixes
this = sys.modules[__name__]
for k, v in PyKCS11.LowLevel.__dict__.items():
if k[:4] in [
"CKA_",
"CKC_",
"CKD_",
"CKF_",
"CKG_",
"CKH_",
"CKK_",
"CKM_",
"CKO_",
"CKR_",
"CKS_",
"CKU_",
"CKZ_",
]:
head = k[:3] # 'CKM_RSA_PKCS' => 'CKM'
if head != old_head:
print(f"\n# {head} constants")
print(f"{head} = {{}}")
old_head = head
print(f"{k} = PyKCS11.LowLevel.{k}")
if k[3:] != "_VENDOR_DEFINED":
# CKM['CKM_RSA_PKCS'] = CKM_RSA_PKCS
print(f'{head}["{k}"] = {k}')
# CKM[CKM_RSA_PKCS] = 'CKM_RSA_PKCS'
print(f'{head}[{k}] = "{k}"')
print()