From faf305b3143d35d60d860c4156d020494280008b Mon Sep 17 00:00:00 2001 From: Alex Stapleton Date: Sat, 12 Jul 2014 12:27:37 +0100 Subject: Get rid of remaining pycon blocks --- docs/hazmat/backends/multibackend.rst | 19 ++++++++++++++++++- docs/hazmat/primitives/mac/cmac.rst | 4 ++-- docs/hazmat/primitives/mac/hmac.rst | 4 ++-- docs/random-numbers.rst | 2 +- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/docs/hazmat/backends/multibackend.rst b/docs/hazmat/backends/multibackend.rst index 119b13ae..0aae04a7 100644 --- a/docs/hazmat/backends/multibackend.rst +++ b/docs/hazmat/backends/multibackend.rst @@ -12,7 +12,24 @@ MultiBackend This class allows you to combine multiple backends into a single backend that offers the combined features of all of its constituents. - .. code-block:: pycon + .. testsetup:: + + from cryptography import utils + from cryptography.exceptions import UnsupportedAlgorithm, _Reasons + from cryptography.hazmat.backends.interfaces import HashBackend + from cryptography.hazmat.backends.openssl.backend import backend as backend2 + + @utils.register_interface(HashBackend) + class DummyHashBackend(object): + def hash_supported(self, algorithm): + return False + + def create_hash_ctx(self, algorithm): + raise UnsupportedAlgorithm("", _Reasons.UNSUPPORTED_HASH) + + backend1 = DummyHashBackend() + + .. doctest:: >>> from cryptography.hazmat.backends.multibackend import MultiBackend >>> from cryptography.hazmat.primitives import hashes diff --git a/docs/hazmat/primitives/mac/cmac.rst b/docs/hazmat/primitives/mac/cmac.rst index 498b8b1e..104ba8b8 100644 --- a/docs/hazmat/primitives/mac/cmac.rst +++ b/docs/hazmat/primitives/mac/cmac.rst @@ -31,7 +31,7 @@ A subset of CMAC with the AES-128 algorithm is described in :rfc:`4493`. >>> from cryptography.hazmat.primitives.ciphers import algorithms >>> c = cmac.CMAC(algorithms.AES(key), backend=default_backend()) >>> c.update(b"message to authenticate") - >>> c.finalize() + >>> c.copy().finalize() 'CT\x1d\xc8\x0e\x15\xbe4e\xdb\xb6\x84\xca\xd9Xk' If the backend doesn't support the requested ``algorithm`` an @@ -45,7 +45,7 @@ A subset of CMAC with the AES-128 algorithm is described in :rfc:`4493`. To check that a given signature is correct use the :meth:`verify` method. You will receive an exception if the signature is wrong: - .. code-block:: pycon + .. doctest:: >>> c.verify(b"an incorrect signature") Traceback (most recent call last): diff --git a/docs/hazmat/primitives/mac/hmac.rst b/docs/hazmat/primitives/mac/hmac.rst index d56927b9..da75fa9d 100644 --- a/docs/hazmat/primitives/mac/hmac.rst +++ b/docs/hazmat/primitives/mac/hmac.rst @@ -31,7 +31,7 @@ of a message. >>> from cryptography.hazmat.primitives import hashes, hmac >>> h = hmac.HMAC(key, hashes.SHA256(), backend=default_backend()) >>> h.update(b"message to hash") - >>> h.finalize() + >>> h.copy().finalize() '#F\xdaI\x8b"e\xc4\xf1\xbb\x9a\x8fc\xff\xf5\xdex.\xbc\xcd/+\x8a\x86\x1d\x84\'\xc3\xa6\x1d\xd8J' If the backend doesn't support the requested ``algorithm`` an @@ -45,7 +45,7 @@ of a message. To check that a given signature is correct use the :meth:`verify` method. You will receive an exception if the signature is wrong: - .. code-block:: pycon + .. doctest:: >>> h.verify(b"an incorrect signature") Traceback (most recent call last): diff --git a/docs/random-numbers.rst b/docs/random-numbers.rst index 12969d1c..410f3757 100644 --- a/docs/random-numbers.rst +++ b/docs/random-numbers.rst @@ -13,7 +13,7 @@ provided random number generator`_, which is available as ``os.urandom()``. For example, if you need 16 bytes of random data for an initialization vector, you can obtain them with: -.. code-block:: pycon +.. doctest:: >>> import os >>> os.urandom(16) -- cgit v1.2.3