-
Notifications
You must be signed in to change notification settings - Fork 4
/
smime_constants.py
56 lines (42 loc) · 1.11 KB
/
smime_constants.py
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
import enum
import math
import sys
from pyasn1.type.univ import ObjectIdentifier
CABF_SMIME_OID_ARC = ObjectIdentifier('2.23.140.1.5')
@enum.unique
class ValidationLevel(enum.IntEnum):
MAILBOX = 1
ORGANIZATION = 2
SPONSORED = 4
INDIVIDUAL = 8
[
setattr(
sys.modules[__name__],
f'CABF_SMIME_{v.name}_OID_ARC',
CABF_SMIME_OID_ARC + (int(math.log2(v)) + 1,)
)
for v in ValidationLevel
]
@enum.unique
class Generation(enum.IntEnum):
LEGACY = 1 << 8
MULTIPURPOSE = 1 << 9
STRICT = 1 << 10
def _define_oids(validation_level):
[
setattr(
sys.modules[__name__],
f'CABF_SMIME_{validation_level.name}_{g.name}_OID',
CABF_SMIME_OID_ARC + (
int(math.log2(validation_level)) + 1,
int(math.log2(g >> 8)) + 1,
)
)
for g in Generation
]
[_define_oids(v) for v in ValidationLevel]
def get_policy_oid(validation_level, generation):
return CABF_SMIME_OID_ARC + (
int(math.log2(validation_level)) + 1,
int(math.log2(generation >> 8)) + 1,
)