<s> from __future__ import absolute_import , division , print_function <EOL> import itertools <EOL> import os <EOL> import pytest <EOL> from cryptography . exceptions import AlreadyFinalized , InvalidSignature <EOL> from cryptography . hazmat . backends . interfaces import ( <EOL> DSABackend , PEMSerializationBackend <EOL> ) <EOL> from cryptography . hazmat . primitives import hashes , serialization <EOL> from cryptography . hazmat . primitives . asymmetric import dsa <EOL> from cryptography . hazmat . primitives . asymmetric . utils import ( <EOL> encode_dss_signature <EOL> ) <EOL> from cryptography . utils import bit_length <EOL> from . fixtures_dsa import ( <EOL> DSA_KEY_1024 , DSA_KEY_2048 , DSA_KEY_3072 <EOL> ) <EOL> from ... doubles import DummyHashAlgorithm , DummyKeySerializationEncryption <EOL> from ... utils import ( <EOL> load_fips_dsa_key_pair_vectors , load_fips_dsa_sig_vectors , <EOL> load_vectors_from_file , <EOL> ) <EOL> def _skip_if_dsa_not_supported ( backend , algorithm , p , q , g ) : <EOL> if ( <EOL> not backend . dsa_parameters_supported ( p , q , g ) or <EOL> not backend . dsa_hash_supported ( algorithm ) <EOL> ) : <EOL> pytest . skip ( <EOL> "<STR_LIT>" . format ( backend ) <EOL> ) <EOL> @ pytest . mark . requires_backend_interface ( interface = DSABackend ) <EOL> def test_skip_if_dsa_not_supported ( backend ) : <EOL> with pytest . raises ( pytest . skip . Exception ) : <EOL> _skip_if_dsa_not_supported ( backend , DummyHashAlgorithm ( ) , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> @ pytest . mark . requires_backend_interface ( interface = DSABackend ) <EOL> class TestDSA ( object ) : <EOL> def test_generate_dsa_parameters ( self , backend ) : <EOL> parameters = dsa . generate_parameters ( <NUM_LIT> , backend ) <EOL> assert isinstance ( parameters , dsa . DSAParameters ) <EOL> def test_generate_invalid_dsa_parameters ( self , backend ) : <EOL> with pytest . raises ( ValueError ) : <EOL> dsa . generate_parameters ( <NUM_LIT:1> , backend ) <EOL> @ pytest . mark . parametrize ( <EOL> "<STR_LIT>" , <EOL> load_vectors_from_file ( <EOL> os . path . join ( <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> load_fips_dsa_key_pair_vectors <EOL> ) <EOL> ) <EOL> def test_generate_dsa_keys ( self , vector , backend ) : <EOL> parameters = dsa . DSAParameterNumbers ( <EOL> p = vector [ '<STR_LIT:p>' ] , <EOL> q = vector [ '<STR_LIT:q>' ] , <EOL> g = vector [ '<STR_LIT:g>' ] <EOL> ) . parameters ( backend ) <EOL> skey = parameters . generate_private_key ( ) <EOL> numbers = skey . private_numbers ( ) <EOL> skey_parameters = numbers . public_numbers . parameter_numbers <EOL> pkey = skey . public_key ( ) <EOL> parameters = pkey . parameters ( ) <EOL> parameter_numbers = parameters . parameter_numbers ( ) <EOL> assert parameter_numbers . p == skey_parameters . p <EOL> assert parameter_numbers . q == skey_parameters . q <EOL> assert parameter_numbers . g == skey_parameters . g <EOL> assert skey_parameters . p == vector [ '<STR_LIT:p>' ] <EOL> assert skey_parameters . q == vector [ '<STR_LIT:q>' ] <EOL> assert skey_parameters . g == vector [ '<STR_LIT:g>' ] <EOL> assert skey . key_size == bit_length ( vector [ '<STR_LIT:p>' ] ) <EOL> assert pkey . key_size == skey . key_size <EOL> public_numbers = pkey . public_numbers ( ) <EOL> assert numbers . public_numbers . y == public_numbers . y <EOL> assert numbers . public_numbers . y == pow ( <EOL> skey_parameters . g , numbers . x , skey_parameters . p <EOL> ) <EOL> def test_generate_dsa_private_key_and_parameters ( self , backend ) : <EOL> skey = dsa . generate_private_key ( <NUM_LIT> , backend ) <EOL> assert skey <EOL> numbers = skey . private_numbers ( ) <EOL> skey_parameters = numbers . public_numbers . parameter_numbers <EOL> assert numbers . public_numbers . y == pow ( <EOL> skey_parameters . g , numbers . x , skey_parameters . p <EOL> ) <EOL> def test_invalid_parameters_values ( self , backend ) : <EOL> with pytest . raises ( ValueError ) : <EOL> dsa . DSAParameterNumbers ( <EOL> p = <NUM_LIT:2> ** <NUM_LIT:1000> , <EOL> q = DSA_KEY_1024 . public_numbers . parameter_numbers . q , <EOL> g = DSA_KEY_1024 . public_numbers . parameter_numbers . g , <EOL> ) . parameters ( backend ) <EOL> with pytest . raises ( ValueError ) : <EOL> dsa . DSAParameterNumbers ( <EOL> p = <NUM_LIT:2> ** <NUM_LIT> , <EOL> q = DSA_KEY_2048 . public_numbers . parameter_numbers . q , <EOL> g = DSA_KEY_2048 . public_numbers . parameter_numbers . g , <EOL> ) . parameters ( backend ) <EOL> with pytest . raises ( ValueError ) : <EOL> dsa . DSAParameterNumbers ( <EOL> p = <NUM_LIT:2> ** <NUM_LIT> , <EOL> q = DSA_KEY_3072 . public_numbers . parameter_numbers . q , <EOL> g = DSA_KEY_3072 . public_numbers . parameter_numbers . g , <EOL> ) . parameters ( backend ) <EOL> with pytest . raises ( ValueError ) : <EOL> dsa . DSAParameterNumbers ( <EOL> p = <NUM_LIT:2> ** <NUM_LIT> , <EOL> q = DSA_KEY_3072 . public_numbers . parameter_numbers . q , <EOL> g = DSA_KEY_3072 . public_numbers . parameter_numbers . g , <EOL> ) . parameters ( backend ) <EOL> with pytest . raises ( ValueError ) : <EOL> dsa . DSAParameterNumbers ( <EOL> p = DSA_KEY_1024 . public_numbers . parameter_numbers . p , <EOL> q = <NUM_LIT:2> ** <NUM_LIT> , <EOL> g = DSA_KEY_1024 . public_numbers . parameter_numbers . g , <EOL> ) . parameters ( backend ) <EOL> with pytest . raises ( ValueError ) : <EOL> dsa . DSAParameterNumbers ( <EOL> p = DSA_KEY_2048 . public_numbers . parameter_numbers . p , <EOL> q = <NUM_LIT:2> ** <NUM_LIT> , <EOL> g = DSA_KEY_2048 . public_numbers . parameter_numbers . g <EOL> ) . parameters ( backend ) <EOL> with pytest . raises ( ValueError ) : <EOL> dsa . DSAParameterNumbers ( <EOL> p = DSA_KEY_3072 . public_numbers . parameter_numbers . p , <EOL> q = <NUM_LIT:2> ** <NUM_LIT> , <EOL> g = DSA_KEY_3072 . public_numbers . parameter_numbers . g , <EOL> ) . parameters ( backend ) <EOL> with pytest . raises ( ValueError ) : <EOL> dsa . DSAParameterNumbers ( <EOL> p = DSA_KEY_1024 . public_numbers . parameter_numbers . p , <EOL> q = DSA_KEY_1024 . public_numbers . parameter_numbers . q , <EOL> g = <NUM_LIT:0> <EOL> ) . parameters ( backend ) <EOL> with pytest . raises ( ValueError ) : <EOL> dsa . DSAParameterNumbers ( <EOL> p = DSA_KEY_1024 . public_numbers . parameter_numbers . p , <EOL> q = DSA_KEY_1024 . public_numbers . parameter_numbers . q , <EOL> g = <NUM_LIT:1> <EOL> ) . parameters ( backend ) <EOL> with pytest . raises ( ValueError ) : <EOL> dsa . DSAParameterNumbers ( <EOL> p = DSA_KEY_1024 . public_numbers . parameter_numbers . p , <EOL> q = DSA_KEY_1024 . public_numbers . parameter_numbers . q , <EOL> g = <NUM_LIT:2> ** <NUM_LIT> <EOL> ) . parameters ( backend ) <EOL> def test_invalid_dsa_private_key_arguments ( self , backend ) : <EOL> with pytest . raises ( ValueError ) : <EOL> dsa . DSAPrivateNumbers ( <EOL> public_numbers = dsa . DSAPublicNumbers ( <EOL> parameter_numbers = dsa . DSAParameterNumbers ( <EOL> p = <NUM_LIT:2> ** <NUM_LIT:1000> , <EOL> q = DSA_KEY_1024 . public_numbers . parameter_numbers . q , <EOL> g = DSA_KEY_1024 . public_numbers . parameter_numbers . g , <EOL> ) , <EOL> y = DSA_KEY_1024 . public_numbers . y <EOL> ) , <EOL> x = DSA_KEY_1024 . x <EOL> ) . private_key ( backend ) <EOL> with pytest . raises ( ValueError ) : <EOL> dsa . DSAPrivateNumbers ( <EOL> public_numbers = dsa . DSAPublicNumbers ( <EOL> parameter_numbers = dsa . DSAParameterNumbers ( <EOL> p = <NUM_LIT:2> ** <NUM_LIT> , <EOL> q = DSA_KEY_2048 . public_numbers . parameter_numbers . q , <EOL> g = DSA_KEY_2048 . public_numbers . parameter_numbers . g , <EOL> ) , <EOL> y = DSA_KEY_2048 . public_numbers . y <EOL> ) , <EOL> x = DSA_KEY_2048 . x , <EOL> ) . private_key ( backend ) <EOL> with pytest . raises ( ValueError ) : <EOL> dsa . DSAPrivateNumbers ( <EOL> public_numbers = dsa . DSAPublicNumbers ( <EOL> parameter_numbers = dsa . DSAParameterNumbers ( <EOL> p = <NUM_LIT:2> ** <NUM_LIT> , <EOL> q = DSA_KEY_3072 . public_numbers . parameter_numbers . q , <EOL> g = DSA_KEY_3072 . public_numbers . parameter_numbers . g , <EOL> ) , <EOL> y = DSA_KEY_3072 . public_numbers . y <EOL> ) , <EOL> x = DSA_KEY_3072 . x , <EOL> ) . private_key ( backend ) <EOL> with pytest . raises ( ValueError ) : <EOL> dsa . DSAPrivateNumbers ( <EOL> public_numbers = dsa . DSAPublicNumbers ( <EOL> parameter_numbers = dsa . DSAParameterNumbers ( <EOL> p = <NUM_LIT:2> ** <NUM_LIT> , <EOL> q = DSA_KEY_3072 . public_numbers . parameter_numbers . q , <EOL> g = DSA_KEY_3072 . public_numbers . parameter_numbers . g , <EOL> ) , <EOL> y = DSA_KEY_3072 . public_numbers . y <EOL> ) , <EOL> x = DSA_KEY_3072 . x , <EOL> ) . private_key ( backend ) <EOL> with pytest . raises ( ValueError ) : <EOL> dsa . DSAPrivateNumbers ( <EOL> public_numbers = dsa . DSAPublicNumbers ( <EOL> parameter_numbers = dsa . DSAParameterNumbers ( <EOL> p = DSA_KEY_1024 . public_numbers . parameter_numbers . p , <EOL> q = <NUM_LIT:2> ** <NUM_LIT> , <EOL> g = DSA_KEY_1024 . public_numbers . parameter_numbers . g , <EOL> ) , <EOL> y = DSA_KEY_1024 . public_numbers . y <EOL> ) , <EOL> x = DSA_KEY_1024 . x , <EOL> ) . private_key ( backend ) <EOL> with pytest . raises ( ValueError ) : <EOL> dsa . DSAPrivateNumbers ( <EOL> public_numbers = dsa . DSAPublicNumbers ( <EOL> parameter_numbers = dsa . DSAParameterNumbers ( <EOL> p = DSA_KEY_2048 . public_numbers . parameter_numbers . p , <EOL> q = <NUM_LIT:2> ** <NUM_LIT> , <EOL> g = DSA_KEY_2048 . public_numbers . parameter_numbers . g , <EOL> ) , <EOL> y = DSA_KEY_2048 . public_numbers . y <EOL> ) , <EOL> x = DSA_KEY_2048 . x , <EOL> ) . private_key ( backend ) <EOL> with pytest . raises ( ValueError ) : <EOL> dsa . DSAPrivateNumbers ( <EOL> public_numbers = dsa . DSAPublicNumbers ( <EOL> parameter_numbers = dsa . DSAParameterNumbers ( <EOL> p = DSA_KEY_3072 . public_numbers . parameter_numbers . p , <EOL> q = <NUM_LIT:2> ** <NUM_LIT> , <EOL> g = DSA_KEY_3072 . public_numbers . parameter_numbers . g , <EOL> ) , <EOL> y = DSA_KEY_3072 . public_numbers . y <EOL> ) , <EOL> x = DSA_KEY_3072 . x , <EOL> ) . private_key ( backend ) <EOL> with pytest . raises ( ValueError ) : <EOL> dsa . DSAPrivateNumbers ( <EOL> public_numbers = dsa . DSAPublicNumbers ( <EOL> parameter_numbers = dsa . DSAParameterNumbers ( <EOL> p = DSA_KEY_1024 . public_numbers . parameter_numbers . p , <EOL> q = DSA_KEY_1024 . public_numbers . parameter_numbers . q , <EOL> g = <NUM_LIT:0> , <EOL> ) , <EOL> y = DSA_KEY_1024 . public_numbers . y <EOL> ) , <EOL> x = DSA_KEY_1024 . x , <EOL> ) . private_key ( backend ) <EOL> with pytest . raises ( ValueError ) : <EOL> dsa . DSAPrivateNumbers ( <EOL> public_numbers = dsa . DSAPublicNumbers ( <EOL> parameter_numbers = dsa . DSAParameterNumbers ( <EOL> p = DSA_KEY_1024 . public_numbers . parameter_numbers . p , <EOL> q = DSA_KEY_1024 . public_numbers . parameter_numbers . q , <EOL> g = <NUM_LIT:1> , <EOL> ) , <EOL> y = DSA_KEY_1024 . public_numbers . y <EOL> ) , <EOL> x = DSA_KEY_1024 . x , <EOL> ) . private_key ( backend ) <EOL> with pytest . raises ( ValueError ) : <EOL> dsa . DSAPrivateNumbers ( <EOL> public_numbers = dsa . DSAPublicNumbers ( <EOL> parameter_numbers = dsa . DSAParameterNumbers ( <EOL> p = DSA_KEY_1024 . public_numbers . parameter_numbers . p , <EOL> q = DSA_KEY_1024 . public_numbers . parameter_numbers . q , <EOL> g = <NUM_LIT:2> ** <NUM_LIT> , <EOL> ) , <EOL> y = DSA_KEY_1024 . public_numbers . y <EOL> ) , <EOL> x = DSA_KEY_1024 . x , <EOL> ) . private_key ( backend ) <EOL> with pytest . raises ( ValueError ) : <EOL> dsa . DSAPrivateNumbers ( <EOL> public_numbers = dsa . DSAPublicNumbers ( <EOL> parameter_numbers = dsa . DSAParameterNumbers ( <EOL> p = DSA_KEY_1024 . public_numbers . parameter_numbers . p , <EOL> q = DSA_KEY_1024 . public_numbers . parameter_numbers . q , <EOL> g = DSA_KEY_1024 . public_numbers . parameter_numbers . g , <EOL> ) , <EOL> y = DSA_KEY_1024 . public_numbers . y <EOL> ) , <EOL> x = <NUM_LIT:0> , <EOL> ) . private_key ( backend ) <EOL> with pytest . raises ( ValueError ) : <EOL> dsa . DSAPrivateNumbers ( <EOL> public_numbers = dsa . DSAPublicNumbers ( <EOL> parameter_numbers = dsa . DSAParameterNumbers ( <EOL> p = DSA_KEY_1024 . public_numbers . parameter_numbers . p , <EOL> q = DSA_KEY_1024 . public_numbers . parameter_numbers . q , <EOL> g = DSA_KEY_1024 . public_numbers . parameter_numbers . g , <EOL> ) , <EOL> y = DSA_KEY_1024 . public_numbers . y <EOL> ) , <EOL> x = - <NUM_LIT:2> , <EOL> ) . private_key ( backend ) <EOL> with pytest . raises ( ValueError ) : <EOL> dsa . DSAPrivateNumbers ( <EOL> public_numbers = dsa . DSAPublicNumbers ( <EOL> parameter_numbers = dsa . DSAParameterNumbers ( <EOL> p = DSA_KEY_1024 . public_numbers . parameter_numbers . p , <EOL> q = DSA_KEY_1024 . public_numbers . parameter_numbers . q , <EOL> g = DSA_KEY_1024 . public_numbers . parameter_numbers . g , <EOL> ) , <EOL> y = DSA_KEY_1024 . public_numbers . y <EOL> ) , <EOL> x = <NUM_LIT:2> ** <NUM_LIT> , <EOL> ) . private_key ( backend ) <EOL> with pytest . raises ( ValueError ) : <EOL> dsa . DSAPrivateNumbers ( <EOL> public_numbers = dsa . DSAPublicNumbers ( <EOL> parameter_numbers = dsa . DSAParameterNumbers ( <EOL> p = DSA_KEY_1024 . public_numbers . parameter_numbers . p , <EOL> q = DSA_KEY_1024 . public_numbers . parameter_numbers . q , <EOL> g = DSA_KEY_1024 . public_numbers . parameter_numbers . g , <EOL> ) , <EOL> y = DSA_KEY_1024 . public_numbers . y <EOL> ) , <EOL> x = <NUM_LIT:2> ** <NUM_LIT:200> , <EOL> ) . private_key ( backend ) <EOL> with pytest . raises ( ValueError ) : <EOL> dsa . DSAPrivateNumbers ( <EOL> public_numbers = dsa . DSAPublicNumbers ( <EOL> parameter_numbers = dsa . DSAParameterNumbers ( <EOL> p = DSA_KEY_1024 . public_numbers . parameter_numbers . p , <EOL> q = DSA_KEY_1024 . public_numbers . parameter_numbers . q , <EOL> g = DSA_KEY_1024 . public_numbers . parameter_numbers . g , <EOL> ) , <EOL> y = <NUM_LIT:2> ** <NUM_LIT:100> <EOL> ) , <EOL> x = DSA_KEY_1024 . x , <EOL> ) . private_key ( backend ) <EOL> with pytest . raises ( TypeError ) : <EOL> dsa . DSAPrivateNumbers ( <EOL> public_numbers = dsa . DSAPublicNumbers ( <EOL> parameter_numbers = dsa . DSAParameterNumbers ( <EOL> p = DSA_KEY_1024 . public_numbers . parameter_numbers . p , <EOL> q = DSA_KEY_1024 . public_numbers . parameter_numbers . q , <EOL> g = DSA_KEY_1024 . public_numbers . parameter_numbers . g , <EOL> ) , <EOL> y = None <EOL> ) , <EOL> x = DSA_KEY_1024 . x , <EOL> ) . private_key ( backend ) <EOL> with pytest . raises ( TypeError ) : <EOL> dsa . DSAPrivateNumbers ( <EOL> public_numbers = dsa . DSAPublicNumbers ( <EOL> parameter_numbers = dsa . DSAParameterNumbers ( <EOL> p = DSA_KEY_1024 . public_numbers . parameter_numbers . p , <EOL> q = DSA_KEY_1024 . public_numbers . parameter_numbers . q , <EOL> g = DSA_KEY_1024 . public_numbers . parameter_numbers . g , <EOL> ) , <EOL> y = DSA_KEY_1024 . public_numbers . y <EOL> ) , <EOL> x = None , <EOL> ) . private_key ( backend ) <EOL> def test_invalid_dsa_public_key_arguments ( self , backend ) : <EOL> with pytest . raises ( ValueError ) : <EOL> dsa . DSAPublicNumbers ( <EOL> parameter_numbers = dsa . DSAParameterNumbers ( <EOL> p = <NUM_LIT:2> ** <NUM_LIT:1000> , <EOL> q = DSA_KEY_1024 . public_numbers . parameter_numbers . q , <EOL> g = DSA_KEY_1024 . public_numbers . parameter_numbers . g , <EOL> ) , <EOL> y = DSA_KEY_1024 . public_numbers . y <EOL> ) . public_key ( backend ) <EOL> with pytest . raises ( ValueError ) : <EOL> dsa . DSAPublicNumbers ( <EOL> parameter_numbers = dsa . DSAParameterNumbers ( <EOL> p = <NUM_LIT:2> ** <NUM_LIT> , <EOL> q = DSA_KEY_2048 . public_numbers . parameter_numbers . q , <EOL> g = DSA_KEY_2048 . public_numbers . parameter_numbers . g , <EOL> ) , <EOL> y = DSA_KEY_2048 . public_numbers . y <EOL> ) . public_key ( backend ) <EOL> with pytest . raises ( ValueError ) : <EOL> dsa . DSAPublicNumbers ( <EOL> parameter_numbers = dsa . DSAParameterNumbers ( <EOL> p = <NUM_LIT:2> ** <NUM_LIT> , <EOL> q = DSA_KEY_3072 . public_numbers . parameter_numbers . q , <EOL> g = DSA_KEY_3072 . public_numbers . parameter_numbers . g , <EOL> ) , <EOL> y = DSA_KEY_3072 . public_numbers . y <EOL> ) . public_key ( backend ) <EOL> with pytest . raises ( ValueError ) : <EOL> dsa . DSAPublicNumbers ( <EOL> parameter_numbers = dsa . DSAParameterNumbers ( <EOL> p = <NUM_LIT:2> ** <NUM_LIT> , <EOL> q = DSA_KEY_3072 . public_numbers . parameter_numbers . q , <EOL> g = DSA_KEY_3072 . public_numbers . parameter_numbers . g , <EOL> ) , <EOL> y = DSA_KEY_3072 . public_numbers . y <EOL> ) . public_key ( backend ) <EOL> with pytest . raises ( ValueError ) : <EOL> dsa . DSAPublicNumbers ( <EOL> parameter_numbers = dsa . DSAParameterNumbers ( <EOL> p = DSA_KEY_1024 . public_numbers . parameter_numbers . p , <EOL> q = <NUM_LIT:2> ** <NUM_LIT> , <EOL> g = DSA_KEY_1024 . public_numbers . parameter_numbers . g , <EOL> ) , <EOL> y = DSA_KEY_1024 . public_numbers . y <EOL> ) . public_key ( backend ) <EOL> with pytest . raises ( ValueError ) : <EOL> dsa . DSAPublicNumbers ( <EOL> parameter_numbers = dsa . DSAParameterNumbers ( <EOL> p = DSA_KEY_2048 . public_numbers . parameter_numbers . p , <EOL> q = <NUM_LIT:2> ** <NUM_LIT> , <EOL> g = DSA_KEY_2048 . public_numbers . parameter_numbers . g , <EOL> ) , <EOL> y = DSA_KEY_2048 . public_numbers . y <EOL> ) . public_key ( backend ) <EOL> with pytest . raises ( ValueError ) : <EOL> dsa . DSAPublicNumbers ( <EOL> parameter_numbers = dsa . DSAParameterNumbers ( <EOL> p = DSA_KEY_3072 . public_numbers . parameter_numbers . p , <EOL> q = <NUM_LIT:2> ** <NUM_LIT> , <EOL> g = DSA_KEY_3072 . public_numbers . parameter_numbers . g , <EOL> ) , <EOL> y = DSA_KEY_3072 . public_numbers . y <EOL> ) . public_key ( backend ) <EOL> with pytest . raises ( ValueError ) : <EOL> dsa . DSAPublicNumbers ( <EOL> parameter_numbers = dsa . DSAParameterNumbers ( <EOL> p = DSA_KEY_1024 . public_numbers . parameter_numbers . p , <EOL> q = DSA_KEY_1024 . public_numbers . parameter_numbers . q , <EOL> g = <NUM_LIT:0> , <EOL> ) , <EOL> y = DSA_KEY_1024 . public_numbers . y <EOL> ) . public_key ( backend ) <EOL> with pytest . raises ( ValueError ) : <EOL> dsa . DSAPublicNumbers ( <EOL> parameter_numbers = dsa . DSAParameterNumbers ( <EOL> p = DSA_KEY_1024 . public_numbers . parameter_numbers . p , <EOL> q = DSA_KEY_1024 . public_numbers . parameter_numbers . q , <EOL> g = <NUM_LIT:1> , <EOL> ) , <EOL> y = DSA_KEY_1024 . public_numbers . y <EOL> ) . public_key ( backend ) <EOL> with pytest . raises ( ValueError ) : <EOL> dsa . DSAPublicNumbers ( <EOL> parameter_numbers = dsa . DSAParameterNumbers ( <EOL> p = DSA_KEY_1024 . public_numbers . parameter_numbers . p , <EOL> q = DSA_KEY_1024 . public_numbers . parameter_numbers . q , <EOL> g = <NUM_LIT:2> ** <NUM_LIT> , <EOL> ) , <EOL> y = DSA_KEY_1024 . public_numbers . y <EOL> ) . public_key ( backend ) <EOL> with pytest . raises ( TypeError ) : <EOL> dsa . DSAPublicNumbers ( <EOL> parameter_numbers = dsa . DSAParameterNumbers ( <EOL> p = DSA_KEY_1024 . public_numbers . parameter_numbers . p , <EOL> q = DSA_KEY_1024 . public_numbers . parameter_numbers . q , <EOL> g = DSA_KEY_1024 . public_numbers . parameter_numbers . g , <EOL> ) , <EOL> y = None <EOL> ) . public_key ( backend ) <EOL> @ pytest . mark . requires_backend_interface ( interface = DSABackend ) <EOL> class TestDSAVerification ( object ) : <EOL> _algorithms_dict = { <EOL> '<STR_LIT>' : hashes . SHA1 , <EOL> '<STR_LIT>' : hashes . SHA224 , <EOL> '<STR_LIT>' : hashes . SHA256 , <EOL> '<STR_LIT>' : hashes . SHA384 , <EOL> '<STR_LIT>' : hashes . SHA512 <EOL> } <EOL> @ pytest . mark . parametrize ( <EOL> "<STR_LIT>" , <EOL> load_vectors_from_file ( <EOL> os . path . join ( <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> load_fips_dsa_sig_vectors <EOL> ) <EOL> ) <EOL> def test_dsa_verification ( self , vector , backend ) : <EOL> digest_algorithm = vector [ '<STR_LIT>' ] . replace ( "<STR_LIT:->" , "<STR_LIT>" ) <EOL> algorithm = self . _algorithms_dict [ digest_algorithm ] <EOL> _skip_if_dsa_not_supported ( <EOL> backend , algorithm , vector [ '<STR_LIT:p>' ] , vector [ '<STR_LIT:q>' ] , vector [ '<STR_LIT:g>' ] <EOL> ) <EOL> public_key = dsa . DSAPublicNumbers ( <EOL> parameter_numbers = dsa . DSAParameterNumbers ( <EOL> vector [ '<STR_LIT:p>' ] , vector [ '<STR_LIT:q>' ] , vector [ '<STR_LIT:g>' ] <EOL> ) , <EOL> y = vector [ '<STR_LIT:y>' ] <EOL> ) . public_key ( backend ) <EOL> sig = encode_dss_signature ( vector [ '<STR_LIT:r>' ] , vector [ '<STR_LIT:s>' ] ) <EOL> verifier = public_key . verifier ( sig , algorithm ( ) ) <EOL> verifier . update ( vector [ '<STR_LIT>' ] ) <EOL> if vector [ '<STR_LIT:result>' ] == "<STR_LIT:F>" : <EOL> with pytest . raises ( InvalidSignature ) : <EOL> verifier . verify ( ) <EOL> else : <EOL> verifier . verify ( ) <EOL> def test_dsa_verify_invalid_asn1 ( self , backend ) : <EOL> public_key = DSA_KEY_1024 . public_numbers . public_key ( backend ) <EOL> verifier = public_key . verifier ( b'<STR_LIT>' , hashes . SHA1 ( ) ) <EOL> verifier . update ( b'<STR_LIT>' ) <EOL> with pytest . raises ( InvalidSignature ) : <EOL> verifier . verify ( ) <EOL> def test_signature_not_bytes ( self , backend ) : <EOL> public_key = DSA_KEY_1024 . public_numbers . public_key ( backend ) <EOL> with pytest . raises ( TypeError ) : <EOL> public_key . verifier ( <NUM_LIT> , hashes . SHA1 ( ) ) <EOL> def test_use_after_finalize ( self , backend ) : <EOL> public_key = DSA_KEY_1024 . public_numbers . public_key ( backend ) <EOL> verifier = public_key . verifier ( b'<STR_LIT>' , hashes . SHA1 ( ) ) <EOL> verifier . update ( b'<STR_LIT>' ) <EOL> with pytest . raises ( InvalidSignature ) : <EOL> verifier . verify ( ) <EOL> with pytest . raises ( AlreadyFinalized ) : <EOL> verifier . verify ( ) <EOL> with pytest . raises ( AlreadyFinalized ) : <EOL> verifier . update ( b"<STR_LIT>" ) <EOL> @ pytest . mark . requires_backend_interface ( interface = DSABackend ) <EOL> class TestDSASignature ( object ) : <EOL> _algorithms_dict = { <EOL> '<STR_LIT>' : hashes . SHA1 , <EOL> '<STR_LIT>' : hashes . SHA224 , <EOL> '<STR_LIT>' : hashes . SHA256 , <EOL> '<STR_LIT>' : hashes . SHA384 , <EOL> '<STR_LIT>' : hashes . SHA512 } <EOL> @ pytest . mark . parametrize ( <EOL> "<STR_LIT>" , <EOL> load_vectors_from_file ( <EOL> os . path . join ( <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> load_fips_dsa_sig_vectors <EOL> ) <EOL> ) <EOL> def test_dsa_signing ( self , vector , backend ) : <EOL> digest_algorithm = vector [ '<STR_LIT>' ] . replace ( "<STR_LIT:->" , "<STR_LIT>" ) <EOL> algorithm = self . _algorithms_dict [ digest_algorithm ] <EOL> _skip_if_dsa_not_supported ( <EOL> backend , algorithm , vector [ '<STR_LIT:p>' ] , vector [ '<STR_LIT:q>' ] , vector [ '<STR_LIT:g>' ] <EOL> ) <EOL> private_key = dsa . DSAPrivateNumbers ( <EOL> public_numbers = dsa . DSAPublicNumbers ( <EOL> parameter_numbers = dsa . DSAParameterNumbers ( <EOL> vector [ '<STR_LIT:p>' ] , vector [ '<STR_LIT:q>' ] , vector [ '<STR_LIT:g>' ] <EOL> ) , <EOL> y = vector [ '<STR_LIT:y>' ] <EOL> ) , <EOL> x = vector [ '<STR_LIT:x>' ] <EOL> ) . private_key ( backend ) <EOL> signer = private_key . signer ( algorithm ( ) ) <EOL> signer . update ( vector [ '<STR_LIT>' ] ) <EOL> signature = signer . finalize ( ) <EOL> assert signature <EOL> public_key = private_key . public_key ( ) <EOL> verifier = public_key . verifier ( signature , algorithm ( ) ) <EOL> verifier . update ( vector [ '<STR_LIT>' ] ) <EOL> verifier . verify ( ) <EOL> def test_use_after_finalize ( self , backend ) : <EOL> private_key = DSA_KEY_1024 . private_key ( backend ) <EOL> signer = private_key . signer ( hashes . SHA1 ( ) ) <EOL> signer . update ( b"<STR_LIT:data>" ) <EOL> signer . finalize ( ) <EOL> with pytest . raises ( AlreadyFinalized ) : <EOL> signer . finalize ( ) <EOL> with pytest . raises ( AlreadyFinalized ) : <EOL> signer . update ( b"<STR_LIT>" ) <EOL> class TestDSANumbers ( object ) : <EOL> def test_dsa_parameter_numbers ( self ) : <EOL> parameter_numbers = dsa . DSAParameterNumbers ( p = <NUM_LIT:1> , q = <NUM_LIT:2> , g = <NUM_LIT:3> ) <EOL> assert parameter_numbers . p == <NUM_LIT:1> <EOL> assert parameter_numbers . q == <NUM_LIT:2> <EOL> assert parameter_numbers . g == <NUM_LIT:3> <EOL> def test_dsa_parameter_numbers_invalid_types ( self ) : <EOL> with pytest . raises ( TypeError ) : <EOL> dsa . DSAParameterNumbers ( p = None , q = <NUM_LIT:2> , g = <NUM_LIT:3> ) <EOL> with pytest . raises ( TypeError ) : <EOL> dsa . DSAParameterNumbers ( p = <NUM_LIT:1> , q = None , g = <NUM_LIT:3> ) <EOL> with pytest . raises ( TypeError ) : <EOL> dsa . DSAParameterNumbers ( p = <NUM_LIT:1> , q = <NUM_LIT:2> , g = None ) <EOL> def test_dsa_public_numbers ( self ) : <EOL> parameter_numbers = dsa . DSAParameterNumbers ( p = <NUM_LIT:1> , q = <NUM_LIT:2> , g = <NUM_LIT:3> ) <EOL> public_numbers = dsa . DSAPublicNumbers ( <EOL> y = <NUM_LIT:4> , <EOL> parameter_numbers = parameter_numbers <EOL> ) <EOL> assert public_numbers . y == <NUM_LIT:4> <EOL> assert public_numbers . parameter_numbers == parameter_numbers <EOL> def test_dsa_public_numbers_invalid_types ( self ) : <EOL> with pytest . raises ( TypeError ) : <EOL> dsa . DSAPublicNumbers ( y = <NUM_LIT:4> , parameter_numbers = None ) <EOL> with pytest . raises ( TypeError ) : <EOL> parameter_numbers = dsa . DSAParameterNumbers ( p = <NUM_LIT:1> , q = <NUM_LIT:2> , g = <NUM_LIT:3> ) <EOL> dsa . DSAPublicNumbers ( y = None , parameter_numbers = parameter_numbers ) <EOL> def test_dsa_private_numbers ( self ) : <EOL> parameter_numbers = dsa . DSAParameterNumbers ( p = <NUM_LIT:1> , q = <NUM_LIT:2> , g = <NUM_LIT:3> ) <EOL> public_numbers = dsa . DSAPublicNumbers ( <EOL> y = <NUM_LIT:4> , <EOL> parameter_numbers = parameter_numbers <EOL> ) <EOL> private_numbers = dsa . DSAPrivateNumbers ( <EOL> x = <NUM_LIT:5> , <EOL> public_numbers = public_numbers <EOL> ) <EOL> assert private_numbers . x == <NUM_LIT:5> <EOL> assert private_numbers . public_numbers == public_numbers <EOL> def test_dsa_private_numbers_invalid_types ( self ) : <EOL> parameter_numbers = dsa . DSAParameterNumbers ( p = <NUM_LIT:1> , q = <NUM_LIT:2> , g = <NUM_LIT:3> ) <EOL> public_numbers = dsa . DSAPublicNumbers ( <EOL> y = <NUM_LIT:4> , <EOL> parameter_numbers = parameter_numbers <EOL> ) <EOL> with pytest . raises ( TypeError ) : <EOL> dsa . DSAPrivateNumbers ( x = <NUM_LIT:4> , public_numbers = None ) <EOL> with pytest . raises ( TypeError ) : <EOL> dsa . DSAPrivateNumbers ( x = None , public_numbers = public_numbers ) <EOL> class TestDSANumberEquality ( object ) : <EOL> def test_parameter_numbers_eq ( self ) : <EOL> param = dsa . DSAParameterNumbers ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) <EOL> assert param == dsa . DSAParameterNumbers ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) <EOL> def test_parameter_numbers_ne ( self ) : <EOL> param = dsa . DSAParameterNumbers ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) <EOL> assert param != dsa . DSAParameterNumbers ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:4> ) <EOL> assert param != dsa . DSAParameterNumbers ( <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:3> ) <EOL> assert param != dsa . DSAParameterNumbers ( <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:3> ) <EOL> assert param != object ( ) <EOL> def test_public_numbers_eq ( self ) : <EOL> pub = dsa . DSAPublicNumbers ( <NUM_LIT:1> , dsa . DSAParameterNumbers ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) ) <EOL> assert pub == dsa . DSAPublicNumbers ( <NUM_LIT:1> , dsa . DSAParameterNumbers ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) ) <EOL> def test_public_numbers_ne ( self ) : <EOL> pub = dsa . DSAPublicNumbers ( <NUM_LIT:1> , dsa . DSAParameterNumbers ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) ) <EOL> assert pub != dsa . DSAPublicNumbers ( <NUM_LIT:2> , dsa . DSAParameterNumbers ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) ) <EOL> assert pub != dsa . DSAPublicNumbers ( <NUM_LIT:1> , dsa . DSAParameterNumbers ( <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:3> ) ) <EOL> assert pub != dsa . DSAPublicNumbers ( <NUM_LIT:1> , dsa . DSAParameterNumbers ( <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:3> ) ) <EOL> assert pub != dsa . DSAPublicNumbers ( <NUM_LIT:1> , dsa . DSAParameterNumbers ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:4> ) ) <EOL> assert pub != object ( ) <EOL> def test_private_numbers_eq ( self ) : <EOL> pub = dsa . DSAPublicNumbers ( <NUM_LIT:1> , dsa . DSAParameterNumbers ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) ) <EOL> priv = dsa . DSAPrivateNumbers ( <NUM_LIT:1> , pub ) <EOL> assert priv == dsa . DSAPrivateNumbers ( <EOL> <NUM_LIT:1> , dsa . DSAPublicNumbers ( <EOL> <NUM_LIT:1> , dsa . DSAParameterNumbers ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) <EOL> ) <EOL> ) <EOL> def test_private_numbers_ne ( self ) : <EOL> pub = dsa . DSAPublicNumbers ( <NUM_LIT:1> , dsa . DSAParameterNumbers ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) ) <EOL> priv = dsa . DSAPrivateNumbers ( <NUM_LIT:1> , pub ) <EOL> assert priv != dsa . DSAPrivateNumbers ( <EOL> <NUM_LIT:2> , dsa . DSAPublicNumbers ( <EOL> <NUM_LIT:1> , dsa . DSAParameterNumbers ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) <EOL> ) <EOL> ) <EOL> assert priv != dsa . DSAPrivateNumbers ( <EOL> <NUM_LIT:1> , dsa . DSAPublicNumbers ( <EOL> <NUM_LIT:2> , dsa . DSAParameterNumbers ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) <EOL> ) <EOL> ) <EOL> assert priv != dsa . DSAPrivateNumbers ( <EOL> <NUM_LIT:1> , dsa . DSAPublicNumbers ( <EOL> <NUM_LIT:1> , dsa . DSAParameterNumbers ( <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:3> ) <EOL> ) <EOL> ) <EOL> assert priv != dsa . DSAPrivateNumbers ( <EOL> <NUM_LIT:1> , dsa . DSAPublicNumbers ( <EOL> <NUM_LIT:1> , dsa . DSAParameterNumbers ( <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:3> ) <EOL> ) <EOL> ) <EOL> assert priv != dsa . DSAPrivateNumbers ( <EOL> <NUM_LIT:1> , dsa . DSAPublicNumbers ( <EOL> <NUM_LIT:1> , dsa . DSAParameterNumbers ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:4> ) <EOL> ) <EOL> ) <EOL> assert priv != object ( ) <EOL> @ pytest . mark . requires_backend_interface ( interface = DSABackend ) <EOL> @ pytest . mark . requires_backend_interface ( interface = PEMSerializationBackend ) <EOL> class TestDSASerialization ( object ) : <EOL> @ pytest . mark . parametrize ( <EOL> ( "<STR_LIT>" , "<STR_LIT:password>" ) , <EOL> itertools . product ( <EOL> [ <EOL> serialization . PrivateFormat . TraditionalOpenSSL , <EOL> serialization . PrivateFormat . PKCS8 <EOL> ] , <EOL> [ <EOL> b"<STR_LIT:s>" , <EOL> b"<STR_LIT>" , <EOL> b"<STR_LIT>" , <EOL> b"<STR_LIT>" * <NUM_LIT:1000> , <EOL> ] <EOL> ) <EOL> ) <EOL> def test_private_bytes_encrypted_pem ( self , backend , fmt , password ) : <EOL> key_bytes = load_vectors_from_file ( <EOL> os . path . join ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> lambda pemfile : pemfile . read ( ) . encode ( ) <EOL> ) <EOL> key = serialization . load_pem_private_key ( key_bytes , None , backend ) <EOL> serialized = key . private_bytes ( <EOL> serialization . Encoding . PEM , <EOL> fmt , <EOL> serialization . BestAvailableEncryption ( password ) <EOL> ) <EOL> loaded_key = serialization . load_pem_private_key ( <EOL> serialized , password , backend <EOL> ) <EOL> loaded_priv_num = loaded_key . private_numbers ( ) <EOL> priv_num = key . private_numbers ( ) <EOL> assert loaded_priv_num == priv_num <EOL> @ pytest . mark . parametrize ( <EOL> ( "<STR_LIT>" , "<STR_LIT:password>" ) , <EOL> [ <EOL> [ serialization . PrivateFormat . PKCS8 , b"<STR_LIT:s>" ] , <EOL> [ serialization . PrivateFormat . PKCS8 , b"<STR_LIT>" ] , <EOL> [ serialization . PrivateFormat . PKCS8 , b"<STR_LIT>" ] , <EOL> [ serialization . PrivateFormat . PKCS8 , b"<STR_LIT>" * <NUM_LIT:1000> ] <EOL> ] <EOL> ) <EOL> def test_private_bytes_encrypted_der ( self , backend , fmt , password ) : <EOL> key_bytes = load_vectors_from_file ( <EOL> os . path . join ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> lambda pemfile : pemfile . read ( ) . encode ( ) <EOL> ) <EOL> key = serialization . load_pem_private_key ( key_bytes , None , backend ) <EOL> serialized = key . private_bytes ( <EOL> serialization . Encoding . DER , <EOL> fmt , <EOL> serialization . BestAvailableEncryption ( password ) <EOL> ) <EOL> loaded_key = serialization . load_der_private_key ( <EOL> serialized , password , backend <EOL> ) <EOL> loaded_priv_num = loaded_key . private_numbers ( ) <EOL> priv_num = key . private_numbers ( ) <EOL> assert loaded_priv_num == priv_num <EOL> @ pytest . mark . parametrize ( <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> [ <EOL> [ <EOL> serialization . Encoding . PEM , <EOL> serialization . PrivateFormat . TraditionalOpenSSL , <EOL> serialization . load_pem_private_key <EOL> ] , <EOL> [ <EOL> serialization . Encoding . DER , <EOL> serialization . PrivateFormat . TraditionalOpenSSL , <EOL> serialization . load_der_private_key <EOL> ] , <EOL> [ <EOL> serialization . Encoding . PEM , <EOL> serialization . PrivateFormat . PKCS8 , <EOL> serialization . load_pem_private_key <EOL> ] , <EOL> [ <EOL> serialization . Encoding . DER , <EOL> serialization . PrivateFormat . PKCS8 , <EOL> serialization . load_der_private_key <EOL> ] , <EOL> ] <EOL> ) <EOL> def test_private_bytes_unencrypted ( self , backend , encoding , fmt , <EOL> loader_func ) : <EOL> key = DSA_KEY_1024 . private_key ( backend ) <EOL> serialized = key . private_bytes ( <EOL> encoding , fmt , serialization . NoEncryption ( ) <EOL> ) <EOL> loaded_key = loader_func ( serialized , None , backend ) <EOL> loaded_priv_num = loaded_key . private_numbers ( ) <EOL> priv_num = key . private_numbers ( ) <EOL> assert loaded_priv_num == priv_num <EOL> @ pytest . mark . parametrize ( <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> [ <EOL> [ <EOL> os . path . join ( <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> ) , <EOL> serialization . Encoding . PEM , <EOL> serialization . load_pem_private_key <EOL> ] , <EOL> [ <EOL> os . path . join ( <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" <EOL> ) , <EOL> serialization . Encoding . DER , <EOL> serialization . load_der_private_key <EOL> ] , <EOL> ] <EOL> ) <EOL> def test_private_bytes_traditional_openssl_unencrypted ( <EOL> self , backend , key_path , encoding , loader_func <EOL> ) : <EOL> key_bytes = load_vectors_from_file ( <EOL> key_path , lambda pemfile : pemfile . read ( ) , mode = "<STR_LIT:rb>" <EOL> ) <EOL> key = loader_func ( key_bytes , None , backend ) <EOL> serialized = key . private_bytes ( <EOL> encoding , <EOL> serialization . PrivateFormat . TraditionalOpenSSL , <EOL> serialization . NoEncryption ( ) <EOL> ) <EOL> assert serialized == key_bytes <EOL> def test_private_bytes_traditional_der_encrypted_invalid ( self , backend ) : <EOL> key = DSA_KEY_1024 . private_key ( backend ) <EOL> with pytest . raises ( ValueError ) : <EOL> key . private_bytes ( <EOL> serialization . Encoding . DER , <EOL> serialization . PrivateFormat . TraditionalOpenSSL , <EOL> serialization . BestAvailableEncryption ( b"<STR_LIT:password>" ) <EOL> ) <EOL> def test_private_bytes_invalid_encoding ( self , backend ) : <EOL> key = load_vectors_from_file ( <EOL> os . path . join ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> lambda pemfile : serialization . load_pem_private_key ( <EOL> pemfile . read ( ) . encode ( ) , None , backend <EOL> ) <EOL> ) <EOL> with pytest . raises ( TypeError ) : <EOL> key . private_bytes ( <EOL> "<STR_LIT>" , <EOL> serialization . PrivateFormat . PKCS8 , <EOL> serialization . NoEncryption ( ) <EOL> ) <EOL> def test_private_bytes_invalid_format ( self , backend ) : <EOL> key = load_vectors_from_file ( <EOL> os . path . join ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> lambda pemfile : serialization . load_pem_private_key ( <EOL> pemfile . read ( ) . encode ( ) , None , backend <EOL> ) <EOL> ) <EOL> with pytest . raises ( TypeError ) : <EOL> key . private_bytes ( <EOL> serialization . Encoding . PEM , <EOL> "<STR_LIT>" , <EOL> serialization . NoEncryption ( ) <EOL> ) <EOL> def test_private_bytes_invalid_encryption_algorithm ( self , backend ) : <EOL> key = load_vectors_from_file ( <EOL> os . path . join ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> lambda pemfile : serialization . load_pem_private_key ( <EOL> pemfile . read ( ) . encode ( ) , None , backend <EOL> ) <EOL> ) <EOL> with pytest . raises ( TypeError ) : <EOL> key . private_bytes ( <EOL> serialization . Encoding . PEM , <EOL> serialization . PrivateFormat . TraditionalOpenSSL , <EOL> "<STR_LIT>" <EOL> ) <EOL> def test_private_bytes_unsupported_encryption_type ( self , backend ) : <EOL> key = load_vectors_from_file ( <EOL> os . path . join ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> lambda pemfile : serialization . load_pem_private_key ( <EOL> pemfile . read ( ) . encode ( ) , None , backend <EOL> ) <EOL> ) <EOL> with pytest . raises ( ValueError ) : <EOL> key . private_bytes ( <EOL> serialization . Encoding . PEM , <EOL> serialization . PrivateFormat . TraditionalOpenSSL , <EOL> DummyKeySerializationEncryption ( ) <EOL> ) <EOL> @ pytest . mark . requires_backend_interface ( interface = DSABackend ) <EOL> @ pytest . mark . requires_backend_interface ( interface = PEMSerializationBackend ) <EOL> class TestDSAPEMPublicKeySerialization ( object ) : <EOL> @ pytest . mark . parametrize ( <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> [ <EOL> ( <EOL> os . path . join ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> serialization . load_pem_public_key , <EOL> serialization . Encoding . PEM , <EOL> ) , ( <EOL> os . path . join ( <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> ) , <EOL> serialization . load_der_public_key , <EOL> serialization . Encoding . DER , <EOL> ) <EOL> ] <EOL> ) <EOL> def test_public_bytes_match ( self , key_path , loader_func , encoding , <EOL> backend ) : <EOL> key_bytes = load_vectors_from_file ( <EOL> key_path , lambda pemfile : pemfile . read ( ) , mode = "<STR_LIT:rb>" <EOL> ) <EOL> key = loader_func ( key_bytes , backend ) <EOL> serialized = key . public_bytes ( <EOL> encoding , serialization . PublicFormat . SubjectPublicKeyInfo , <EOL> ) <EOL> assert serialized == key_bytes <EOL> def test_public_bytes_invalid_encoding ( self , backend ) : <EOL> key = DSA_KEY_2048 . private_key ( backend ) . public_key ( ) <EOL> with pytest . raises ( TypeError ) : <EOL> key . public_bytes ( <EOL> "<STR_LIT>" , <EOL> serialization . PublicFormat . SubjectPublicKeyInfo <EOL> ) <EOL> def test_public_bytes_invalid_format ( self , backend ) : <EOL> key = DSA_KEY_2048 . private_key ( backend ) . public_key ( ) <EOL> with pytest . raises ( TypeError ) : <EOL> key . public_bytes ( serialization . Encoding . PEM , "<STR_LIT>" ) <EOL> def test_public_bytes_pkcs1_unsupported ( self , backend ) : <EOL> key = DSA_KEY_2048 . private_key ( backend ) . public_key ( ) <EOL> with pytest . raises ( ValueError ) : <EOL> key . public_bytes ( <EOL> serialization . Encoding . PEM , serialization . PublicFormat . PKCS1 <EOL> ) </s>
