class PkiExpress::CadesSignatureStarter

Attributes

encapsulated_content[RW]

Public Class Methods

new(config=PkiExpressConfig.new) click to toggle source
Calls superclass method
# File lib/pki_express/cades_signature_starter.rb, line 7
def initialize(config=PkiExpressConfig.new)
  super(config)
  @file_to_sign_path = nil
  @data_file_path = nil
  @encapsulated_content = true
end

Public Instance Methods

data_file() click to toggle source

region The “data_file” accessors

# File lib/pki_express/cades_signature_starter.rb, line 108
def data_file
  _get_data_file
end
data_file=(content_raw) click to toggle source
# File lib/pki_express/cades_signature_starter.rb, line 121
def data_file=(content_raw)
  _set_data_file(content_raw)
end
data_file_base64() click to toggle source
# File lib/pki_express/cades_signature_starter.rb, line 138
def data_file_base64
  _get_data_file_base64
end
data_file_base64=(content_base64) click to toggle source
# File lib/pki_express/cades_signature_starter.rb, line 152
def data_file_base64=(content_base64)
  _set_data_file_base64(content_base64)
end
data_file_path() click to toggle source
# File lib/pki_express/cades_signature_starter.rb, line 171
def data_file_path
  _get_data_file_path
end
data_file_path=(path) click to toggle source
# File lib/pki_express/cades_signature_starter.rb, line 180
def data_file_path=(path)
  _set_data_file_path(path)
end
file_to_sign() click to toggle source

region The “file_to_sign” accessors

# File lib/pki_express/cades_signature_starter.rb, line 16
def file_to_sign
  _get_file_to_sign
end
file_to_sign=(content_raw) click to toggle source
# File lib/pki_express/cades_signature_starter.rb, line 29
def file_to_sign=(content_raw)
  _set_file_to_sign(content_raw)
end
file_to_sign_base64() click to toggle source
# File lib/pki_express/cades_signature_starter.rb, line 46
def file_to_sign_base64
  _get_file_to_sign_base64
end
file_to_sign_base64=(content_base64) click to toggle source
# File lib/pki_express/cades_signature_starter.rb, line 60
def file_to_sign_base64=(content_base64)
  _set_file_to_sign_base64(content_base64)
end
file_to_sign_path() click to toggle source
# File lib/pki_express/cades_signature_starter.rb, line 79
def file_to_sign_path
  _get_file_to_sign_path
end
file_to_sign_path=(path) click to toggle source
# File lib/pki_express/cades_signature_starter.rb, line 88
def file_to_sign_path=(path)
  _set_file_to_sign_path(path)
end
start() click to toggle source

endregion

# File lib/pki_express/cades_signature_starter.rb, line 198
def start

  unless @file_to_sign_path
    raise 'The file to be signed was not set'
  end

  unless @certificate_path
    raise 'The certificate was not set'
  end

  # Generate transfer file.
  transfer_file_id = get_transfer_filename

  args = [
      @file_to_sign_path,
      @certificate_path,
      File.expand_path(transfer_file_id, @config.transfer_data_folder),
  ]

  # Verify and add common options between signers.
  verify_and_add_common_options(args)

  if @data_file_path
    args.append('--data-file')
    args.append(@data_file_path)
  end

  unless @encapsulated_content
    args.append('--detached')
  end

  # This operation can only be used on version greater than 1.3 of the
  # PKI Express.
  @version_manager.require_version('1.3')

  # Invoke command.
  result = invoke(Commands::START_CADES, args)

  # Parse output and return model.
  model = parse_output(result)
  SignatureStartResult.new(model, transfer_file_id)
end

Private Instance Methods

_get_data_file() click to toggle source
# File lib/pki_express/cades_signature_starter.rb, line 112
def _get_data_file
  unless @data_file_path
    return nil
  end

  File.read(@data_file_path)
end
_get_data_file_base64() click to toggle source
# File lib/pki_express/cades_signature_starter.rb, line 142
def _get_data_file_base64
  unless @data_file_path
    return nil
  end

  content = File.read(@data_file_path)
  Base64.encode64(content)
end
_get_data_file_path() click to toggle source
# File lib/pki_express/cades_signature_starter.rb, line 175
def _get_data_file_path
  @data_file_path
end
_get_file_to_sign() click to toggle source
# File lib/pki_express/cades_signature_starter.rb, line 20
def _get_file_to_sign
  unless @file_to_sign_path
    return nil
  end

  File.read(@file_to_sign_path)
end
_get_file_to_sign_base64() click to toggle source
# File lib/pki_express/cades_signature_starter.rb, line 50
def _get_file_to_sign_base64
  unless @file_to_sign_path
    return nil
  end

  content = File.read(@file_to_sign_path)
  Base64.encode64(content)
end
_get_file_to_sign_path() click to toggle source
# File lib/pki_express/cades_signature_starter.rb, line 83
def _get_file_to_sign_path
  @file_to_sign_path
end
_set_data_file(content_raw) click to toggle source
# File lib/pki_express/cades_signature_starter.rb, line 125
def _set_data_file(content_raw)
  unless content_raw
    raise 'The provided "data_file" is not valid'
  end

  temp_file_path = self.create_temp_file
  File.open(temp_file_path, 'wb') do |f|
    f.write(content_raw)
  end
  @data_file_path = temp_file_path
end
_set_data_file_base64(content_base64) click to toggle source
# File lib/pki_express/cades_signature_starter.rb, line 156
def _set_data_file_base64(content_base64)
  unless content_base64
    raise 'The provided "data_file_base64" is not valid'
  end

  begin
    content_raw = Base64.decode64(content_base64)
  rescue Error
    raise 'The provided "data_file_base64" is not Base64-encoded'
  end

  _set_data_file(content_raw)
end
_set_data_file_path(path) click to toggle source
# File lib/pki_express/cades_signature_starter.rb, line 184
def _set_data_file_path(path)
  unless path
    raise 'The provided "data_file_path" is not valid'
  end
  unless File.exists?(path)
    raise 'The provided "data_file_path" does not exist'
  end

  @data_file_path = path
end
_set_file_to_sign(content_raw) click to toggle source
# File lib/pki_express/cades_signature_starter.rb, line 33
def _set_file_to_sign(content_raw)
  unless content_raw
    raise 'The provided "file_to_sign" is not valid'
  end

  temp_file_path = self.create_temp_file
  File.open(temp_file_path, 'wb') do |f|
    f.write(content_raw)
  end
  @file_to_sign_path = temp_file_path
end
_set_file_to_sign_base64(content_base64) click to toggle source
# File lib/pki_express/cades_signature_starter.rb, line 64
def _set_file_to_sign_base64(content_base64)
  unless content_base64
    raise 'The provided "file_to_sign_base64" is not valid'
  end

  begin
    content_raw = Base64.decode64(content_base64)
  rescue Error
    raise 'The provided "file_to_sign_base64" is not Base64-encoded'
  end

  _set_file_to_sign(content_raw)
end
_set_file_to_sign_path(path) click to toggle source
# File lib/pki_express/cades_signature_starter.rb, line 92
def _set_file_to_sign_path(path)
  unless path
    raise 'The provided "file_to_sign_path" is not valid'
  end
  unless File.exists?(path)
    raise 'The provided "file_to_sign_path" does not exist'
  end

  @file_to_sign_path = path
end