4
4
import json
5
5
import logging
6
6
import os
7
+ import threading
7
8
import time
8
9
from datetime import datetime
9
10
from functools import cmp_to_key
10
11
from typing import List
11
12
from typing import Optional
12
13
13
14
import requests
14
- from readerwriterlock import rwlock
15
15
16
16
from cryptojwt .jwk .ec import NIST2SEC
17
17
from cryptojwt .jwk .hmac import new_sym_key
@@ -153,14 +153,6 @@ def ec_init(spec):
153
153
return _kb
154
154
155
155
156
- def keys_reader (func ):
157
- def wrapper (self , * args , ** kwargs ):
158
- with self ._lock_reader :
159
- return func (self , * args , ** kwargs )
160
-
161
- return wrapper
162
-
163
-
164
156
def keys_writer (func ):
165
157
def wrapper (self , * args , ** kwargs ):
166
158
with self ._lock_writer :
@@ -246,9 +238,7 @@ def __init__(
246
238
self .source = None
247
239
self .time_out = 0
248
240
249
- self ._lock = rwlock .RWLockFairD ()
250
- self ._lock_reader = self ._lock .gen_rlock ()
251
- self ._lock_writer = self ._lock .gen_wlock ()
241
+ self ._lock_writer = threading .Lock ()
252
242
253
243
if httpc :
254
244
self .httpc = httpc
@@ -592,12 +582,11 @@ def get(self, typ="", only_active=True):
592
582
"""
593
583
self ._uptodate ()
594
584
595
- with self ._lock_reader :
596
- if typ :
597
- _typs = [typ .lower (), typ .upper ()]
598
- _keys = [k for k in self ._keys if k .kty in _typs ]
599
- else :
600
- _keys = self ._keys [:]
585
+ if typ :
586
+ _typs = [typ .lower (), typ .upper ()]
587
+ _keys = [k for k in self ._keys [:] if k .kty in _typs ]
588
+ else :
589
+ _keys = self ._keys [:]
601
590
602
591
if only_active :
603
592
return [k for k in _keys if not k .inactive_since ]
@@ -612,8 +601,7 @@ def keys(self, update: bool = True):
612
601
"""
613
602
if update :
614
603
self ._uptodate ()
615
- with self ._lock_reader :
616
- return self ._keys [:]
604
+ return self ._keys [:]
617
605
618
606
def active_keys (self ):
619
607
"""Return the set of active keys."""
@@ -685,7 +673,6 @@ def remove(self, key):
685
673
except ValueError :
686
674
pass
687
675
688
- @keys_reader
689
676
def __len__ (self ):
690
677
"""
691
678
The number of keys.
@@ -707,8 +694,7 @@ def get_key_with_kid(self, kid):
707
694
:return: The key or None
708
695
"""
709
696
self ._uptodate ()
710
- with self ._lock_reader :
711
- return self ._get_key_with_kid (kid )
697
+ return self ._get_key_with_kid (kid )
712
698
713
699
def _get_key_with_kid (self , kid ):
714
700
for key in self ._keys :
@@ -775,7 +761,6 @@ def remove_outdated(self, after, when=0):
775
761
def __contains__ (self , key ):
776
762
return key in self .keys ()
777
763
778
- @keys_reader
779
764
def copy (self ):
780
765
"""
781
766
Make deep copy of this KeyBundle
0 commit comments