lib/fernet/generator.rb in fernet-1.0 vs lib/fernet/generator.rb in fernet-1.1
- old
+ new
@@ -1,7 +1,7 @@
require 'base64'
-require 'json'
+require 'yajl'
require 'openssl'
require 'date'
module Fernet
class Generator
@@ -14,17 +14,17 @@
@data = {}
end
def generate
yield self if block_given?
- data.merge!(issued_at: DateTime.now)
+ data.merge!(:issued_at => DateTime.now)
if encrypt?
iv = encrypt_data!
@payload = "#{base64(data)}|#{base64(iv)}"
else
- @payload = base64(JSON.dump(data))
+ @payload = base64(Yajl::Encoder.encode(data))
end
mac = OpenSSL::HMAC.hexdigest('sha256', payload, signing_key)
"#{payload}|#{mac}"
end
@@ -45,10 +45,10 @@
cipher = OpenSSL::Cipher.new('AES-128-CBC')
cipher.encrypt
iv = cipher.random_iv
cipher.iv = iv
cipher.key = encryption_key
- @data = cipher.update(JSON.dump(data)) + cipher.final
+ @data = cipher.update(Yajl::Encoder.encode(data)) + cipher.final
iv
end
def base64(chars)
Base64.urlsafe_encode64(chars)