alex/cryptography — pull request #42 by dstufft (2013-08-11 21:52:34+00:00)
Title: Use the Sphinx doctest builder

Currently we are testing if our documentation builds. However this doesn't prevent incorrect examples inside of our documentation (such as was a problem in https://github.com/alex/cryptography/pull/40). This adds the ability to use doc tests inside of Sphinx in order to also test our examples. Currently there are zero documentation tests however an example one could be added to https://github.com/alex/cryptography/pull/28 with this diff:

```diff
diff --git a/docs/primitives/symmetric-encryption.rst b/docs/primitives/symmetric-encryption.rst
index 9986d89..52eb0c3 100644
--- a/docs/primitives/symmetric-encryption.rst
+++ b/docs/primitives/symmetric-encryption.rst
@@ -1,6 +1,13 @@
Symmetric Encryption
====================

+.. testsetup::
+
+ import binascii
+ key = binascii.unhexlify(b"0" * 32)
+ iv = binascii.unhexlify(b"0" * 32)
+
+
Symmetric encryption is a way to encrypt (hide the plaintext value) material
where the encrypter and decrypter both use the same key.

@@ -10,13 +17,12 @@ where the encrypter and decrypter both use the same key.
They combine an underlying algorithm (such as AES), with a mode (such as
CBC, CTR, or GCM). A simple example of encrypting content with AES is:

- .. code-block:: pycon
+ .. doctest::

>>> from cryptography.primitives.block import BlockCipher, ciphers, modes
>>> cipher = BlockCipher(ciphers.AES(key), modes.CBC(iv))
>>> cipher.encrypt(b"a secret message") + cipher.finalize()
- # The ciphertext
- [...]
+ '...'

:param cipher: One of the ciphers described below.
:param mode: One of the modes described below.
```