Skip to content

Commit c7147e8

Browse files
committed
Fixed docs to mention the new eventsourcing.cryptography.AESCipher class. Also fixed refs to eventsourcing.persistence.Cipher.
1 parent 68efe9e commit c7147e8

File tree

4 files changed

+48
-11
lines changed

4 files changed

+48
-11
lines changed

docs/topics/application.rst

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,12 +1082,12 @@ of the application "on the wire" and "at rest".
10821082
To enable application-level encryption, set the environment variable
10831083
``CIPHER_TOPIC`` to be the :ref:`topic <Topics>` of a cipher class.
10841084

1085-
The library's :class:`~eventsourcing.cipher.AESCipher` class can
1086-
be used to encrypt stored domain events.
1085+
The library's older :class:`eventsourcing.cipher.AESCipher` class can
1086+
be used to encrypt stored domain events. This class uses `Pycryptodome <https://pypi.org/project/pycryptodome/>`_.
10871087
When using the library's :class:`~eventsourcing.cipher.AESCipher`
10881088
class, set environment variable ``CIPHER_KEY`` to be a valid encryption
10891089
key. You can use the static method :func:`~eventsourcing.cipher.AESCipher.create_key`
1090-
on the :class:`~eventsourcing.cipher.AESCipher` class to generate a valid encryption key.
1090+
on the :class:`eventsourcing.cipher.AESCipher` class to generate a valid encryption key.
10911091

10921092
.. code-block:: python
10931093
@@ -1103,6 +1103,31 @@ on the :class:`~eventsourcing.cipher.AESCipher` class to generate a valid encryp
11031103
os.environ["CIPHER_KEY"] = cipher_key
11041104
11051105
1106+
Alternatively, the library's new :class:`eventsourcing.cryptography.AESCipher` class can
1107+
be used to encrypt stored domain events. This class uses the newer "standard" Python
1108+
`cryptography <https://pypi.org/project/cryptography/>`_ package. When using this
1109+
:class:`~eventsourcing.cryptography.AESCipher` class, set environment variable ``CIPHER_KEY``
1110+
to be a valid encryption key. You can use the static method :func:`~eventsourcing.cryptography.AESCipher.create_key`
1111+
on the :class:`eventsourcing.cryptography.AESCipher` class to generate a valid encryption key.
1112+
1113+
.. code-block:: python
1114+
1115+
from eventsourcing.cryptography import AESCipher
1116+
1117+
# Generate a cipher key (keep this safe).
1118+
cipher_key = AESCipher.create_key(num_bytes=32)
1119+
1120+
# Configure cipher topic.
1121+
os.environ["CIPHER_TOPIC"] = "eventsourcing.cryptography:AESCipher"
1122+
1123+
# Configure cipher key.
1124+
os.environ["CIPHER_KEY"] = cipher_key
1125+
1126+
1127+
The classes :class:`eventsourcing.cipher.AESCipher` and :class:`eventsourcing.cryptography.AESCipher` are tested
1128+
as being interoperable. You should be able to decrypt events with one that have been encrypted with the other, using
1129+
the same cipher key.
1130+
11061131
.. _Snapshotting:
11071132

11081133
Snapshotting
@@ -1254,6 +1279,13 @@ Code reference
12541279
:special-members:
12551280
:exclude-members: __weakref__, __dict__
12561281

1282+
.. automodule:: eventsourcing.cryptography
1283+
:show-inheritance:
1284+
:member-order: bysource
1285+
:members:
1286+
:special-members:
1287+
:exclude-members: __weakref__, __dict__
1288+
12571289
.. automodule:: eventsourcing.cipher
12581290
:show-inheritance:
12591291
:member-order: bysource

