Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.

Commit c6693f3

Browse files
committed
Cleaned up a bit.
1 parent 25c3162 commit c6693f3

File tree

7 files changed

+125
-268
lines changed

7 files changed

+125
-268
lines changed

src/oidcmsg/__init__.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,24 @@
11
__author__ = 'Roland Hedberg'
2-
__version__ = '0.4.0'
2+
__version__ = '0.5.0'
3+
4+
def proper_path(path):
5+
"""
6+
Clean up the path specification so it looks like something I could use.
7+
"./" <path> "/"
8+
"""
9+
if path.startswith("./"):
10+
pass
11+
elif path.startswith("/"):
12+
path = ".%s" % path
13+
elif path.startswith("."):
14+
while path.startswith("."):
15+
path = path[1:]
16+
if path.startswith("/"):
17+
path = ".%s" % path
18+
else:
19+
path = "./%s" % path
20+
21+
if not path.endswith("/"):
22+
path += "/"
23+
24+
return path

src/oidcmsg/key_bundle.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88

99
from cryptography.hazmat.backends import default_backend
1010
from cryptography.hazmat.primitives import serialization
11+
from cryptography.hazmat.primitives.asymmetric import ec
1112
from cryptography.hazmat.primitives.asymmetric.rsa import generate_private_key
1213

1314
from cryptojwt import as_unicode
14-
from cryptojwt.jwk import ECKey
15+
from cryptojwt.jwk import ECKey, NIST2SEC
1516
from cryptojwt.jwk import JWKException
1617
from cryptojwt.jwk import RSAKey
1718
from cryptojwt.jwk import SYMKey
@@ -116,6 +117,19 @@ def rsa_init(spec):
116117
:param spec:
117118
:return: KeyBundle
118119
"""
120+
if 'name' not in spec:
121+
try:
122+
_key_name = spec['key']
123+
except KeyError:
124+
pass
125+
else:
126+
if '/' in _key_name:
127+
(head, tail) = os.path.split(spec['key'])
128+
spec['path'] = head
129+
spec['name'] = tail
130+
else:
131+
spec['name'] = _key_name
132+
119133
arg = {}
120134
for param in ["name", "path", "size"]:
121135
try:
@@ -130,6 +144,25 @@ def rsa_init(spec):
130144
return kb
131145

132146

147+
def ec_init(spec):
148+
"""
149+
Initiate a keybundle with an elliptic curve key.
150+
151+
:param spec: Key specifics of the form::
152+
{"type": "EC", "crv": "P-256", "use": ["sig"]}
153+
154+
:return: A KeyBundle instance
155+
"""
156+
157+
_key = ec.generate_private_key(NIST2SEC[spec['crv']], default_backend())
158+
159+
kb = KeyBundle(keytype="EC", keyusage=spec["use"])
160+
for use in spec["use"]:
161+
eck = ECKey(use=use).load_key(_key)
162+
kb.append(eck)
163+
return kb
164+
165+
133166
class KeyBundle(object):
134167
def __init__(self, keys=None, source="", cache_time=300, verify_ssl=True,
135168
fileformat="jwk", keytype="RSA", keyusage=None):

0 commit comments

Comments
 (0)