lib/httpx/plugins/authentication/digest.rb in httpx-0.24.3 vs lib/httpx/plugins/authentication/digest.rb in httpx-0.24.4

- old
+ new

@@ -8,14 +8,15 @@ module Plugins module Authentication class Digest using RegexpExtensions unless Regexp.method_defined?(:match?) - def initialize(user, password, **) + def initialize(user, password, hashed: false, **) @user = user @password = password @nonce = 0 + @hashed = hashed end def can_authenticate?(authenticate) authenticate && /Digest .*/.match?(authenticate) end @@ -53,14 +54,16 @@ cnonce = make_cnonce nc = format("%<nonce>08x", nonce: nc) end a1 = if sess - [algorithm.hexdigest("#{@user}:#{params["realm"]}:#{@password}"), - nonce, - cnonce].join ":" + [ + (@hashed ? @password : algorithm.hexdigest("#{@user}:#{params["realm"]}:#{@password}")), + nonce, + cnonce, + ].join ":" else - "#{@user}:#{params["realm"]}:#{@password}" + @hashed ? @password : "#{@user}:#{params["realm"]}:#{@password}" end ha1 = algorithm.hexdigest(a1) ha2 = algorithm.hexdigest("#{meth}:#{uri}") request_digest = [ha1, nonce]