aboutsummaryrefslogtreecommitdiffstats
path: root/cryptography
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2014-03-15 15:15:30 -0700
committerAlex Gaynor <alex.gaynor@gmail.com>2014-03-15 15:15:30 -0700
commit106cc54b4344cc97af54eccb4d873434efe4203a (patch)
treef1253ea7cbd411c5f97e25558defc5de6eb95cd1 /cryptography
parent7b9d92416ece98fdb12b2c220b81d5180bc87945 (diff)
parenta0fdedef7328615fad7f174d52d6dc36346c7e2f (diff)
downloadcryptography-106cc54b4344cc97af54eccb4d873434efe4203a.tar.gz
cryptography-106cc54b4344cc97af54eccb4d873434efe4203a.tar.bz2
cryptography-106cc54b4344cc97af54eccb4d873434efe4203a.zip
Merge pull request #775 from reaperhulk/rsa-mgf1-class
add MGF1 class, docs, tests
Diffstat (limited to 'cryptography')
-rw-r--r--cryptography/hazmat/primitives/asymmetric/padding.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/cryptography/hazmat/primitives/asymmetric/padding.py b/cryptography/hazmat/primitives/asymmetric/padding.py
index 6bafe314..46e00b8e 100644
--- a/cryptography/hazmat/primitives/asymmetric/padding.py
+++ b/cryptography/hazmat/primitives/asymmetric/padding.py
@@ -13,6 +13,8 @@
from __future__ import absolute_import, division, print_function
+import six
+
from cryptography import utils
from cryptography.hazmat.primitives import interfaces
@@ -20,3 +22,22 @@ from cryptography.hazmat.primitives import interfaces
@utils.register_interface(interfaces.AsymmetricPadding)
class PKCS1v15(object):
name = "EMSA-PKCS1-v1_5"
+
+
+class MGF1(object):
+ MAX_LENGTH = object()
+
+ def __init__(self, algorithm, salt_length):
+ if not isinstance(algorithm, interfaces.HashAlgorithm):
+ raise TypeError("Expected instance of interfaces.HashAlgorithm.")
+
+ self._algorithm = algorithm
+
+ if (not isinstance(salt_length, six.integer_types) and
+ salt_length is not self.MAX_LENGTH):
+ raise TypeError("salt_length must be an integer")
+
+ if salt_length is not self.MAX_LENGTH and salt_length < 0:
+ raise ValueError("salt_length must be zero or greater")
+
+ self._salt_length = salt_length