Class: Virgil::SDK::HighLevel::VirgilCardManager::CardArray

Inherits:
Array
  • Object
show all
Defined in:
lib/virgil/sdk/high_level/virgil_card_manager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(array) ⇒ CardArray

Returns a new instance of CardArray.



66
67
68
69
# File 'lib/virgil/sdk/high_level/virgil_card_manager.rb', line 66

def initialize(array)
  @crypto = Cryptography::VirgilCrypto.new
  super
end

Instance Attribute Details

#cryptoObject

Returns the value of attribute crypto.



64
65
66
# File 'lib/virgil/sdk/high_level/virgil_card_manager.rb', line 64

def crypto
  @crypto
end

Instance Method Details

#encrypt(buffer) ⇒ Object

Encrypts the specified data using recipients Public keys.

Args:

buffer: The data to be encrypted. It can be VirgilBuffer, utf8 String or Array of bytes

Returns:

Encrypted data for current recipients Public keys

Raises:

ArgumentError: Buffer has unsupported type if buffer doesn't have type VirgilBuffer, String or Array of bytes


81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/virgil/sdk/high_level/virgil_card_manager.rb', line 81

def encrypt(buffer)
  all_public_keys = self.map(&:public_key)
  buffer_to_encrypt = case buffer.class.name.split("::").last
                        when 'VirgilBuffer'
                          buffer
                        when 'String'
                          VirgilBuffer.from_string(buffer)
                        when 'Array'
                          VirgilBuffer.from_bytes(buffer)
                        else
                          raise ArgumentError.new("Buffer has unsupported type")
                      end

  VirgilBuffer.new(crypto.encrypt(buffer_to_encrypt.bytes, *all_public_keys))
end