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='')
| 36 | ) |
| 37 | |
| 38 | def __init__(self, key, msg=None, digestmod=''): |
| 39 | """Create a new HMAC object. |
| 40 | |
| 41 | key: bytes or buffer, key for the keyed hash object. |
| 42 | msg: bytes or buffer, Initial input for the hash or None. |
| 43 | digestmod: A hash name suitable for hashlib.new(). *OR* |
| 44 | A hashlib constructor returning a new hash object. *OR* |
| 45 | A module supporting PEP 247. |
| 46 | |
| 47 | Required as of 3.8, despite its position after the optional |
| 48 | msg argument. Passing it as a keyword argument is |
| 49 | recommended, though not required for legacy API reasons. |
| 50 | """ |
| 51 | |
| 52 | if not isinstance(key, (bytes, bytearray)): |
| 53 | raise TypeError("key: expected bytes or bytearray, but got %r" % type(key).__name__) |
| 54 | |
| 55 | if not digestmod: |
| 56 | raise TypeError("Missing required argument 'digestmod'.") |
| 57 | |
| 58 | if _hashopenssl and isinstance(digestmod, (str, _functype)): |
| 59 | try: |
| 60 | self._init_hmac(key, msg, digestmod) |
| 61 | except _hashopenssl.UnsupportedDigestmodError: |
| 62 | self._init_old(key, msg, digestmod) |
| 63 | else: |
| 64 | self._init_old(key, msg, digestmod) |
| 65 | |
| 66 | def _init_hmac(self, key, msg, digestmod): |
| 67 | self._hmac = _hashopenssl.hmac_new(key, msg, digestmod=digestmod) |
nothing calls this directly
no test coverage detected