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



78
79
80
81
# File 'lib/virgil/sdk/high_level/virgil_card_manager.rb', line 78

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

Instance Attribute Details

#cryptoObject

Returns the value of attribute crypto



76
77
78
# File 'lib/virgil/sdk/high_level/virgil_card_manager.rb', line 76

def crypto
  @crypto
end

Instance Method Details

#encrypt(buffer) ⇒ VirgilBuffer

Encrypts the specified data using recipients Public keys.

Examples:

virgil = VirgilApi.new( access_token: "[YOUR_ACCESS_TOKEN_HERE]")
# search for Cards
bob_cards = virgil.cards.find("bob")

# message for encryption
message = "Hey Bob, how's it going?"

# encrypt the message
ciphertext = bob_cards.encrypt(message).to_base64

Parameters:

Returns:

  • (VirgilBuffer)

    Encrypted data for current recipients Public keys.

Raises:

  • (ArgumentError)

    if buffer doesn't have type VirgilBuffer, String or Array of bytes.



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/virgil/sdk/high_level/virgil_card_manager.rb', line 98

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