Class: Virgil::SDK::HighLevel::VirgilCard
- Inherits:
-
Object
- Object
- Virgil::SDK::HighLevel::VirgilCard
- Defined in:
- lib/virgil/sdk/high_level/virgil_card.rb
Overview
A Virgil Card is the main entity of the Virgil Security services, it includes an information about the user and his public key. The Virgil Card identifies the user by one of his available types, such as an email, a phone number, etc.
Defined Under Namespace
Classes: AppCredentialsException
Instance Method Summary collapse
-
#check_identity(identity_options = nil) ⇒ Object
Initiates an identity verification process for current Card indentity type.
- #data ⇒ Object
- #device ⇒ Object
- #device_name ⇒ Object
-
#encrypt(buffer) ⇒ Object
Encrypts the specified data for current Virgil card recipient.
-
#export ⇒ Object
Exports card’s snapshot.
- #id ⇒ Object
- #identity ⇒ Object
- #identity_type ⇒ Object
-
#initialize(context:, card:) ⇒ VirgilCard
constructor
A new instance of VirgilCard.
- #public_key ⇒ Object
-
#publish ⇒ Object
Publish synchronously the card into application Virgil Services scope Raises: Virgil::SDK::Client::HTTP::BaseConnection::ApiError if access_token is invalid or Virgil Card with the same fingerprint already exists in Virgil Security services AppCredentialsException: For this operation we need app_id and app_key if application credentials is missing.
-
#publish_as_global(validation_token) ⇒ Object
Publish synchronously the global card into application Virgil Services scope Raises: Virgil Card with the same fingerprint already exists in Virgil Security services.
- #scope ⇒ Object
-
#verify(buffer, signature) ⇒ Object
Verifies the specified buffer and signature with current VirgilCard recipient.
Constructor Details
#initialize(context:, card:) ⇒ VirgilCard
Returns a new instance of VirgilCard.
44 45 46 47 |
# File 'lib/virgil/sdk/high_level/virgil_card.rb', line 44 def initialize(context:, card:) @context = context @card = card end |
Instance Method Details
#check_identity(identity_options = nil) ⇒ Object
Initiates an identity verification process for current Card indentity type. It is only working for
Global identity types like Email.
Args:
identity_options: The data to be encrypted.
Returns:
An instance of VirgilIdentity::VerificationAttempt that contains
information about operation etc
175 176 177 178 179 180 |
# File 'lib/virgil/sdk/high_level/virgil_card.rb', line 175 def check_identity( = nil) action_id = context.client.verify_identity(identity, identity_type) VirgilIdentity::VerificationAttempt.new(context: context, action_id: action_id, identity: identity, identity_type: identity_type, additional_options: ) end |
#data ⇒ Object
74 75 76 |
# File 'lib/virgil/sdk/high_level/virgil_card.rb', line 74 def data card.data end |
#device ⇒ Object
88 89 90 |
# File 'lib/virgil/sdk/high_level/virgil_card.rb', line 88 def device card.device end |
#device_name ⇒ Object
93 94 95 |
# File 'lib/virgil/sdk/high_level/virgil_card.rb', line 93 def device_name card.device_name end |
#encrypt(buffer) ⇒ Object
Encrypts the specified data for current Virgil card recipient
Args:
buffer: The data to be encrypted. It can be VirgilBuffer, utf8-String or Array of bytes
Returns:
Encrypted data for current Virgil card recipient
Raises:
ArgumentError: Buffer has unsupported type if buffer doesn't have type VirgilBuffer, String or Array of bytes
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/virgil/sdk/high_level/virgil_card.rb', line 148 def encrypt(buffer) 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(context.crypto.encrypt(buffer_to_encrypt.bytes, public_key)) end |
#export ⇒ Object
Exports card’s snapshot.
Returns:
base64-encoded json representation of card's content_snapshot and meta.
102 103 104 |
# File 'lib/virgil/sdk/high_level/virgil_card.rb', line 102 def export card.export end |
#id ⇒ Object
59 60 61 |
# File 'lib/virgil/sdk/high_level/virgil_card.rb', line 59 def id card.id end |
#identity ⇒ Object
64 65 66 |
# File 'lib/virgil/sdk/high_level/virgil_card.rb', line 64 def identity card.identity end |
#identity_type ⇒ Object
69 70 71 |
# File 'lib/virgil/sdk/high_level/virgil_card.rb', line 69 def identity_type card.identity_type end |
#public_key ⇒ Object
83 84 85 |
# File 'lib/virgil/sdk/high_level/virgil_card.rb', line 83 def public_key context.crypto.import_public_key(card.public_key) end |
#publish ⇒ Object
Publish synchronously the card into application Virgil Services scope Raises: Virgil::SDK::Client::HTTP::BaseConnection::ApiError if access_token is invalid or
Virgil Card with the same fingerprint already exists in Virgil Security services
AppCredentialsException: For this operation we need app_id and app_key
if application credentials is missing
113 114 115 116 117 118 119 120 121 122 |
# File 'lib/virgil/sdk/high_level/virgil_card.rb', line 113 def publish raise NotImplementedError.new("Current card isn't local!") unless @card.scope == Client::Card::APPLICATION validate_app_credentials @card = context.client.sign_and_publish_card( card, context.credentials.app_id, context.credentials.app_key(context.crypto)) end |
#publish_as_global(validation_token) ⇒ Object
Publish synchronously the global card into application Virgil Services scope Raises: Virgil Card with the same fingerprint already exists in Virgil Security services
128 129 130 131 132 133 134 135 |
# File 'lib/virgil/sdk/high_level/virgil_card.rb', line 128 def publish_as_global(validation_token) raise NotImplementedError.new("Current card isn't global!") unless @card.scope == Client::Card::GLOBAL @card.validation_token = validation_token @card = context.client.publish_as_global_card(card) @card.validation_token = validation_token end |
#scope ⇒ Object
79 80 81 |
# File 'lib/virgil/sdk/high_level/virgil_card.rb', line 79 def scope card.scope end |
#verify(buffer, signature) ⇒ Object
Verifies the specified buffer and signature with current VirgilCard recipient
Args:
buffer: The data to be verified. It can be VirgilBuffer, utf8-encoded String or Array of bytes
signature: The signature used to verify the data integrity. It can be VirgilBuffer, base64-encoded String or Array of bytes
Returns:
true if signature is valid, false otherwise.
Raises:
ArgumentError: Buffer has unsupported type if buffer doesn't have type VirgilBuffer, Array of bytes or utf8-encoded String
ArgumentError: Signature has unsupported type if signature doesn't have type VirgilBuffer, base64-encoded String or Array of bytes
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/virgil/sdk/high_level/virgil_card.rb', line 195 def verify(buffer, signature) buffer_to_verify = 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 signature_to_verify = case signature.class.name.split("::").last when 'VirgilBuffer' signature when 'String' VirgilBuffer.from_base64(signature) when 'Array' VirgilBuffer.from_bytes(signature) else raise ArgumentError.new("Signature has unsupported type") end context.crypto.verify(buffer_to_verify.bytes, signature_to_verify.bytes, public_key) end |