Skip to content

Commit

Permalink
Added detached property for cms.SignedData and made data property od …
Browse files Browse the repository at this point in the history
…detached signatures return None instead of throwing exception
  • Loading branch information
vbwagner committed Nov 8, 2018
1 parent 201998c commit 33c3290
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions ctypescrypto/cms.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,20 @@ def signers(self):
return StackOfX509(ptr=signerlist, disposable=False)

@property
def detached(self):
"""
True, if SignedData object represents detached signature, i.e.
just signature without data inside.
"""
return libcrypto.CMS_is_detached(self.ptr) != 0
@property
def data(self):
"""
Returns signed data if present in the message
"""
# Check if signatire is detached
if self.detached:
return None
bio = Membio()
if not libcrypto.CMS_verify(self.ptr, None, None, None, bio.bio,
Flags.NO_VERIFY):
Expand Down Expand Up @@ -363,6 +373,8 @@ def decrypt(self, key, flags=0):
libcrypto.CMS_get1_certs.restype = c_void_p
libcrypto.CMS_get1_certs.argtypes = (c_void_p, )
libcrypto.CMS_sign.restype = c_void_p
libcrypto.CMS_is_detached.argtypes = (c_void_p,)
libcrypto.CMS_is_detached.restype = c_int
libcrypto.CMS_sign.argtypes = (c_void_p, c_void_p, c_void_p, c_void_p, c_uint)
libcrypto.CMS_add1_signer.restype = c_void_p
libcrypto.CMS_add1_signer.argtypes = (c_void_p, c_void_p, c_void_p,
Expand Down

0 comments on commit 33c3290

Please sign in to comment.