lib/fernet/token.rb in fernet-2.0.rc2 vs lib/fernet/token.rb in fernet-2.0

- old
+ new

@@ -16,14 +16,15 @@ # Internal: initializes a Token object # # token - the string representation of this token # opts - a has containing - # secret: the secret, optionally base 64 encoded (required) - # enforce_ttl: whether to enforce TTL upon validation. Defaults to value - # set in Configuration.enforce_ttl - # ttl: number of seconds token is valid, defaults to Configuration.ttl + # * secret - the secret, optionally base 64 encoded (required) + # * enforce_ttl - whether to enforce TTL upon validation. Defaults to + # value set in Configuration.enforce_ttl + # * ttl - number of seconds token is valid, defaults to + # Configuration.ttl def initialize(token, opts = {}) @token = token @secret = Secret.new(opts.fetch(:secret)) @enforce_ttl = opts.fetch(:enforce_ttl) { Configuration.enforce_ttl } @ttl = opts[:ttl] || Configuration.ttl @@ -63,19 +64,21 @@ end # Internal: generates a Fernet Token # # opts - a hash containing - # secret: a string containing the secret, optionally base64 encoded - # message: the message in plain text + # * secret - a string containing the secret, optionally base64 encoded + # * message - the message in plain text def self.generate(opts) unless opts[:secret] raise ArgumentError, 'Secret not provided' end secret = Secret.new(opts.fetch(:secret)) - encrypted_message, iv = Encryption.encrypt(key: secret.encryption_key, - message: opts[:message], - iv: opts[:iv]) + encrypted_message, iv = Encryption.encrypt( + key: secret.encryption_key, + message: opts[:message], + iv: opts[:iv] + ) issued_timestamp = (opts[:now] || Time.now).to_i payload = [DEFAULT_VERSION].pack("C") + BitPacking.pack_int64_bigendian(issued_timestamp) + iv +