class Virgil::SDK::HighLevel::VirgilCardManager::CardArray

Attributes

crypto[RW]

Public Class Methods

new(array) click to toggle source
Calls superclass method
# File lib/virgil/sdk/high_level/virgil_card_manager.rb, line 66
def initialize(array)
  @crypto = Cryptography::VirgilCrypto.new
  super
end

Public Instance Methods

encrypt(buffer) click to toggle source

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
# 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