diff options
author | Paul Kehrer <paul.l.kehrer@gmail.com> | 2016-03-16 12:58:27 -0400 |
---|---|---|
committer | Paul Kehrer <paul.l.kehrer@gmail.com> | 2016-03-16 12:58:27 -0400 |
commit | f790b4289ed026cab590fd98aca4d6777f62d719 (patch) | |
tree | a5a4a589545c9332fdd9f00c60781f57bb00fc8e /docs/hazmat/primitives | |
parent | 1c6e624631cb339b9e5e437083bca971530bba9f (diff) | |
parent | 70b3a7dd5ce2a953da1ce19534bcedbb53a8c2bf (diff) | |
download | cryptography-f790b4289ed026cab590fd98aca4d6777f62d719.tar.gz cryptography-f790b4289ed026cab590fd98aca4d6777f62d719.tar.bz2 cryptography-f790b4289ed026cab590fd98aca4d6777f62d719.zip |
Merge pull request #2736 from cedk/ANSI_X.923
Added support for padding ANSI X.923
Diffstat (limited to 'docs/hazmat/primitives')
-rw-r--r-- | docs/hazmat/primitives/padding.rst | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/docs/hazmat/primitives/padding.rst b/docs/hazmat/primitives/padding.rst index a60f5ac8..0b76327e 100644 --- a/docs/hazmat/primitives/padding.rst +++ b/docs/hazmat/primitives/padding.rst @@ -54,6 +54,49 @@ multiple of the block size. provider. +.. class:: ANSIX923(block_size) + + .. versionadded:: 1.3 + + `ANSI X.923`_ padding works by appending ``N-1`` bytes with the value of + ``0`` and a last byte with the value of ``chr(N)``, where ``N`` is the + number of bytes required to make the final block of data the same size as + the block size. A simple example of padding is: + + .. doctest:: + + >>> padder = padding.ANSIX923(128).padder() + >>> padded_data = padder.update(b"11111111111111112222222222") + >>> padded_data + '1111111111111111' + >>> padded_data += padder.finalize() + >>> padded_data + '11111111111111112222222222\x00\x00\x00\x00\x00\x06' + >>> unpadder = padding.ANSIX923(128).unpadder() + >>> data = unpadder.update(padded_data) + >>> data + '1111111111111111' + >>> data + unpadder.finalize() + '11111111111111112222222222' + + :param block_size: The size of the block in bits that the data is being + padded to. + :raises ValueError: Raised if block size is not a multiple of 8 or is not + between 0 and 256. + + .. method:: padder() + + :returns: A padding + :class:`~cryptography.hazmat.primitives.padding.PaddingContext` + provider + + .. method:: unpadder() + + :returns: An unpadding + :class:`~cryptography.hazmat.primitives.padding.PaddingContext` + provider. + + .. class:: PaddingContext When calling ``padder()`` or ``unpadder()`` the result will conform to the @@ -82,3 +125,5 @@ multiple of the block size. :raises TypeError: Raised if data is not bytes. :raises ValueError: When trying to remove padding from incorrectly padded data. + +.. _`ANSI X.923`: https://en.wikipedia.org/wiki/Padding_%28cryptography%29#ANSI_X.923 |