Class: RestPki::XmlElementSignatureStarter

Inherits:
XmlSignatureStarter show all
Defined in:
lib/rest_pki/xml_element_signature_starter.rb

Instance Attribute Summary collapse

Attributes inherited from SignatureStarter

#callback_argument, #ignore_revocation_status_unknown, #security_context_id, #signature_policy_id

Instance Method Summary collapse

Methods inherited from XmlSignatureStarter

#set_signature_element_location, #set_xml_content_tosign, #set_xml_file_tosign, #set_xml_tosign_from_base64, #set_xml_tosign_from_path, #set_xml_tosign_from_raw

Methods inherited from SignatureStarter

#certificate, #signer_certificate=, #signer_certificate_base64=

Constructor Details

#initialize(restpki_client) ⇒ XmlElementSignatureStarter

Returns a new instance of XmlElementSignatureStarter.



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

def initialize(restpki_client)
    super(restpki_client)
    @element_tosign_id = nil
    @id_resolution_table = nil
end

Instance Attribute Details

#element_tosign_idObject

Returns the value of attribute element_tosign_id.



3
4
5
# File 'lib/rest_pki/xml_element_signature_starter.rb', line 3

def element_tosign_id
  @element_tosign_id
end

#id_resolution_tableObject

Returns the value of attribute id_resolution_table.



3
4
5
# File 'lib/rest_pki/xml_element_signature_starter.rb', line 3

def id_resolution_table
  @id_resolution_table
end

Instance Method Details

#startObject



36
37
38
39
40
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
# File 'lib/rest_pki/xml_element_signature_starter.rb', line 36

def start
    verify_common_parameters(true)
    if @xml_content_base64.to_s.blank?
        raise 'The XML was not set'
    end
    if @element_tosign_id.to_s.blank?
        raise 'The XML element id to sign was not set'
    end

    request = get_request
    request['elementToSignId'] = @element_tosign_id
    unless @id_resolution_table.nil?
        request['idResolutionTable'] = @id_resolution_table.to_model
    end

    response = @restpki_client.post('Api/XmlSignatures/XmlElementSignature', request, 'xml_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_webpkiObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rest_pki/xml_element_signature_starter.rb', line 11

def start_with_webpki
    verify_common_parameters(true)
    if @xml_content_base64.to_s.blank?
        raise 'The XML was not set'
    end
    if @element_tosign_id.to_s.blank?
        raise 'The XML element id to sign was not set'
    end

    request = get_request
    request['elementToSignId'] = @element_tosign_id
    unless @id_resolution_table.nil?
        request['idResolutionTable'] = @id_resolution_table.to_model
    end

    response = @restpki_client.post('Api/XmlSignatures/XmlElementSignature', request, 'xml_model')

    unless response['certificate'].nil?
        @certificate = response['certificate']
    end
    @done = true

    response['token']
end