Class: Virgil::SDK::HighLevel::VirgilKeyManager
- Inherits:
-
Object
- Object
- Virgil::SDK::HighLevel::VirgilKeyManager
- Defined in:
- lib/virgil/sdk/high_level/virgil_key_manager.rb
Overview
this class provides a list of methods to generate the VirgilKey and further them storage in secure place.
Instance Attribute Summary collapse
-
#context ⇒ VirgilContext
readonly
manages the VirgilApi dependencies during run time.
Instance Method Summary collapse
-
#delete(key_name) ⇒ Object
Remove the VirgilKey from current storage by specified key name.
-
#generate ⇒ VirgilKey
Generates a new VirgilKey with default parameters.
-
#import(buffer, password = nil) ⇒ VirgilKey
Imports the VirgilKey from buffer.
-
#initialize(context) ⇒ VirgilKeyManager
constructor
Initializes a new instance of the VirgilKeyManager class.
-
#load(key_name, key_password = nil) ⇒ VirgilKey
Loads the VirgilKey from current storage by specified key name.
Constructor Details
#initialize(context) ⇒ VirgilKeyManager
Initializes a new instance of the Virgil::SDK::HighLevel::VirgilKeyManager class.
46 47 48 |
# File 'lib/virgil/sdk/high_level/virgil_key_manager.rb', line 46 def initialize(context) @context = context end |
Instance Attribute Details
#context ⇒ VirgilContext (readonly)
manages the VirgilApi dependencies during run time.
43 44 45 |
# File 'lib/virgil/sdk/high_level/virgil_key_manager.rb', line 43 def context @context end |
Instance Method Details
#delete(key_name) ⇒ Object
Remove the Virgil::SDK::HighLevel::VirgilKey from current storage by specified key name.
123 124 125 126 127 128 |
# File 'lib/virgil/sdk/high_level/virgil_key_manager.rb', line 123 def delete(key_name) raise ArgumentError.new("key_name is not valid") if key_name.nil? context.key_storage.delete(key_name) end |
#generate ⇒ VirgilKey
Generates a new Virgil::SDK::HighLevel::VirgilKey with default parameters.
70 71 72 73 |
# File 'lib/virgil/sdk/high_level/virgil_key_manager.rb', line 70 def generate key_pair = context.crypto.generate_keys() VirgilKey.new(context, key_pair.private_key) end |
#import(buffer, password = nil) ⇒ VirgilKey
Imports the Virgil::SDK::HighLevel::VirgilKey from buffer.
109 110 111 112 |
# File 'lib/virgil/sdk/high_level/virgil_key_manager.rb', line 109 def import(buffer, password=nil) private_key = context.crypto.import_private_key(buffer.bytes, password) VirgilKey.new(context, private_key) end |
#load(key_name, key_password = nil) ⇒ VirgilKey
Loads the VirgilKey from current storage by specified key name.
87 88 89 90 91 92 93 94 95 |
# File 'lib/virgil/sdk/high_level/virgil_key_manager.rb', line 87 def load(key_name, key_password=nil) raise ArgumentError.new("key_name is not valid") if key_name.nil? storage_item = context.key_storage.load(key_name) private_key = context.crypto.import_private_key(storage_item.data, key_password) VirgilKey.new(context, private_key) end |