Construct a Key object for the given algorithm with the given key_data.
(key_data, algorithm=None)
| 61 | |
| 62 | |
| 63 | def construct(key_data, algorithm=None): |
| 64 | """ |
| 65 | Construct a Key object for the given algorithm with the given |
| 66 | key_data. |
| 67 | """ |
| 68 | |
| 69 | # Allow for pulling the algorithm off of the passed in jwk. |
| 70 | if not algorithm and isinstance(key_data, dict): |
| 71 | algorithm = key_data.get("alg", None) |
| 72 | |
| 73 | if not algorithm: |
| 74 | raise JWKError("Unable to find an algorithm for key") |
| 75 | |
| 76 | key_class = get_key(algorithm) |
| 77 | if not key_class: |
| 78 | raise JWKError("Unable to find an algorithm for key") |
| 79 | return key_class(key_data, algorithm) |