Class: SafeNet::KeyHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/safenet.rb

Instance Method Summary collapse

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(message_base64)
  keys = get_keys()
  keys["secret_box"].decrypt(keys["symmetric_nonce"], Base64.strict_decode64(message_base64))
end

#encrypt(message) ⇒ Object



77
78
79
80
81
# File 'lib/safenet.rb', line 77

def encrypt(message)
  keys = get_keys()
  res = keys["secret_box"].encrypt(keys["symmetric_nonce"], message)
  Base64.strict_encode64(res)
end

#get_tokenObject



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_tokenObject



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

#invalidateObject



83
84
85
# File 'lib/safenet.rb', line 83

def invalidate
  @keys = {}
end