aboutsummaryrefslogtreecommitdiffstats
path: root/docs/hazmat/primitives/hmac.rst
diff options
context:
space:
mode:
Diffstat (limited to 'docs/hazmat/primitives/hmac.rst')
-rw-r--r--docs/hazmat/primitives/hmac.rst29
1 files changed, 25 insertions, 4 deletions
diff --git a/docs/hazmat/primitives/hmac.rst b/docs/hazmat/primitives/hmac.rst
index bd1a4934..db5e98d3 100644
--- a/docs/hazmat/primitives/hmac.rst
+++ b/docs/hazmat/primitives/hmac.rst
@@ -15,7 +15,7 @@ message authentication codes using a cryptographic hash function coupled with a
secret key. You can use an HMAC to verify integrity as well as authenticate a
message.
-.. class:: HMAC(key, algorithm)
+.. class:: HMAC(key, algorithm, backend)
HMAC objects take a ``key`` and a provider of
:class:`~cryptography.hazmat.primitives.interfaces.HashAlgorithm`.
@@ -27,24 +27,45 @@ message.
.. doctest::
+ >>> from cryptography.hazmat.bindings import default_backend
>>> from cryptography.hazmat.primitives import hashes, hmac
- >>> h = hmac.HMAC(key, hashes.SHA256())
+ >>> h = hmac.HMAC(key, hashes.SHA256(), backend=default_backend())
>>> h.update(b"message to hash")
>>> h.finalize()
'#F\xdaI\x8b"e\xc4\xf1\xbb\x9a\x8fc\xff\xf5\xdex.\xbc\xcd/+\x8a\x86\x1d\x84\'\xc3\xa6\x1d\xd8J'
+
+ :param key: Secret key as ``bytes``.
+ :param algorithm: A
+ :class:`~cryptography.hazmat.primitives.interfaces.HashAlgorithm`
+ provider such as those described in
+ :ref:`Cryptographic Hashes <cryptographic-hash-algorithms>`.
+ :param backend: A
+ :class:`~cryptography.hazmat.bindings.interfaces.HMACBackend`
+ provider.
+
.. method:: update(msg)
:param bytes msg: The bytes to hash and authenticate.
+ :raises cryptography.exceptions.AlreadyFinalized: See :meth:`finalize`
.. method:: copy()
- :return: a new instance of this object with a copied internal state.
+ Copy this :class:`HMAC` instance, usually so that we may call
+ :meth:`finalize` and get an intermediate digest value while we continue
+ to call :meth:`update` on the original.
+
+ :return: A new instance of :class:`HMAC` which can be updated
+ and finalized independently of the original instance.
+ :raises cryptography.exceptions.AlreadyFinalized: See :meth:`finalize`
.. method:: finalize()
Finalize the current context and return the message digest as bytes.
- Once ``finalize`` is called this object can no longer be used.
+ Once ``finalize`` is called this object can no longer be used and
+ :meth:`update`, :meth:`copy`, and :meth:`finalize` will raise
+ :class:`~cryptography.exceptions.AlreadyFinalized`.
:return bytes: The message digest as bytes.
+ :raises cryptography.exceptions.AlreadyFinalized: