Skip to content

Commit bcec42e

Browse files
committed
Added new function (sym_init)
1 parent 26a707f commit bcec42e

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/cryptojwt/key_bundle.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import requests
88

9+
from cryptojwt.jwk.hmac import new_sym_key
910
from .exception import DeSerializationNotPossible
1011
from .exception import JWKException
1112
from .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+
88121
def 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

0 commit comments

Comments
 (0)