diff options
author | Colleen Murphy <cmurphy@users.noreply.github.com> | 2016-06-04 09:09:08 -0700 |
---|---|---|
committer | Paul Kehrer <paul.l.kehrer@gmail.com> | 2016-06-04 09:09:08 -0700 |
commit | 34d5c39a9c1efa6c2f2c9f473890ebe44816e85a (patch) | |
tree | 8009a882571352fbd33ad05ff82c841eb4a0ff2e /src | |
parent | 4f125c122499e21050e46f20a18bbc4848b0f43b (diff) | |
download | cryptography-34d5c39a9c1efa6c2f2c9f473890ebe44816e85a.tar.gz cryptography-34d5c39a9c1efa6c2f2c9f473890ebe44816e85a.tar.bz2 cryptography-34d5c39a9c1efa6c2f2c9f473890ebe44816e85a.zip |
Add convenience methods to sign and verify w/ RSA (#2945)
This patch adds wrapper methods to allow the user to sign and verify a
single message block without having to go through the multi-step
process of creating a signer or verifier, updating it with the one
message, and finalizing the result. This will make signing and
verifying data more user-friendly when only using small messages.
Partial bug #1529
Diffstat (limited to 'src')
-rw-r--r-- | src/cryptography/hazmat/backends/openssl/rsa.py | 11 | ||||
-rw-r--r-- | src/cryptography/hazmat/primitives/asymmetric/rsa.py | 12 |
2 files changed, 23 insertions, 0 deletions
diff --git a/src/cryptography/hazmat/backends/openssl/rsa.py b/src/cryptography/hazmat/backends/openssl/rsa.py index fa23bf89..10c51fee 100644 --- a/src/cryptography/hazmat/backends/openssl/rsa.py +++ b/src/cryptography/hazmat/backends/openssl/rsa.py @@ -611,6 +611,12 @@ class _RSAPrivateKey(object): self._rsa_cdata ) + def sign(self, data, padding, algorithm): + signer = self.signer(padding, algorithm) + signer.update(data) + signature = signer.finalize() + return signature + @utils.register_interface(RSAPublicKeyWithSerialization) class _RSAPublicKey(object): @@ -661,3 +667,8 @@ class _RSAPublicKey(object): self._evp_pkey, self._rsa_cdata ) + + def verify(self, signature, data, padding, algorithm): + verifier = self.verifier(signature, padding, algorithm) + verifier.update(data) + verifier.verify() diff --git a/src/cryptography/hazmat/primitives/asymmetric/rsa.py b/src/cryptography/hazmat/primitives/asymmetric/rsa.py index 41b0089e..2cb89515 100644 --- a/src/cryptography/hazmat/primitives/asymmetric/rsa.py +++ b/src/cryptography/hazmat/primitives/asymmetric/rsa.py @@ -40,6 +40,12 @@ class RSAPrivateKey(object): The RSAPublicKey associated with this private key. """ + @abc.abstractmethod + def sign(self, data, padding, algorithm): + """ + Signs the data. + """ + @six.add_metaclass(abc.ABCMeta) class RSAPrivateKeyWithSerialization(RSAPrivateKey): @@ -88,6 +94,12 @@ class RSAPublicKey(object): Returns the key serialized as bytes. """ + @abc.abstractmethod + def verify(self, signature, data, padding, algorithm): + """ + Verifies the signature of the data. + """ + RSAPublicKeyWithSerialization = RSAPublicKey |