docs/topics/installing.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ for those unable to meet the prerequisites needed for building ``psycopg[c]``.
8585
This package now follows the recommendation that library's should depend only on the pure Python package, giving
8686
users the choice of either compiling the C optimization or using the pre-built binary or using the pure
8787
Python package. If you don't install either ``psycopg[c]`` or ``psycopg[binary]`` then you need to make sure
88-
the `libpq` is installed. The `libpq` is the client library used by psql, the PostgreSQL command line client. See
88+
the libpq is installed. The libpq is the client library used by psql, the PostgreSQL command line client. See
8989
the `Psycopg docs <https://www.psycopg.org/psycopg3/docs/basic/install.html#pure-python-installation>`_ for more
9090
information.
9191

docs/topics/persistence.rst

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -596,12 +596,12 @@ Encryption
596596
==========
597597

598598
The :class:`~eventsourcing.persistence.Mapper` class has an optional constructor argument, ``cipher``,
599-
which accepts :class:`~eventsourcing.cipher.Cipher` objects. A cipher will encrypt and decrypt the state
599+
which accepts :class:`~eventsourcing.persistence.Cipher` objects. A cipher will encrypt and decrypt the state
600600
of stored events within an event-sourced application, inhibiting disclosure of sensitive information in
601601
case of unauthorised access to an application's database files and backups, or network interception.
602602

603-
The library's :class:`~eventsourcing.cipher.AESCipher` class
604-
implements the abstract base class :class:`~eventsourcing.cipher.Cipher`.
603+
The library's :class:`eventsourcing.cipher.AESCipher` class
604+
implements the abstract base class :class:`~eventsourcing.persistence.Cipher`.
605605
It can be used to cryptographically encode and decode the state of stored
606606
events using the `AES cipher <https://pycryptodome.readthedocs.io/en/stable/src/cipher/aes.html>`_
607607
from the `PyCryptodome library <https://pycryptodome.readthedocs.io/en/stable/index.html>`_
@@ -611,7 +611,12 @@ standard for symmetric encryption. Galois/Counter Mode (GCM) is a mode of
611611
operation for symmetric block ciphers that is designed to provide both data
612612
authenticity and confidentiality, and is widely adopted for its performance.
613613

614-
A :class:`~eventsourcing.cipher.Cipher` is constructed with an
614+
Alternatively, the library's :class:`eventsourcing.cryptography.AESCipher` class
615+
also implements the abstract base class :class:`~eventsourcing.persistence.Cipher` and
616+
is functionally equivalent, but uses the `Python cryptography library <https://cryptography.io>`_,
617+
and should work as a drop-in replacement for :class:`eventsourcing.cipher.AESCipher`.
618+
619+
A :class:`~eventsourcing.persistence.Cipher` is constructed with an
615620
:class:`~eventsourcing.utils.Environment` object so that that
616621
encryption can be configured using environment variables.
617622

@@ -650,7 +655,7 @@ than the state of a stored event that is not encrypted.
650655
assert len(encrypted_stored_event.state) > len(stored_event.state)
651656
652657
If you want to use a different cipher strategy, then implement the base
653-
class :class:`~eventsourcing.cipher.Cipher`.
658+
class :class:`~eventsourcing.persistence.Cipher`.
654659

655660

656661
Compression and encryption

docs/topics/tutorial/part5.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,15 +362,15 @@ we will also configure the system to compress and encrypt the domain events.
362362
363363
import os
364364
365-
from eventsourcing.cipher import AESCipher
365+
from eventsourcing.cryptography import AESCipher
366366
367367
# Generate a cipher key (keep this safe).
368368
cipher_key = AESCipher.create_key(num_bytes=32)
369369
370370
# Cipher key.
371371
os.environ['CIPHER_KEY'] = cipher_key
372372
# Cipher topic.
373-
os.environ['CIPHER_TOPIC'] = 'eventsourcing.cipher:AESCipher'
373+
os.environ['CIPHER_TOPIC'] = 'eventsourcing.cryptography:AESCipher'
374374
# Compressor topic.
375375
os.environ['COMPRESSOR_TOPIC'] = 'eventsourcing.compressor:ZlibCompressor'
376376

0 commit comments

Comments
 (0)