@@ -905,6 +905,25 @@ def test_pkcs7_verify_der(
905905 # Verification
906906 pkcs7 .pkcs7_verify_der (signature , data , certificate , [])
907907
908+ def test_pkcs7_verify_der_no_content (
909+ self , backend , data , certificate , private_key
910+ ):
911+ """
912+ Tests verification when needing the content stored in the PKCS7 signed
913+ data structure.
914+ """
915+ # Signature
916+ builder = (
917+ pkcs7 .PKCS7SignatureBuilder ()
918+ .set_data (data )
919+ .add_signer (certificate , private_key , hashes .SHA256 ())
920+ )
921+ options = [pkcs7 .PKCS7Options .NoAttributes ]
922+ signature = builder .sign (serialization .Encoding .DER , options )
923+
924+ # Verification
925+ pkcs7 .pkcs7_verify_der (signature , None , certificate , [])
926+
908927 def test_pkcs7_verify_der_no_data (
909928 self , backend , data , certificate , private_key
910929 ):
@@ -924,6 +943,20 @@ def test_pkcs7_verify_der_no_data(
924943 with pytest .raises (ValueError ):
925944 pkcs7 .pkcs7_verify_der (signature , None , certificate , [])
926945
946+ def test_pkcs7_verify_der_not_signed (self , backend , data ):
947+ # Encryption of data with a text/html content type header
948+ certificate , _ = _load_rsa_cert_key ()
949+ builder = (
950+ pkcs7 .PKCS7EnvelopeBuilder ()
951+ .set_data (b"Hello world!" )
952+ .add_recipient (certificate )
953+ )
954+ enveloped = builder .encrypt (serialization .Encoding .DER , [])
955+
956+ # Verification
957+ with pytest .raises (ValueError ):
958+ pkcs7 .pkcs7_verify_der (enveloped , None , certificate , [])
959+
927960 def test_pkcs7_verify_der_wrong_certificate (
928961 self , backend , data , certificate , private_key
929962 ):
0 commit comments