Skip to content

Commit

Permalink
discard error on hash.Write
Browse files Browse the repository at this point in the history
  • Loading branch information
cenkalti committed Mar 19, 2019
1 parent 58d8be0 commit 9a9a606
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions internal/analytics/analytics.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (p *Analytics) InsertEvents(events []event.Event) (n int, err error) {
e.IsAnonymous = true
} else {
hash.Reset()
hash.Write([]byte(e.UserID))
_, _ = hash.Write([]byte(e.UserID))
if hex.EncodeToString(hash.Sum(nil)) != *e.UserHash {
err = errors.New("invalid user hash: " + *e.UserHash)
return
Expand All @@ -64,7 +64,7 @@ func (p *Analytics) UpdateUsers(users []user.User) (n int, err error) {
now := time.Now().UTC()
for _, u := range users {
hash.Reset()
hash.Write([]byte(u.ID))
_, _ = hash.Write([]byte(u.ID))
if hex.EncodeToString(hash.Sum(nil)) != u.Hash {
err = errors.New("invalid hash: " + u.Hash)
return
Expand Down Expand Up @@ -98,7 +98,7 @@ func (p *Analytics) Health() error {

func (p *Analytics) Alias(previousID, userID user.ID, userHash string) error {
hash := hmac.New(sha256.New, p.secret)
hash.Write([]byte(userID))
_, _ = hash.Write([]byte(userID))
if hex.EncodeToString(hash.Sum(nil)) != userHash {
return errors.New("invalid hash: " + userHash)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/analytics/analytics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,6 @@ func TestAlias(t *testing.T) {

func generateUserHash(userID, secret string) string {
hash := hmac.New(sha256.New, []byte(secret))
hash.Write([]byte(userID))
_, _ = hash.Write([]byte(userID))
return hex.EncodeToString(hash.Sum(nil))
}

0 comments on commit 9a9a606

Please sign in to comment.