Class: RestPki::PadesSignatureFinisher

Inherits:
SignatureFinisher show all
Defined in:
lib/rest_pki/pades_signature_finisher.rb

Instance Attribute Summary

Attributes inherited from SignatureFinisher

#signature, #token

Instance Method Summary collapse

Methods inherited from SignatureFinisher

#certificate_info, #get_callback_argument

Constructor Details

#initialize(restpki_client) ⇒ PadesSignatureFinisher

Returns a new instance of PadesSignatureFinisher.



5
6
7
8
# File 'lib/rest_pki/pades_signature_finisher.rb', line 5

def initialize(restpki_client)
    super(restpki_client)
    @signed_pdf_content = nil
end

Instance Method Details

#finishObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rest_pki/pades_signature_finisher.rb', line 10

def finish
    if @token.to_s.blank?
        raise 'The token was not set'
    end

    if @signature.to_s.blank?
        response = @restpki_client.post("Api/PadesSignatures/#{@token}/Finalize", nil, 'pades_model')
    else
        request = { signature: @signature }
        response = @restpki_client.post("Api/PadesSignatures/#{@token}/SignedBytes", request, 'pades_model')
    end

    @signed_pdf_content = Base64.decode64(response['signedPdf'])
    @callback_argument = response['callbackArgument']
    @certificate_info = response['certificate']
    @done = true

    @signed_pdf_content
end

#signed_pdf_contentObject



30
31
32
33
34
35
36
# File 'lib/rest_pki/pades_signature_finisher.rb', line 30

def signed_pdf_content
    unless @done
        raise 'The field "signed_pdf_content" can only be accessed after calling the finish method'
    end

    @signed_pdf_content
end

#write_signed_pdf(pdf_path) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/rest_pki/pades_signature_finisher.rb', line 38

def write_signed_pdf(pdf_path)
    unless @done
        raise 'The method write_signed_pdf can only be called after calling the finish method'
    end

    file = File.open(pdf_path, 'wb')
    file.write(@signed_pdf_content)
    file.close

    nil # No value is returned.
end