Skip to content

Commit 7afc219

Browse files
committed
Which HTTP client that is used can be changed.
1 parent 68acf4d commit 7afc219

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/cryptojwt/key_jar.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
import logging
33
import os
44

5+
from requests import request
6+
57
from .jws.utils import alg2keytype as jws_alg2keytype
68
from .jwe.jwe import alg2keytype as jwe_alg2keytype
79

810
from .exception import DeSerializationNotPossible
911
from .key_bundle import KeyBundle
1012
from .key_bundle import ec_init
1113
from .key_bundle import rsa_init
12-
from .utils import as_bytes
13-
from .utils import b64e
1414

1515

1616
__author__ = 'Roland Hedberg'
@@ -38,7 +38,7 @@ class KeyJar(object):
3838
""" A keyjar contains a number of KeyBundles sorted by owner/issuer """
3939

4040
def __init__(self, ca_certs=None, verify_ssl=True, keybundle_cls=KeyBundle,
41-
remove_after=3600):
41+
remove_after=3600, httpc=None):
4242
"""
4343
KeyJar init function
4444
@@ -52,6 +52,7 @@ def __init__(self, ca_certs=None, verify_ssl=True, keybundle_cls=KeyBundle,
5252
self.verify_ssl = verify_ssl
5353
self.keybundle_cls = keybundle_cls
5454
self.remove_after = remove_after
55+
self.httpc = httpc or request
5556

5657
def __repr__(self):
5758
issuers = list(self.issuer_keys.keys())
@@ -74,10 +75,11 @@ def add_url(self, issuer, url, **kwargs):
7475
raise KeyError("No url given")
7576

7677
if "/localhost:" in url or "/localhost/" in url:
77-
kb = self.keybundle_cls(source=url, verify_ssl=False, **kwargs)
78+
kb = self.keybundle_cls(source=url, verify_ssl=False,
79+
httpc=self.httpc, **kwargs)
7880
else:
7981
kb = self.keybundle_cls(source=url, verify_ssl=self.verify_ssl,
80-
**kwargs)
82+
httpc=self.httpc, **kwargs)
8183

8284
self.add_kb(issuer, kb)
8385

@@ -679,10 +681,10 @@ def build_keyjar(key_conf, kid_template="", keyjar=None, owner=''):
679681

680682
kid = 0
681683

684+
tot_kb = KeyBundle()
682685
for spec in key_conf:
683686
typ = spec["type"].upper()
684687

685-
kb = {}
686688
if typ == "RSA":
687689
if "key" in spec:
688690
error_to_catch = (OSError, IOError,
@@ -699,6 +701,8 @@ def build_keyjar(key_conf, kid_template="", keyjar=None, owner=''):
699701
kb = rsa_init(spec)
700702
elif typ == "EC":
701703
kb = ec_init(spec)
704+
else:
705+
continue
702706

703707
for k in kb.keys():
704708
if kid_template:
@@ -707,7 +711,9 @@ def build_keyjar(key_conf, kid_template="", keyjar=None, owner=''):
707711
else:
708712
k.add_kid()
709713

710-
keyjar.add_kb(owner, kb)
714+
tot_kb.extend(kb.keys())
715+
716+
keyjar.add_kb(owner, tot_kb)
711717

712718
return keyjar
713719

0 commit comments

Comments
 (0)