Class: RestPki::CadesSignatureFinisher

Inherits:
SignatureFinisher show all
Defined in:
lib/rest_pki/cades_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) ⇒ CadesSignatureFinisher

Returns a new instance of CadesSignatureFinisher.



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

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

Instance Method Details

#cmsObject



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

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

    @cms
end

#finishObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rest_pki/cades_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/CadesSignatures/#{@token}/Finalize", nil, 'cades_model')
    else
        request = { signature: @signature }
        response = @restpki_client.post("Api/CadesSignatures/#{@token}/SignedBytes", request, 'cades_model')
    end

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

    @cms
end

#write_cms_to_path(path) ⇒ Object



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

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

    file = File.open(path, 'wb')
    file.write(@cms)
    file.close
end