Class: Keen::ScopedKey

Inherits:
Object
  • Object
show all
Extended by:
AESHelper
Includes:
AESHelper
Defined in:
lib/keen/scoped_key.rb

Constant Summary

Constants included from AESHelper

AESHelper::BLOCK_SIZE

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from AESHelper

aes256_decrypt, aes256_encrypt, hexlify, pad, unhexlify

Constructor Details

#initialize(api_key, data) ⇒ ScopedKey

Returns a new instance of ScopedKey.



22
23
24
25
# File 'lib/keen/scoped_key.rb', line 22

def initialize(api_key, data)
  self.api_key = api_key
  self.data = data
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



9
10
11
# File 'lib/keen/scoped_key.rb', line 9

def api_key
  @api_key
end

#dataObject

Returns the value of attribute data.



10
11
12
# File 'lib/keen/scoped_key.rb', line 10

def data
  @data
end

Class Method Details

.decrypt!(api_key, scoped_key) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/keen/scoped_key.rb', line 13

def decrypt!(api_key, scoped_key)
  encrypted = unhexlify(scoped_key)
  padded_api_key = pad(api_key)
  decrypted = aes256_decrypt(padded_api_key, encrypted)
  data = MultiJson.load(decrypted)
  self.new(api_key, data)
end

Instance Method Details

#encrypt!Object



27
28
29
30
31
32
33
# File 'lib/keen/scoped_key.rb', line 27

def encrypt!
  json_str = MultiJson.dump(self.data)
  padded_api_key = pad(self.api_key)
  padded_data = pad(json_str)
  encrypted, iv = aes256_encrypt(padded_api_key, json_str)
  hexlify(iv) + hexlify(encrypted)
end