@@ -27,11 +27,13 @@ type Options struct {
27
27
URI string
28
28
GetBody func () (io.ReadCloser , error )
29
29
Count int
30
- A1 string
31
30
Username string
32
31
Password string
33
32
34
- // used for testing
33
+ // The following are provided for advanced use cases where the client needs
34
+ // to override the default digest calculation behavior. Most users should
35
+ // leave these fields unset.
36
+ A1 string
35
37
Cnonce string
36
38
}
37
39
@@ -77,18 +79,16 @@ func Digest(chal *Challenge, o Options) (*Credentials, error) {
77
79
if cred .Userhash {
78
80
cred .Username = hashf (h , "%s:%s" , o .Username , cred .Realm )
79
81
}
80
-
82
+ // generate the a1 hash if one was not provided
81
83
a1 := o .A1
82
-
83
84
if a1 == "" {
84
85
a1 = hashf (h , "%s:%s:%s" , o .Username , cred .Realm , o .Password )
85
86
}
86
-
87
87
// generate the response
88
88
switch {
89
89
case len (chal .QOP ) == 0 :
90
90
cred .Response = hashf (h , "%s:%s:%s" ,
91
- a1 , // A1
91
+ a1 ,
92
92
cred .Nonce ,
93
93
hashf (h , "%s:%s" , o .Method , o .URI ), // A2
94
94
)
@@ -101,7 +101,7 @@ func Digest(chal *Challenge, o Options) (*Credentials, error) {
101
101
cred .Nc = 1
102
102
}
103
103
cred .Response = hashf (h , "%s:%s:%08x:%s:%s:%s" ,
104
- a1 , // A1
104
+ a1 ,
105
105
cred .Nonce ,
106
106
cred .Nc ,
107
107
cred .Cnonce ,
@@ -121,7 +121,7 @@ func Digest(chal *Challenge, o Options) (*Credentials, error) {
121
121
return nil , fmt .Errorf ("digest: failed to read body for auth-int: %w" , err )
122
122
}
123
123
cred .Response = hashf (h , "%s:%s:%08x:%s:%s:%s" ,
124
- a1 , // A1
124
+ a1 ,
125
125
cred .Nonce ,
126
126
cred .Nc ,
127
127
cred .Cnonce ,
0 commit comments