Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/jose/backends/base.py: 54%
28 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:16 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:16 +0000
1from ..utils import base64url_encode, ensure_binary
4class Key:
5 """
6 A simple interface for implementing JWK keys.
7 """
9 def __init__(self, key, algorithm):
10 pass
12 def sign(self, msg):
13 raise NotImplementedError()
15 def verify(self, msg, sig):
16 raise NotImplementedError()
18 def public_key(self):
19 raise NotImplementedError()
21 def to_pem(self):
22 raise NotImplementedError()
24 def to_dict(self):
25 raise NotImplementedError()
27 def encrypt(self, plain_text, aad=None):
28 """
29 Encrypt the plain text and generate an auth tag if appropriate
31 Args:
32 plain_text (bytes): Data to encrypt
33 aad (bytes, optional): Authenticated Additional Data if key's algorithm supports auth mode
35 Returns:
36 (bytes, bytes, bytes): IV, cipher text, and auth tag
37 """
38 raise NotImplementedError()
40 def decrypt(self, cipher_text, iv=None, aad=None, tag=None):
41 """
42 Decrypt the cipher text and validate the auth tag if present
43 Args:
44 cipher_text (bytes): Cipher text to decrypt
45 iv (bytes): IV if block mode
46 aad (bytes): Additional Authenticated Data to verify if auth mode
47 tag (bytes): Authentication tag if auth mode
49 Returns:
50 bytes: Decrypted value
51 """
52 raise NotImplementedError()
54 def wrap_key(self, key_data):
55 """
56 Wrap the the plain text key data
58 Args:
59 key_data (bytes): Key data to wrap
61 Returns:
62 bytes: Wrapped key
63 """
64 raise NotImplementedError()
66 def unwrap_key(self, wrapped_key):
67 """
68 Unwrap the the wrapped key data
70 Args:
71 wrapped_key (bytes): Wrapped key data to unwrap
73 Returns:
74 bytes: Unwrapped key
75 """
76 raise NotImplementedError()
79class DIRKey(Key):
80 def __init__(self, key_data, algorithm):
81 self._key = ensure_binary(key_data)
82 self._alg = algorithm
84 def to_dict(self):
85 return {
86 "alg": self._alg,
87 "kty": "oct",
88 "k": base64url_encode(self._key),
89 }