14func validateCookie(cookie *http.Cookie, seed string) (string, bool) {
15 // value, timestamp, sig
16 parts := strings.Split(cookie.Value, "|")
20 sig := cookieSignature(seed, cookie.Name, parts[0], parts[1])
22 ts, err := strconv.Atoi(parts[1])
23 if err == nil && int64(ts) > time.Now().Add(time.Duration(24)*7*time.Hour*-1).Unix() {
24 // it's a valid cookie. now get the contents
25 rawValue, err := base64.URLEncoding.DecodeString(parts[0])
27 return string(rawValue), true
34func signedCookieValue(seed string, key string, value string) string {
35 encodedValue := base64.URLEncoding.EncodeToString([]byte(value))
36 timeStr := fmt.Sprintf("%d", time.Now().Unix())
37 sig := cookieSignature(seed, key, encodedValue, timeStr)
38 cookieVal := fmt.Sprintf("%s|%s|%s", encodedValue, timeStr, sig)
42func cookieSignature(args ...string) string {
43 h := hmac.New(sha1.New, []byte(args[0]))
44 for _, arg := range args[1:] {
49 return base64.URLEncoding.EncodeToString(b)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list