@@ -920,6 +920,25 @@ def test_pkcs7_verify_der(
920
920
# Verification
921
921
pkcs7 .pkcs7_verify_der (signature , data , certificate , [])
922
922
923
+ def test_pkcs7_verify_der_no_content (
924
+ self , backend , data , certificate , private_key
925
+ ):
926
+ """
927
+ Tests verification when needing the content stored in the PKCS7 signed
928
+ data structure.
929
+ """
930
+ # Signature
931
+ builder = (
932
+ pkcs7 .PKCS7SignatureBuilder ()
933
+ .set_data (data )
934
+ .add_signer (certificate , private_key , hashes .SHA256 ())
935
+ )
936
+ options = [pkcs7 .PKCS7Options .NoAttributes ]
937
+ signature = builder .sign (serialization .Encoding .DER , options )
938
+
939
+ # Verification
940
+ pkcs7 .pkcs7_verify_der (signature , None , certificate , [])
941
+
923
942
def test_pkcs7_verify_der_no_data (
924
943
self , backend , data , certificate , private_key
925
944
):
@@ -939,6 +958,20 @@ def test_pkcs7_verify_der_no_data(
939
958
with pytest .raises (ValueError ):
940
959
pkcs7 .pkcs7_verify_der (signature , None , certificate , [])
941
960
961
+ def test_pkcs7_verify_der_not_signed (self , backend , data ):
962
+ # Encryption of data with a text/html content type header
963
+ certificate , _ = _load_rsa_cert_key ()
964
+ builder = (
965
+ pkcs7 .PKCS7EnvelopeBuilder ()
966
+ .set_data (b"Hello world!" )
967
+ .add_recipient (certificate )
968
+ )
969
+ enveloped = builder .encrypt (serialization .Encoding .DER , [])
970
+
971
+ # Verification
972
+ with pytest .raises (ValueError ):
973
+ pkcs7 .pkcs7_verify_der (enveloped , None , certificate , [])
974
+
942
975
def test_pkcs7_verify_der_wrong_certificate (
943
976
self , backend , data , certificate , private_key
944
977
):
0 commit comments