Permalink
Browse files

gofix

  • Loading branch information...
1 parent 80de377 commit 2e479d42d6729ef9783f607efc5dedaff4c137a6 @bpowers committed Dec 7, 2011
Showing with 12 additions and 12 deletions.
  1. +7 −7 seshcookie.go
  2. +5 −5 seshcookie_test.go
View
@@ -175,7 +175,7 @@ func encode(block cipher.Block, hmac hash.Hash, data []byte) ([]byte, error) {
buf.Write(iv)
hmac.Write(buf.Bytes())
- buf.Write(hmac.Sum())
+ buf.Write(hmac.Sum(nil))
return buf.Bytes(), nil
}
@@ -201,7 +201,7 @@ func encodeCookie(content interface{}, encKey, hmacKey []byte) (string, []byte,
return "", nil, err
}
- return base64.StdEncoding.EncodeToString(sessionBytes), gobHash.Sum(), nil
+ return base64.StdEncoding.EncodeToString(sessionBytes), gobHash.Sum(nil), nil
}
// decode uses the given block cipher (in CTR mode) to decrypt the
@@ -216,7 +216,7 @@ func decode(block cipher.Block, hmac hash.Hash, ciphertext []byte) ([]byte, erro
ciphertext = ciphertext[:len(ciphertext)-hmac.Size()]
hmac.Write(ciphertext)
- if subtle.ConstantTimeCompare(hmac.Sum(), receivedHmac) != 1 {
+ if subtle.ConstantTimeCompare(hmac.Sum(nil), receivedHmac) != 1 {
return nil, HashError
}
@@ -257,7 +257,7 @@ func decodeCookie(encoded string, encKey, hmacKey []byte) (map[string]interface{
log.Printf("decodeGob: %s\n", err)
return nil, nil, err
}
- return session, gobHash.Sum(), nil
+ return session, gobHash.Sum(nil), nil
}
func (s sessionResponseWriter) WriteHeader(code int) {
@@ -284,7 +284,7 @@ func (s sessionResponseWriter) WriteHeader(code int) {
cookie.Path = "/"
// a cookie is expired by setting it
// with an expiration time in the past
- cookie.Expires = *time.SecondsToUTC(0)
+ cookie.Expires = time.Unix(0, 0).UTC()
http.SetCookie(s, &cookie)
}
goto write
@@ -366,7 +366,7 @@ func NewSessionHandler(handler http.Handler, key string, rs *RequestSessions) *S
CookieName: "session",
CookiePath: "/",
RS: rs,
- encKey: encHash.Sum()[:blockSize],
- hmacKey: hmacHash.Sum()[:blockSize],
+ encKey: encHash.Sum(nil)[:blockSize],
+ hmacKey: hmacHash.Sum(nil)[:blockSize],
}
}
View
@@ -5,21 +5,21 @@ package seshcookie
import (
"bytes"
- "time"
"crypto/sha1"
"testing"
+ "time"
)
func createKey() (encKey, hmacKey []byte) {
encSha1 := sha1.New()
- encSha1.Write([]byte(time.UTC().String()))
+ encSha1.Write([]byte(time.Now().UTC().String()))
encSha1.Write([]byte("-enc"))
- encKey = encSha1.Sum()[:blockSize]
+ encKey = encSha1.Sum(nil)[:blockSize]
hmacSha1 := sha1.New()
- hmacSha1.Write([]byte(time.UTC().String()))
+ hmacSha1.Write([]byte(time.Now().UTC().String()))
hmacSha1.Write([]byte("-hmac"))
- hmacKey = hmacSha1.Sum()[:blockSize]
+ hmacKey = hmacSha1.Sum(nil)[:blockSize]
return
}

0 comments on commit 2e479d4

Please sign in to comment.