vendor/bundle/ruby/2.1.0/gems/httpauth-0.2.1/lib/httpauth/digest.rb
def decode_directives(directives, variant)
          fail(HTTPAuth::UnwellformedHeader, "Can't decode directives which are nil") if directives.nil?
          decode = {:domain => :space_quoted_string_to_list, :algorithm => false, :stale => :str_to_bool, :nc => :hex_to_int}
          if [:credentials, :auth].include? variant
            decode.merge! :qop => false
          elsif variant == :challenge
            decode.merge! :qop => :comma_quoted_string_to_list
          else
            fail(ArgumentError, "#{variant} is not a valid value for `variant' use :auth, :credentials or :challenge")
          end

          start = 0
          unless variant == :auth
            # The first six characters are 'Digest '
            start = 6
            scheme = directives[0..6].strip
            fail(HTTPAuth::UnwellformedHeader, "Scheme should be Digest, server responded with `#{directives}'") unless scheme == 'Digest'
          end

          # The rest are the directives
          # TODO: split is ugly, I want a real parser (:
          directives[start..-1].split(',').inject({}) do |h, part|
            parts = part.split('=')
            name = parts[0].strip.intern
            value = parts[1..-1].join('=').strip

            # --- HACK
            # IE and Safari qoute qop values
            # IE also quotes algorithm values
            if variant != :challenge && [:qop, :algorithm].include?(name) && value =~ /^\"[^\"]+\"$/
              value = Conversions.unquote_string(value)
            end
            # --- END HACK

            if decode[name]
              h[name] = Conversions.send decode[name], value
            elsif decode[name].nil?
              h[name] = Conversions.unquote_string value
            else
              h[name] = value
            end
            h
          end
        end
# Decodes digest directives from a header. Returns a hash with directives.
#
# * <tt>directives</tt>: The directives
# * <tt>variant</tt>: Specifies whether the directives are for an Authorize header (:credentials),
#   for a WWW-Authenticate header (:challenge) or for a Authentication-Info header (:auth_info).
Decodes digest directives from a header. Returns a hash with directives.
Decodes digest directives from a header . Returns a hash with directives .
def decode_directives(directives, variant)
          fail(HTTPAuth::UnwellformedHeader, "Can't decode directives which are nil") if directives.nil?
          decode = {:domain => :space_quoted_string_to_list, :algorithm => false, :stale => :str_to_bool, :nc => :hex_to_int}
          if [:credentials, :auth].include? variant
            decode.merge! :qop => false
          elsif variant == :challenge
            decode.merge! :qop => :comma_quoted_string_to_list
          else
            fail(ArgumentError, "#{variant} is not a valid value for `variant' use :auth, :credentials or :challenge")
          end
          start = 0
          unless variant == :auth
            start = 6
            scheme = directives[0..6].strip
            fail(HTTPAuth::UnwellformedHeader, "Scheme should be Digest, server responded with `#{directives}'") unless scheme == 'Digest'
          end
          directives[start..-1].split(',').inject({}) do |h, part|
            parts = part.split('=')
            name = parts[0].strip.intern
            value = parts[1..-1].join('=').strip
            if variant != :challenge && [:qop, :algorithm].include?(name) && value =~ /^\"[^\"]+\"$/
              value = Conversions.unquote_string(value)
            end
            if decode[name]
              h[name] = Conversions.send decode[name], value
            elsif decode[name].nil?
              h[name] = Conversions.unquote_string value
            else
              h[name] = value
            end
            h
          end
        end
def decode_directives ( directives , variant ) fail ( HTTPAuth :: UnwellformedHeader , "Can't decode directives which are nil" ) if directives . nil? decode = { :domain => :space_quoted_string_to_list , :algorithm => false , :stale => :str_to_bool , :nc => :hex_to_int } if [ :credentials , :auth ] . include? variant decode . merge! :qop => false elsif variant == :challenge decode . merge! :qop => :comma_quoted_string_to_list else fail ( ArgumentError , "#{variant} is not a valid value for `variant' use :auth, :credentials or :challenge" ) end start = 0 unless variant == :auth start = 6 scheme = directives [ 0 .. 6 ] . strip fail ( HTTPAuth :: UnwellformedHeader , "Scheme should be Digest, server responded with `#{directives}'" ) unless scheme == 'Digest' end directives [ start .. - 1 ] . split ( ',' ) . inject ( { } ) do | h , part | parts = part . split ( '=' ) name = parts [ 0 ] . strip . intern value = parts [ 1 .. - 1 ] . join ( '=' ) . strip if variant != :challenge && [ :qop , :algorithm ] . include? ( name ) && value =~ / ^ \" [^ \" ]+ \" $ / value = Conversions . unquote_string ( value ) end if decode [ name ] h [ name ] = Conversions . send decode [ name ] , value elsif decode [ name ] . nil? h [ name ] = Conversions . unquote_string value else h [ name ] = value end h end end
Decodes digest directives from a header.
Decodes digest directives from a header .
# The first six characters are 'Digest ' # The rest are the directives # TODO: split is ugly, I want a real parser (: # --- HACK # IE and Safari qoute qop values # IE also quotes algorithm values # --- END HACK
directives
variant