class RestPki::PadesSignatureStarter

Attributes

visual_representation[RW]

Public Class Methods

new(restpki_client) click to toggle source
Calls superclass method
# 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

Public Instance Methods

set_pdf_content_tosign(content_raw) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source

region set_pdf_tosign

# 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) click to toggle source
# 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() click to toggle source
# 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() click to toggle source

endregion

# 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