Class: RestPki::PadesSignatureStarter
- Inherits:
-
SignatureStarter
- Object
- SignatureStarter
- RestPki::PadesSignatureStarter
- Defined in:
- lib/rest_pki/pades_signature_starter.rb
Instance Attribute Summary collapse
-
#visual_representation ⇒ Object
Returns the value of attribute visual_representation.
Attributes inherited from SignatureStarter
#callback_argument, #ignore_revocation_status_unknown, #security_context_id, #signature_policy_id
Instance Method Summary collapse
-
#initialize(restpki_client) ⇒ PadesSignatureStarter
constructor
A new instance of PadesSignatureStarter.
- #set_pdf_content_tosign(content_raw) ⇒ Object
- #set_pdf_file_tosign(pdf_path) ⇒ Object
- #set_pdf_tosign_from_base64(content_base64) ⇒ Object
-
#set_pdf_tosign_from_path(pdf_path) ⇒ Object
region set_pdf_tosign.
- #set_pdf_tosign_from_raw(content_raw) ⇒ Object
- #start ⇒ Object
-
#start_with_webpki ⇒ Object
endregion.
Methods inherited from SignatureStarter
#certificate, #signer_certificate=, #signer_certificate_base64=
Constructor Details
#initialize(restpki_client) ⇒ PadesSignatureStarter
Returns a new instance of PadesSignatureStarter.
7 8 9 10 11 |
# File 'lib/rest_pki/pades_signature_starter.rb', line 7 def initialize(restpki_client) super(restpki_client) @pdf_content_base64 = nil @visual_representation = nil end |
Instance Attribute Details
#visual_representation ⇒ Object
Returns the value of attribute visual_representation.
5 6 7 |
# File 'lib/rest_pki/pades_signature_starter.rb', line 5 def visual_representation @visual_representation end |
Instance Method Details
#set_pdf_content_tosign(content_raw) ⇒ Object
31 32 33 |
# File 'lib/rest_pki/pades_signature_starter.rb', line 31 def set_pdf_content_tosign(content_raw) set_pdf_tosign_from_raw(content_raw) end |
#set_pdf_file_tosign(pdf_path) ⇒ Object
35 36 37 |
# File 'lib/rest_pki/pades_signature_starter.rb', line 35 def set_pdf_file_tosign(pdf_path) set_pdf_tosign_from_path(pdf_path) end |
#set_pdf_tosign_from_base64(content_base64) ⇒ Object
27 28 29 |
# File 'lib/rest_pki/pades_signature_starter.rb', line 27 def set_pdf_tosign_from_base64(content_base64) @pdf_content_base64 = content_base64 end |
#set_pdf_tosign_from_path(pdf_path) ⇒ Object
region set_pdf_tosign
15 16 17 18 19 20 21 |
# File 'lib/rest_pki/pades_signature_starter.rb', line 15 def set_pdf_tosign_from_path(pdf_path) file = File.open(pdf_path, 'rb') @pdf_content_base64 = Base64.encode64(file.read) file.close @pdf_content_base64 end |
#set_pdf_tosign_from_raw(content_raw) ⇒ Object
23 24 25 |
# File 'lib/rest_pki/pades_signature_starter.rb', line 23 def set_pdf_tosign_from_raw(content_raw) @pdf_content_base64 = Base64.encode64(content_raw) end |
#start ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/rest_pki/pades_signature_starter.rb', line 71 def start if @pdf_content_base64.to_s.blank? raise 'The PDF to sign was not set' end if @signature_policy_id.to_s.blank? raise 'The signature policy was not set' end if @signer_certificate_base64.to_s.blank? raise 'The signer certificate was not set' end request = { securityContextId: @security_context_id, pdfToSign: @pdf_content_base64, signaturePolicyId: @signature_policy_id, callbackArgument: @callback_argument, visualRepresentation: @visual_representation, ignoreRevocationStatusUnknown: @ignore_revocation_status_unknown } unless @signer_certificate_base64.to_s.blank? request['certificate'] = Base64.encode64(@signer_certificate_base64) end response = @restpki_client.post('Api/PadesSignatures', request, 'pades_model') unless response['certificate'].nil? @certificate = response['certificate'] end @done = true { :token => response['token'], :to_sign_data => response['toSignData'], :to_sign_hash => response['toSignHash'], :digest_algorithm_oid => response['digestAlgorithmOid'], :signature_algorithm => get_signature_algorithm(response['digestAlgorithmOid']) } end |
#start_with_webpki ⇒ Object
endregion
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/rest_pki/pades_signature_starter.rb', line 41 def start_with_webpki if @pdf_content_base64.to_s.blank? raise 'The PDF to sign was not set' end if @signature_policy_id.to_s.blank? raise 'The signature policy was not set' end request = { securityContextId: @security_context_id, pdfToSign: @pdf_content_base64, signaturePolicyId: @signature_policy_id, callbackArgument: @callback_argument, visualRepresentation: @visual_representation, ignoreRevocationStatusUnknown: @ignore_revocation_status_unknown } unless @signer_certificate_base64.to_s.blank? request['certificate'] = Base64.encode64(@signer_certificate_base64) end response = @restpki_client.post('Api/PadesSignatures', request, 'pades_model') unless response['certificate'].nil? @certificate = response['certificate'] end @done = true response['token'] end |