gettalong / hexapdf

Versatile PDF creation and manipulation for Ruby
https://hexapdf.gettalong.org
Other
1.21k stars 69 forks source link

How we know level DocMDP from the document? #284

Closed WSPDV closed 6 months ago

WSPDV commented 7 months ago

Hi mas @gettalong

Can we get the level DocMDP from the already signed document using .signatures?

I can get the information on the signature, but I didn't find information about docMDP

image

Thank you

gettalong commented 7 months ago

This information is available in doc.signatures.first[:Reference].first[:TransformMethod], i.e. from the signature reference dictionary of the signature object.

WSPDV commented 7 months ago

Thank you mas @gettalong that's very helpful. But, not necessarily all PDF document has a TransformMethod. I just read your documentation at

https://hexapdf.gettalong.org/documentation/api/HexaPDF/DigitalSignature/Signing/DefaultHandler.html#method-i-doc_mdp_permissions-3D

The default is nil.

How about the level DocMDP if has no TransformMethod method (nil value)? is the no DocMDP the same as level 3?

signature_dict = doc.signatures.first

# the sigref have possibility null value
sigref = signature_dict[:Reference]&.find {|ref| ref[:TransformMethod] == :DocMDP }
gettalong commented 6 months ago

You are right, there doesn't need to be any signature reference dictionary. So if there isn't, then the document doesn't have a certification signature.

WSPDV commented 6 months ago

Terima kasih mas @gettalong 🙏🏿