diff options
author | Paul Kehrer <paul.l.kehrer@gmail.com> | 2015-06-27 10:12:03 -0500 |
---|---|---|
committer | Paul Kehrer <paul.l.kehrer@gmail.com> | 2015-06-27 10:12:03 -0500 |
commit | fad53a2ef0b1b20056eff529a553b749872407ce (patch) | |
tree | b4f7c5fb17650910014ca78c58b16ea1d352e79a | |
parent | 46e12ee86498fd57c297eeee63485295fcf2e39a (diff) | |
parent | 1c453c25e35ba564746e599f64a389bb77263799 (diff) | |
download | cryptography-fad53a2ef0b1b20056eff529a553b749872407ce.tar.gz cryptography-fad53a2ef0b1b20056eff529a553b749872407ce.tar.bz2 cryptography-fad53a2ef0b1b20056eff529a553b749872407ce.zip |
Merge pull request #2076 from alex/more-branch-coverage
More branch coverage improvements. By virtue of reorganization and a new test
-rw-r--r-- | src/cryptography/hazmat/backends/openssl/backend.py | 14 | ||||
-rw-r--r-- | tests/hazmat/primitives/test_concatkdf.py | 21 |
2 files changed, 27 insertions, 8 deletions
diff --git a/src/cryptography/hazmat/backends/openssl/backend.py b/src/cryptography/hazmat/backends/openssl/backend.py index e27fb6e8..af66aca1 100644 --- a/src/cryptography/hazmat/backends/openssl/backend.py +++ b/src/cryptography/hazmat/backends/openssl/backend.py @@ -1351,9 +1351,6 @@ class Backend(object): def _private_key_bytes(self, encoding, format, encryption_algorithm, evp_pkey, cdata): - if not isinstance(encoding, serialization.Encoding): - raise TypeError("encoding must be an item from the Encoding enum") - if not isinstance(format, serialization.PrivateFormat): raise TypeError( "format must be an item from the PrivateFormat enum" @@ -1416,6 +1413,8 @@ class Backend(object): elif format is serialization.PrivateFormat.PKCS8: write_bio = self._lib.i2d_PKCS8PrivateKey_bio key = evp_pkey + else: + raise TypeError("encoding must be an item from the Encoding enum") bio = self._create_mem_bio() res = write_bio( @@ -1448,11 +1447,6 @@ class Backend(object): if not isinstance(encoding, serialization.Encoding): raise TypeError("encoding must be an item from the Encoding enum") - if not isinstance(format, serialization.PublicFormat): - raise TypeError( - "format must be an item from the PublicFormat enum" - ) - if format is serialization.PublicFormat.SubjectPublicKeyInfo: if encoding is serialization.Encoding.PEM: write_bio = self._lib.PEM_write_bio_PUBKEY @@ -1469,6 +1463,10 @@ class Backend(object): write_bio = self._lib.i2d_RSAPublicKey_bio key = cdata + else: + raise TypeError( + "format must be an item from the PublicFormat enum" + ) bio = self._create_mem_bio() res = write_bio(bio, key) diff --git a/tests/hazmat/primitives/test_concatkdf.py b/tests/hazmat/primitives/test_concatkdf.py index 27e5460e..aa568c1f 100644 --- a/tests/hazmat/primitives/test_concatkdf.py +++ b/tests/hazmat/primitives/test_concatkdf.py @@ -158,6 +158,27 @@ class TestConcatKDFHMAC(object): assert ckdf.derive(prk) == okm + def test_derive_explicit_salt(self, backend): + prk = binascii.unhexlify( + b"013951627c1dea63ea2d7702dd24e963eef5faac6b4af7e4" + b"b831cde499dff1ce45f6179f741c728aa733583b02409208" + b"8f0af7fce1d045edbc5790931e8d5ca79c73" + ) + + okm = binascii.unhexlify(b"64ce901db10d558661f10b6836a122a7" + b"605323ce2f39bf27eaaac8b34cf89f2f") + + oinfo = binascii.unhexlify( + b"a1b2c3d4e55e600be5f367e0e8a465f4bf2704db00c9325c" + b"9fbd216d12b49160b2ae5157650f43415653696421e68e" + ) + + ckdf = ConcatKDFHMAC( + hashes.SHA512(), 32, b"\x00" * 128, oinfo, backend + ) + + assert ckdf.derive(prk) == okm + def test_verify(self, backend): prk = binascii.unhexlify( b"013951627c1dea63ea2d7702dd24e963eef5faac6b4af7e4" |