Create a new HMAC object. key: bytes or buffer, key for the keyed hash object. msg: bytes or buffer, Initial input for the hash or None. digestmod: A hash name suitable for hashlib.new(). *OR* A hashlib constructor returning a new hash object. *OR*
(self, key, msg=None, digestmod='')
| 64 | ) |
| 65 | |
| 66 | def __init__(self, key, msg=None, digestmod=''): |
| 67 | """Create a new HMAC object. |
| 68 | |
| 69 | key: bytes or buffer, key for the keyed hash object. |
| 70 | msg: bytes or buffer, Initial input for the hash or None. |
| 71 | digestmod: A hash name suitable for hashlib.new(). *OR* |
| 72 | A hashlib constructor returning a new hash object. *OR* |
| 73 | A module supporting PEP 247. |
| 74 | |
| 75 | Required as of 3.8, despite its position after the optional |
| 76 | msg argument. Passing it as a keyword argument is |
| 77 | recommended, though not required for legacy API reasons. |
| 78 | """ |
| 79 | |
| 80 | if not isinstance(key, (bytes, bytearray)): |
| 81 | raise TypeError(f"key: expected bytes or bytearray, " |
| 82 | f"but got {type(key).__name__!r}") |
| 83 | |
| 84 | if not digestmod: |
| 85 | raise TypeError("Missing required argument 'digestmod'.") |
| 86 | |
| 87 | self.__init(key, msg, digestmod) |
| 88 | |
| 89 | def __init(self, key, msg, digestmod): |
| 90 | if _hashopenssl and isinstance(digestmod, (str, _functype)): |