@@ -905,6 +905,25 @@ def test_pkcs7_verify_der(
905
905
# Verification
906
906
pkcs7 .pkcs7_verify_der (signature , data , certificate , [])
907
907
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
+
908
927
def test_pkcs7_verify_der_no_data (
909
928
self , backend , data , certificate , private_key
910
929
):
@@ -924,6 +943,20 @@ def test_pkcs7_verify_der_no_data(
924
943
with pytest .raises (ValueError ):
925
944
pkcs7 .pkcs7_verify_der (signature , None , certificate , [])
926
945
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
+
927
960
def test_pkcs7_verify_der_wrong_certificate (
928
961
self , backend , data , certificate , private_key
929
962
):
0 commit comments