Class: Refcode::Encoder
- Inherits:
-
Object
- Object
- Refcode::Encoder
- Defined in:
- lib/refcode.rb
Instance Attribute Summary collapse
-
#salt ⇒ Object
Returns the value of attribute salt.
-
#secret ⇒ Object
Returns the value of attribute secret.
Instance Method Summary collapse
- #decode(val) ⇒ Object
- #decrypt(val) ⇒ Object
- #encode(val) ⇒ Object
- #encrypt(val) ⇒ Object
-
#initialize {|_self| ... } ⇒ Encoder
constructor
A new instance of Encoder.
Constructor Details
#initialize {|_self| ... } ⇒ Encoder
Returns a new instance of Encoder.
13 14 15 |
# File 'lib/refcode.rb', line 13 def initialize yield self if block_given? end |
Instance Attribute Details
#salt ⇒ Object
Returns the value of attribute salt.
11 12 13 |
# File 'lib/refcode.rb', line 11 def salt @salt end |
#secret ⇒ Object
Returns the value of attribute secret.
11 12 13 |
# File 'lib/refcode.rb', line 11 def secret @secret end |
Instance Method Details
#decode(val) ⇒ Object
21 22 23 |
# File 'lib/refcode.rb', line 21 def decode val YAML.load(decrypt(Base64URL.decode(val))) end |
#decrypt(val) ⇒ Object
29 30 31 |
# File 'lib/refcode.rb', line 29 def decrypt val Encryptor.decrypt(:value => val, :key => @secret, :salt => @salt, :iv => iv) end |
#encode(val) ⇒ Object
17 18 19 |
# File 'lib/refcode.rb', line 17 def encode val Base64URL.encode(encrypt(YAML.dump(val))) end |
#encrypt(val) ⇒ Object
25 26 27 |
# File 'lib/refcode.rb', line 25 def encrypt val Encryptor.encrypt(:value => val, :key => @secret, :salt => @salt, :iv => iv) end |