;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; HTTP digest authentication (2617) - ABNF
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;; 1.2 Access Authentication Framework
auth-scheme    = token
auth-param     = token "=" ( token | quoted-string )

challenge   = auth-scheme 1*SP 1#auth-param

realm       = "realm" "=" realm-value
realm-value = quoted-string

;;;; 2 Basic Authentication Scheme
challenge   = "Basic" realm
credentials = "Basic" basic-credentials

basic-credentials = base64-user-pass
base64-user-pass  = token ;<base64 [4] encoding of user-pass, except not limited to 76 char/line>
user-pass   = userid ":" password
userid      = *TEXT ;*<TEXT excluding ":">
password    = *TEXT

;;;; 3.2.1 The WWW-Authenticate Response Header
challenge        =  "Digest" digest-challenge

digest-challenge  = 1#( realm | [ domain ] | nonce | [ opaque ] |[ stale ] | [ algorithm ] | [ qop-options ] | [auth-param] )

domain            = "domain" "=" <"> URI ( 1*SP URI ) <">
URI               = absoluteURI | abs_path
nonce             = "nonce" "=" nonce-value
nonce-value       = quoted-string
opaque            = "opaque" "=" quoted-string
stale             = "stale" "=" ( "true" | "false" )
algorithm         = "algorithm" "=" ( "MD5" | "MD5-sess" | token )
qop-options       = "qop" "=" <"> 1#qop-value <">
qop-value         = "auth" | "auth-int" | token


;;;; 3.2.2 The Authorization Request Header
credentials      = "Digest" digest-response
digest-response  = 1#( username | realm | nonce | digest-url | response | [ algorithm ] | [cnonce] | [opaque] | [message-qop] | [nonce-count]  | [auth-param] )

username         = "username" "=" username-value
username-value   = quoted-string
digest-url       = "url" "=" digest-url-value
digest-url-value = request-url   ; As specified by HTTP/1.1
message-qop      = "qop" "=" qop-value
cnonce           = "cnonce" "=" cnonce-value
cnonce-value     = nonce-value
nonce-count      = "nc" "=" nc-value
nc-value         = 8LHEX
response         = "response" "=" request-digest
request-digest   = DQUOTE 32LHEX DQUOTE
LHEX             = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "a" | "b" | "c" | "d" | "e" | "f"


;;;; 3.2.3 The Authentication-Info Header
AuthenticationInfo = "Authentication-Info" ":" auth-info
auth-info          = 1#(nextnonce | [ message-qop ] | [ response-auth ] | [ cnonce ] | [nonce-count] )
nextnonce          = "nextnonce" "=" nonce-value
response-auth      = "rspauth" "=" response-digest
response-digest    = DQUOTE *LHEX DQUOTE