lib/fernet/generator.rb in fernet-0.0.2 vs lib/fernet/generator.rb in fernet-0.1
- old
+ new
@@ -10,20 +10,24 @@
def initialize(secret)
@secret = secret
end
def generate
- yield self
+ yield self if block_given?
data.merge!(issued_at: DateTime.now)
mac = OpenSSL::HMAC.hexdigest('sha256', JSON.dump(data), secret)
Base64.urlsafe_encode64(JSON.dump(data.merge(signature: mac)))
end
def inspect
"#<Fernet::Generator @secret=[masked] @data=#{@data.inspect}>"
end
alias to_s inspect
+
+ def data
+ @data ||= {}
+ end
private
attr_reader :secret
end
end