(data: Any)
| 9 | |
| 10 | |
| 11 | def import_any_key(data: Any): |
| 12 | if "authlib.jose" in sys.modules: |
| 13 | from authlib.jose.rfc7518 import ECKey |
| 14 | from authlib.jose.rfc7518 import OctKey |
| 15 | from authlib.jose.rfc7518 import RSAKey |
| 16 | from authlib.jose.rfc8037 import OKPKey |
| 17 | |
| 18 | if isinstance(data, (OctKey, RSAKey, ECKey, OKPKey)): |
| 19 | deprecate("Please use joserfc to import keys.", version="2.0.0") |
| 20 | return import_key(data.as_dict(is_private=not data.public_only)) |
| 21 | |
| 22 | if ( |
| 23 | isinstance(data, str) |
| 24 | and data.strip().startswith("{") |
| 25 | and data.strip().endswith("}") |
| 26 | ): |
| 27 | deprecate( |
| 28 | "Please use OctKey, RSAKey, ECKey, OKPKey, and KeySet directly.", |
| 29 | version="2.0.0", |
| 30 | ) |
| 31 | data = json_loads(data) |
| 32 | |
| 33 | if isinstance(data, (str, bytes)): |
| 34 | deprecate( |
| 35 | "Please use OctKey, RSAKey, ECKey, OKPKey, and KeySet directly.", |
| 36 | version="2.0.0", |
| 37 | ) |
| 38 | return import_key(data) |
| 39 | |
| 40 | elif isinstance(data, dict): |
| 41 | if "keys" in data: |
| 42 | deprecate( |
| 43 | "Please `KeySet.import_key_set` from `joserfc.jwk` to import jwks.", |
| 44 | version="2.0.0", |
| 45 | ) |
| 46 | return KeySet.import_key_set(data) |
| 47 | return import_key(data) |
| 48 | return data |
searching dependent graphs…