Class: EverSdk::Crypto::BoxEncryptionAlgorithm

Inherits:
Object
  • Object
show all
Defined in:
lib/ever_sdk_client/crypto.rb

Constant Summary collapse

TYPES =
%i[cha_cha20 nacl_box nacl_secret_box]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, **args) ⇒ BoxEncryptionAlgorithm

Returns a new instance of BoxEncryptionAlgorithm.



282
283
284
285
286
287
288
# File 'lib/ever_sdk_client/crypto.rb', line 282

def initialize(type:, **args)
  unless TYPES.include?(type)
    raise ArgumentError.new("type #{type} is unknown; known types: #{TYPES}")
  end
  @type = type
  @args = args
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



280
281
282
# File 'lib/ever_sdk_client/crypto.rb', line 280

def args
  @args
end

#typeObject (readonly)

Returns the value of attribute type.



280
281
282
# File 'lib/ever_sdk_client/crypto.rb', line 280

def type
  @type
end

Instance Method Details

#to_hObject



290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
# File 'lib/ever_sdk_client/crypto.rb', line 290

def to_h
  hash = case type
         when :cha_cha20
           {
             nonce: args[:nonce]
           }
         when :nacl_box
           {
             their_public: args[:their_public],
             nonce: args[:nonce]
           }
         when :nacl_secret_box
           {
             nonce: args[:nonce]
           }
         end
  {
    type: Helper.sym_to_capitalized_case_str(type)
  }.merge(hash)
end