Skip to content

Commit 89fae3e

Browse files
committed
fix: warn about possible unsafe key for OctKey instead of raising error. #32
1 parent a44cd5a commit 89fae3e

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

src/joserfc/rfc7518/oct_key.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22
from typing import Any
33
import secrets
4+
import warnings
45
from ..util import (
56
to_bytes,
67
urlsafe_b64decode,
@@ -35,7 +36,7 @@ def import_from_dict(cls, value: DictKey) -> bytes:
3536
def import_from_bytes(cls, value: bytes, password: Any | None = None) -> bytes:
3637
# security check
3738
if value.startswith(POSSIBLE_UNSAFE_KEYS):
38-
raise ValueError("This key may not be safe to import")
39+
warnings.warn("This key may not be safe to import")
3940
return value
4041

4142

tests/jwk/test_oct_key.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def test_invalid_key_ops(self):
8080

8181
def test_import_pem_key(self):
8282
public_pem = read_key("ec-p256-public.pem")
83-
self.assertRaises(ValueError, OctKey.import_key, public_pem)
83+
self.assertWarns(UserWarning, OctKey.import_key, public_pem)
8484

8585
def test_generate_key(self):
8686
key = OctKey.generate_key()

0 commit comments

Comments
 (0)