Import a key from bytes, string, or dict data.
(cls, raw, options=None)
| 64 | |
| 65 | @classmethod |
| 66 | def import_key(cls, raw, options=None): |
| 67 | """Import a key from bytes, string, or dict data.""" |
| 68 | if isinstance(raw, cls): |
| 69 | if options is not None: |
| 70 | raw.options.update(options) |
| 71 | return raw |
| 72 | |
| 73 | if isinstance(raw, dict): |
| 74 | cls.check_required_fields(raw) |
| 75 | key = cls(options=options) |
| 76 | key._dict_data = raw |
| 77 | else: |
| 78 | raw_key = to_bytes(raw) |
| 79 | |
| 80 | # security check |
| 81 | if raw_key.startswith(POSSIBLE_UNSAFE_KEYS): |
| 82 | raise ValueError("This key may not be safe to import") |
| 83 | |
| 84 | key = cls(raw_key=raw_key, options=options) |
| 85 | return key |
| 86 | |
| 87 | @classmethod |
| 88 | def generate_key(cls, key_size=256, options=None, is_private=True): |