Class: Refcode::Encoder

Inherits:
Object
  • Object
show all
Defined in:
lib/refcode.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ Encoder

Returns a new instance of Encoder.

Yields:

  • (_self)

Yield Parameters:



13
14
15
# File 'lib/refcode.rb', line 13

def initialize
  yield self if block_given?
end

Instance Attribute Details

#saltObject

Returns the value of attribute salt.



11
12
13
# File 'lib/refcode.rb', line 11

def salt
  @salt
end

#secretObject

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