File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change 6
6
7
7
import requests
8
8
9
+ from cryptojwt .jwk .hmac import new_sym_key
9
10
from .exception import DeSerializationNotPossible
10
11
from .exception import JWKException
11
12
from .exception import UnknownKeyType
@@ -85,6 +86,38 @@ def rsa_init(spec):
85
86
return kb
86
87
87
88
89
+ def sym_init (spec ):
90
+ """
91
+ Initiates a :py:class:`oidcmsg.keybundle.KeyBundle` instance
92
+ containing newly minted SYM keys according to a spec.
93
+
94
+ Example of specification::
95
+ {'bytes':24, 'use': ['enc', 'sig'] }
96
+
97
+ Using the spec above 2 SYM keys would be minted, one for
98
+ encryption and one for signing.
99
+
100
+ :param spec:
101
+ :return: KeyBundle
102
+ """
103
+
104
+ try :
105
+ size = int (spec ['bytes' ])
106
+ except KeyError :
107
+ size = 24
108
+
109
+ kb = KeyBundle (keytype = "OCT" )
110
+ if 'use' in spec :
111
+ for use in harmonize_usage (spec ["use" ]):
112
+ _key = new_sym_key (use = use , bytes = size )
113
+ kb .append (_key )
114
+ else :
115
+ _key = new_sym_key (bytes = size )
116
+ kb .append (_key )
117
+
118
+ return kb
119
+
120
+
88
121
def ec_init (spec ):
89
122
"""
90
123
Initiate a key bundle with an elliptic curve key.
@@ -682,6 +715,8 @@ def build_key_bundle(key_conf, kid_template=""):
682
715
kb = rsa_init (spec )
683
716
elif typ == "EC" :
684
717
kb = ec_init (spec )
718
+ elif typ .upper () == "OCT" :
719
+ kb = sym_init (spec )
685
720
else :
686
721
continue
687
722
You can’t perform that action at this time.
0 commit comments