Class: SafeNet::KeyHelper
- Inherits:
-
Object
- Object
- SafeNet::KeyHelper
- Defined in:
- lib/safenet.rb
Instance Method Summary collapse
- #decrypt(message_base64) ⇒ Object
- #encrypt(message) ⇒ Object
- #get_token ⇒ Object
- #get_valid_token ⇒ Object
-
#initialize(client_obj) ⇒ KeyHelper
constructor
A new instance of KeyHelper.
- #invalidate ⇒ Object
Constructor Details
#initialize(client_obj) ⇒ KeyHelper
Returns a new instance of KeyHelper.
54 55 56 57 58 |
# File 'lib/safenet.rb', line 54 def initialize(client_obj) @client = client_obj @keys = {} @conf = {} end |
Instance Method Details
#decrypt(message_base64) ⇒ Object
72 73 74 75 |
# File 'lib/safenet.rb', line 72 def decrypt() keys = get_keys() keys["secret_box"].decrypt(keys["symmetric_nonce"], Base64.strict_decode64()) end |
#encrypt(message) ⇒ Object
77 78 79 80 81 |
# File 'lib/safenet.rb', line 77 def encrypt() keys = get_keys() res = keys["secret_box"].encrypt(keys["symmetric_nonce"], ) Base64.strict_encode64(res) end |
#get_token ⇒ Object
60 61 62 63 |
# File 'lib/safenet.rb', line 60 def get_token @conf = File.exists?(@client.app_info[:conf_path]) ? JSON.parse(File.read(@client.app_info[:conf_path])) : (@client.auth.auth() || {}) @conf["token"] end |
#get_valid_token ⇒ Object
65 66 67 68 69 70 |
# File 'lib/safenet.rb', line 65 def get_valid_token @last_conf = File.exists?(@client.app_info[:conf_path]) ? JSON.parse(File.read(@client.app_info[:conf_path])) : {} @client.auth.auth() unless File.exists?(@client.app_info[:conf_path]) && @client.auth.is_token_valid() @conf = JSON.parse(File.read(@client.app_info[:conf_path])) @conf["token"] end |
#invalidate ⇒ Object
83 84 85 |
# File 'lib/safenet.rb', line 83 def invalidate @keys = {} end |