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 66
77import requests
88
9+ from cryptojwt .jwk .hmac import new_sym_key
910from .exception import DeSerializationNotPossible
1011from .exception import JWKException
1112from .exception import UnknownKeyType
@@ -85,6 +86,38 @@ def rsa_init(spec):
8586 return kb
8687
8788
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+
88121def ec_init (spec ):
89122 """
90123 Initiate a key bundle with an elliptic curve key.
@@ -682,6 +715,8 @@ def build_key_bundle(key_conf, kid_template=""):
682715 kb = rsa_init (spec )
683716 elif typ == "EC" :
684717 kb = ec_init (spec )
718+ elif typ .upper () == "OCT" :
719+ kb = sym_init (spec )
685720 else :
686721 continue
687722
You can’t perform that action at this time.
0 commit comments