@@ -2342,14 +2342,6 @@ def test_serialize_ssh_private_key_errors(self, backend):
23422342
23432343 private_key = ec .generate_private_key (ec .SECP256R1 (), backend )
23442344
2345- # too long password
2346- with pytest .raises (ValueError ):
2347- private_key .private_bytes (
2348- Encoding .PEM ,
2349- PrivateFormat .OpenSSH ,
2350- BestAvailableEncryption (b"p" * 73 ),
2351- )
2352-
23532345 # unknown encryption class
23542346 with pytest .raises (ValueError ):
23552347 private_key .private_bytes (
@@ -2358,6 +2350,41 @@ def test_serialize_ssh_private_key_errors(self, backend):
23582350 DummyKeySerializationEncryption (),
23592351 )
23602352
2353+ @pytest .mark .supported (
2354+ only_if = lambda backend : ssh ._bcrypt_supported ,
2355+ skip_message = "Requires that bcrypt exists" ,
2356+ )
2357+ @pytest .mark .parametrize (
2358+ "password" ,
2359+ (
2360+ b"1234" ,
2361+ b"p@ssw0rd" ,
2362+ b"x" * 100 ,
2363+ ),
2364+ )
2365+ def test_serialize_ssh_private_key_with_password (self , password , backend ):
2366+ original_key = ec .generate_private_key (ec .SECP256R1 (), backend )
2367+ encoded_key_data = ssh .serialize_ssh_private_key (
2368+ private_key = original_key ,
2369+ password = password ,
2370+ )
2371+
2372+ decoded_key = load_ssh_private_key (
2373+ data = encoded_key_data ,
2374+ password = password ,
2375+ backend = backend ,
2376+ )
2377+
2378+ original_public_key = original_key .public_key ().public_bytes (
2379+ Encoding .OpenSSH , PublicFormat .OpenSSH
2380+ )
2381+
2382+ decoded_public_key = decoded_key .public_key ().public_bytes (
2383+ Encoding .OpenSSH , PublicFormat .OpenSSH
2384+ )
2385+
2386+ assert original_public_key == decoded_public_key
2387+
23612388 @pytest .mark .supported (
23622389 only_if = lambda backend : backend .dsa_supported (),
23632390 skip_message = "Does not support DSA." ,
0 commit comments