Class: HexaPDF::Type::DocumentSecurityStore
- Inherits:
-
Dictionary
- Object
- Object
- Dictionary
- HexaPDF::Type::DocumentSecurityStore
- Defined in:
- lib/hexapdf/type/document_security_store.rb
Overview
The document security store (DSS) dictionary contains data needed for verifying digital signatures.
See: PDF2.0 s12.8.4.3
Defined Under Namespace
Classes: ValidationRelatedInformation
Constant Summary
Constants included from DictionaryFields
DictionaryFields::Boolean, DictionaryFields::PDFByteString, DictionaryFields::PDFDate
Instance Method Summary collapse
-
#add_cert(cert_der) ⇒ Object
Adds the DER-encoded certificate to the /Certs array if not already present and returns the stream object containing it.
-
#add_crl(crl_der) ⇒ Object
Adds the DER-encoded CRL to the /CRLs array if not already present and returns the stream object containing it.
-
#add_ocsp(ocsp_der) ⇒ Object
Adds the DER-encoded OCSP response to the /OCSPs array if not already present and returns the stream object containing it.
-
#add_vri(signature, certs: [], ocsps: [], crls: []) ⇒ Object
Adds validation data for a single signature to the /VRI dictionary and to the various arrays, and returns the new VRI entry.
-
#certificates ⇒ Object
Returns all certificates in the /Certs array as OpenSSL::X509::Certificate objects.
-
#vri_for(signature) ⇒ Object
Returns the VRI dictionary for the given signature if it exists or else
nil.
Methods inherited from Dictionary
#[], #[]=, define_field, define_type, #delete, #each, each_field, #empty?, field, #key?, #to_hash, type, #type
Instance Method Details
#add_cert(cert_der) ⇒ Object
Adds the DER-encoded certificate to the /Certs array if not already present and returns the stream object containing it.
104 105 106 |
# File 'lib/hexapdf/type/document_security_store.rb', line 104 def add_cert(cert_der) add_data_as_stream_to_field(cert_der, :Certs) end |
#add_crl(crl_der) ⇒ Object
Adds the DER-encoded CRL to the /CRLs array if not already present and returns the stream object containing it.
116 117 118 |
# File 'lib/hexapdf/type/document_security_store.rb', line 116 def add_crl(crl_der) add_data_as_stream_to_field(crl_der, :CRLs) end |
#add_ocsp(ocsp_der) ⇒ Object
Adds the DER-encoded OCSP response to the /OCSPs array if not already present and returns the stream object containing it.
110 111 112 |
# File 'lib/hexapdf/type/document_security_store.rb', line 110 def add_ocsp(ocsp_der) add_data_as_stream_to_field(ocsp_der, :OCSPs) end |
#add_vri(signature, certs: [], ocsps: [], crls: []) ⇒ Object
Adds validation data for a single signature to the /VRI dictionary and to the various arrays, and returns the new VRI entry.
signatureThe signature for which the validation data should be added.
certsArray of DER-encoded certificates.
ocspsArray of DER-encoded OCSP responses.
crlsArray of DER-encoded CRLs.
88 89 90 91 92 93 94 95 |
# File 'lib/hexapdf/type/document_security_store.rb', line 88 def add_vri(signature, certs: [], ocsps: [], crls: []) key = OpenSSL::Digest::SHA1.hexdigest(signature.contents).upcase.to_sym vri = {Type: :VRI} vri[:Cert] = certs.map {|der| add_cert(der) } unless certs.empty? vri[:OCSP] = ocsps.map {|der| add_ocsp(der) } unless ocsps.empty? vri[:CRL] = crls.map {|der| add_crl(der) } unless crls.empty? (self[:VRI] ||= {})[key] = document.add(vri) end |
#certificates ⇒ Object
Returns all certificates in the /Certs array as OpenSSL::X509::Certificate objects.
121 122 123 124 125 126 127 |
# File 'lib/hexapdf/type/document_security_store.rb', line 121 def certificates if key?(:Certs) self[:Certs].length.times.map {|i| OpenSSL::X509::Certificate.new(self[:Certs][i].stream) } else [] end end |
#vri_for(signature) ⇒ Object
Returns the VRI dictionary for the given signature if it exists or else nil.
98 99 100 |
# File 'lib/hexapdf/type/document_security_store.rb', line 98 def vri_for(signature) self[:VRI] && self[:VRI][OpenSSL::Digest::SHA1.hexdigest(signature.contents).upcase.to_sym] end |