class Smaak::Associate
Attributes
association_store[R]
key[R]
token_life[R]
Public Class Methods
new()
click to toggle source
# File lib/smaak/associate.rb, line 9 def initialize @association_store = Persistent::Cache.new("association_store", nil, Persistent::Cache::STORAGE_RAM) @token_life = Smaak::DEFAULT_TOKEN_LIFE end
Public Instance Methods
add_association(identifier, key, psk, encrypt = false)
click to toggle source
# File lib/smaak/associate.rb, line 26 def add_association(identifier, key, psk, encrypt = false) the_key = key.is_a?(String) ? OpenSSL::PKey::RSA.new(key) : key raise ArgumentError.new("Key needs to be valid") unless validate_key(the_key) @association_store[identifier] = { 'public_key' => the_key, 'psk' => psk, 'encrypt' => encrypt } rescue OpenSSL::PKey::RSAError raise ArgumentError.new("Key needs to be valid") end
set_key(key)
click to toggle source
# File lib/smaak/associate.rb, line 14 def set_key(key) @key = adapt_rsa_key(key) rescue OpenSSL::PKey::RSAError raise ArgumentError.new("Key needs to be valid") end
set_token_life(token_life)
click to toggle source
# File lib/smaak/associate.rb, line 21 def set_token_life(token_life) raise ArgumentError.new("Token life has to be a positive number of seconds") unless validate_token_life(token_life) @token_life = token_life end
Protected Instance Methods
adapt_rsa_key(key)
click to toggle source
# File lib/smaak/associate.rb, line 37 def adapt_rsa_key(key) the_key = key.is_a?(String) ? OpenSSL::PKey::RSA.new(key) : key raise ArgumentError.new("Key needs to be valid") unless validate_key(the_key) the_key end
Private Instance Methods
validate_key(key)
click to toggle source
# File lib/smaak/associate.rb, line 45 def validate_key(key) return false if key.nil? return false if key.is_a? String and key.empty? return false unless key.is_a? OpenSSL::PKey::RSA true end
validate_token_life(token_life)
click to toggle source
# File lib/smaak/associate.rb, line 52 def validate_token_life(token_life) return false if token_life.nil? return false unless token_life.is_a? Integer return false unless token_life > 0 true end