From bf0f464ab62d2e69ebfacd80fad2de46e862fcbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Fri, 26 Feb 2016 18:40:20 +0100 Subject: Added support for padding ANSI X.923 --- docs/hazmat/primitives/padding.rst | 41 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'docs') diff --git a/docs/hazmat/primitives/padding.rst b/docs/hazmat/primitives/padding.rst index a60f5ac8..37e4252d 100644 --- a/docs/hazmat/primitives/padding.rst +++ b/docs/hazmat/primitives/padding.rst @@ -54,6 +54,47 @@ multiple of the block size. provider. +.. class:: ANSIX923(block_size) + + 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 -- cgit v1.2.3 From 93a3d53151a26ec6b14c60c0173e20b2211ec4a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Fri, 26 Feb 2016 23:34:15 +0100 Subject: Add wikipedia link to ANSI X.923 --- docs/hazmat/primitives/padding.rst | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'docs') diff --git a/docs/hazmat/primitives/padding.rst b/docs/hazmat/primitives/padding.rst index 37e4252d..475976af 100644 --- a/docs/hazmat/primitives/padding.rst +++ b/docs/hazmat/primitives/padding.rst @@ -56,10 +56,10 @@ multiple of the block size. .. class:: ANSIX923(block_size) - 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: + `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:: @@ -123,3 +123,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 -- cgit v1.2.3 From 6cfd9192b7c76dce2979e72f77fae2d653d58ebe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 15 Mar 2016 14:35:19 +0100 Subject: Add version in the doc --- docs/hazmat/primitives/padding.rst | 2 ++ 1 file changed, 2 insertions(+) (limited to 'docs') diff --git a/docs/hazmat/primitives/padding.rst b/docs/hazmat/primitives/padding.rst index 475976af..0b76327e 100644 --- a/docs/hazmat/primitives/padding.rst +++ b/docs/hazmat/primitives/padding.rst @@ -56,6 +56,8 @@ multiple of the block size. .. 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 -- cgit v1.2.3