Class: Smaak::Associate
- Inherits:
-
Object
- Object
- Smaak::Associate
- Defined in:
- lib/smaak/associate.rb
Instance Attribute Summary collapse
-
#association_store ⇒ Object
readonly
Returns the value of attribute association_store.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#token_life ⇒ Object
readonly
Returns the value of attribute token_life.
Instance Method Summary collapse
- #add_association(identifier, key, psk, encrypt = false) ⇒ Object
-
#initialize ⇒ Associate
constructor
A new instance of Associate.
- #set_key(key) ⇒ Object
- #set_token_life(token_life) ⇒ Object
Constructor Details
#initialize ⇒ Associate
Returns a new instance of Associate.
9 10 11 12 |
# 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 |
Instance Attribute Details
#association_store ⇒ Object (readonly)
Returns the value of attribute association_store.
5 6 7 |
# File 'lib/smaak/associate.rb', line 5 def association_store @association_store end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
7 8 9 |
# File 'lib/smaak/associate.rb', line 7 def key @key end |
#token_life ⇒ Object (readonly)
Returns the value of attribute token_life.
6 7 8 |
# File 'lib/smaak/associate.rb', line 6 def token_life @token_life end |
Instance Method Details
#add_association(identifier, key, psk, encrypt = false) ⇒ Object
26 27 28 29 30 31 32 33 |
# 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) ⇒ Object
14 15 16 17 18 19 |
# 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) ⇒ Object
21 22 23 24 |
# 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 |