Class: Fernet::Generator
- Inherits:
-
Object
- Object
- Fernet::Generator
- Defined in:
- lib/fernet/generator.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#payload ⇒ Object
Returns the value of attribute payload.
Instance Method Summary collapse
- #generate {|_self| ... } ⇒ Object
-
#initialize(secret, encrypt) ⇒ Generator
constructor
A new instance of Generator.
- #inspect ⇒ Object (also: #to_s)
Constructor Details
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
8 9 10 |
# File 'lib/fernet/generator.rb', line 8 def data @data end |
#payload ⇒ Object
Returns the value of attribute payload.
8 9 10 |
# File 'lib/fernet/generator.rb', line 8 def payload @payload end |
Instance Method Details
#generate {|_self| ... } ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/fernet/generator.rb', line 17 def generate yield self if block_given? data.merge!(:issued_at => DateTime.now) if encrypt? iv = encrypt_data! @payload = "#{base64(data)}|#{base64(iv)}" else @payload = base64(Yajl::Encoder.encode(data)) end mac = OpenSSL::HMAC.hexdigest('sha256', payload, signing_key) "#{payload}|#{mac}" end |
#inspect ⇒ Object Also known as: to_s
32 33 34 |
# File 'lib/fernet/generator.rb', line 32 def inspect "#<Fernet::Generator @secret=[masked] @data=#{@data.inspect}>" end |