diff options
author | Alex Gaynor <alex.gaynor@gmail.com> | 2016-06-03 13:04:26 -0700 |
---|---|---|
committer | Paul Kehrer <paul.l.kehrer@gmail.com> | 2016-06-03 13:04:26 -0700 |
commit | 949892938735c0cf14a6689d68779c2ce2410585 (patch) | |
tree | 17077680d9c0583458d21662904fdc48dc3f4f5b /tests/hazmat/primitives/test_rsa.py | |
parent | 6eeaf0bd76f5d40e9fbd9bc17b1b2fd08df186c4 (diff) | |
download | cryptography-949892938735c0cf14a6689d68779c2ce2410585.tar.gz cryptography-949892938735c0cf14a6689d68779c2ce2410585.tar.bz2 cryptography-949892938735c0cf14a6689d68779c2ce2410585.zip |
SSH serialization for public keys (#2957)
* SSH serialization for public keys
* name errors ahoy!
* id, ego, superego
* dsa support
* EC support
* Don't keyerror
* Documentation OpenSSH
* flake8
* fix
* bytes bytes bytes
* skip curve unsupported
* bytes!
* Move a function
* reorganize code for coverage
Diffstat (limited to 'tests/hazmat/primitives/test_rsa.py')
-rw-r--r-- | tests/hazmat/primitives/test_rsa.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/hazmat/primitives/test_rsa.py b/tests/hazmat/primitives/test_rsa.py index 6a8bb95d..320a96e5 100644 --- a/tests/hazmat/primitives/test_rsa.py +++ b/tests/hazmat/primitives/test_rsa.py @@ -2066,6 +2066,42 @@ class TestRSAPEMPublicKeySerialization(object): serialized = key.public_bytes(encoding, format) assert serialized == key_bytes + def test_public_bytes_openssh(self, backend): + key_bytes = load_vectors_from_file( + os.path.join("asymmetric", "public", "PKCS1", "rsa.pub.pem"), + lambda pemfile: pemfile.read(), mode="rb" + ) + key = serialization.load_pem_public_key(key_bytes, backend) + + ssh_bytes = key.public_bytes( + serialization.Encoding.OpenSSH, serialization.PublicFormat.OpenSSH + ) + assert ssh_bytes == ( + b"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQC7JHoJfg6yNzLMOWet8Z49a4KD" + b"0dCspMAYvo2YAMB7/wdEycocujbhJ2n/seONi+5XqTqqFkM5VBl8rmkkFPZk/7x0" + b"xmdsTPECSWnHK+HhoaNDFPR3j8jQhVo1laxiqcEhAHegi5cwtFosuJAvSKAFKEvy" + b"D43si00DQnXWrYHAEQ==" + ) + + with pytest.raises(ValueError): + key.public_bytes( + serialization.Encoding.PEM, serialization.PublicFormat.OpenSSH + ) + with pytest.raises(ValueError): + key.public_bytes( + serialization.Encoding.DER, serialization.PublicFormat.OpenSSH + ) + with pytest.raises(ValueError): + key.public_bytes( + serialization.Encoding.OpenSSH, + serialization.PublicFormat.PKCS1, + ) + with pytest.raises(ValueError): + key.public_bytes( + serialization.Encoding.OpenSSH, + serialization.PublicFormat.SubjectPublicKeyInfo, + ) + def test_public_bytes_invalid_encoding(self, backend): key = RSA_KEY_2048.private_key(backend).public_key() with pytest.raises(TypeError): |