Skip to content
This repository was archived by the owner on Feb 9, 2024. It is now read-only.
9 changes: 1 addition & 8 deletions hawk.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ func NewRequestAuth(req *http.Request, creds *Credentials, tsOffset time.Duratio
return auth
}

// NewRequestAuth builds a client Auth based on uri and creds. tsOffset will be
// NewURLAuth builds a client Auth based on uri and creds. tsOffset will be
// applied to Now when setting the timestamp.
func NewURLAuth(uri string, creds *Credentials, tsOffset time.Duration) (*Auth, error) {
u, err := url.Parse(uri)
Expand Down Expand Up @@ -677,7 +677,6 @@ func (auth *Auth) UpdateOffset(header string) (time.Duration, error) {
var err error
var ts time.Time
var tsm []byte
var errMsg string

for _, match := range matches {
switch match[1] {
Expand All @@ -692,15 +691,9 @@ func (auth *Auth) UpdateOffset(header string) (time.Duration, error) {
if err != nil {
return 0, AuthFormatError{"tsm", "malformed base64 encoding"}
}
case "error":
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems weird to update offsets when the error key is present.

errMsg = match[2]
}
}

if errMsg != "Stale timestamp" {
return 0, AuthFormatError{"error", "missing or unknown"}
}

if !hmac.Equal(tsm, auth.tsMac(strconv.FormatInt(ts.Unix(), 10))) {
return 0, ErrInvalidMAC
}
Expand Down