Sha256: 8ce38b24f36b5c3644a43d27b5ea60224171d088b090dced893e296d652e5a6e

Contents?: true

Size: 895 Bytes

Versions: 7

Compression:

Stored size: 895 Bytes

Contents

require 'multi_json'
require 'keen/aes_helper'
require 'keen/aes_helper_old'

module Keen
  class ScopedKey

    attr_accessor :api_key
    attr_accessor :data

    class << self
      def decrypt!(api_key, scoped_key)
        if api_key.length == 64
          decrypted = Keen::AESHelper.aes256_decrypt(api_key, scoped_key)
        else
          decrypted = Keen::AESHelperOld.aes256_decrypt(api_key, scoped_key)
        end
        data = MultiJson.load(decrypted)
        self.new(api_key, data)
      end
    end

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

    def encrypt!(iv = nil)
      json_str = MultiJson.dump(self.data)
      if self.api_key.length == 64
        Keen::AESHelper.aes256_encrypt(self.api_key, json_str, iv)
      else
        Keen::AESHelperOld.aes256_encrypt(self.api_key, json_str, iv)
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
keen-1.0.0 lib/keen/scoped_key.rb
keen-0.9.10 lib/keen/scoped_key.rb
keen-0.9.9 lib/keen/scoped_key.rb
keen-0.9.8 lib/keen/scoped_key.rb
keen-0.9.7 lib/keen/scoped_key.rb
keen-0.9.6 lib/keen/scoped_key.rb
keen-0.9.5 lib/keen/scoped_key.rb