Class: Aspera::DataRepository

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/aspera/data_repository.rb

Overview

a simple binary data repository

Constant Summary collapse

ELEMENTS =

in same order as elements in folder

%i[dsa rsa uuid aspera.global-cli-client aspera.drive license]

Instance Method Summary collapse

Instance Method Details

#item(name) ⇒ String

decode data as expected as string

Parameters:

  • name (Symbol)

    name of the data item

Returns:

Raises:

  • (ArgumentError)


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/aspera/data_repository.rb', line 19

def item(name)
  index = ELEMENTS.index(name)
  raise ArgumentError, "unknown data item #{name} (#{name.class})" unless index
  raw_data = data(START_INDEX + index)
  case name
  when :dsa, :rsa
    # generate PEM from DER
    return OpenSSL::PKey.const_get(name.to_s.upcase).new(raw_data).to_pem
  when :license
    return Zlib::Inflate.inflate(raw_data)
  when :uuid
    return format('%08x-%04x-%04x-%04x-%04x%08x', *raw_data.unpack('NnnnnN'))
  when :'aspera.global-cli-client', :'aspera.drive'
    return Base64.urlsafe_encode64(raw_data)
  else Aspera.error_unexpected_value(name)
  end
end