lib/rack/auth/digest/nonce.rb in rack-2.0.9.4 vs lib/rack/auth/digest/nonce.rb in rack-2.1.0

- old
+ new

@@ -1,6 +1,9 @@ +# frozen_string_literal: true + require 'digest/md5' +require 'base64' module Rack module Auth module Digest # Rack::Auth::Digest::Nonce is the default nonce generator for the @@ -16,22 +19,22 @@ class << self attr_accessor :private_key, :time_limit end def self.parse(string) - new(*string.unpack("m*").first.split(' ', 2)) + new(*Base64.decode64(string).split(' ', 2)) end def initialize(timestamp = Time.now, given_digest = nil) @timestamp, @given_digest = timestamp.to_i, given_digest end def to_s - [([ @timestamp, digest ] * ' ')].pack("m*").strip + Base64.encode64("#{@timestamp} #{digest}").strip end def digest - ::Digest::MD5.hexdigest([ @timestamp, self.class.private_key ] * ':') + ::Digest::MD5.hexdigest("#{@timestamp}:#{self.class.private_key}") end def valid? digest == @given_digest end