summaryrefslogtreecommitdiff
path: root/securecookie.go
diff options
context:
space:
mode:
authorWenhui Shen <swhbox@foxmail.com>2017-07-22 06:11:58 +0300
committerWenhui Shen <swhbox@foxmail.com>2017-07-22 06:11:58 +0300
commitdeb9be694683b721489312b39d5265ff3d29add1 (patch)
treea949ad3c7c6efa6a52b7c3a78cce7805ff60eaab /securecookie.go
parente59506cc896acb7f7bf732d4fdf5e25f7ccd8983 (diff)
Decode: 支持传入临时参数 maxAge
Diffstat (limited to 'securecookie.go')
-rw-r--r--securecookie.go10
1 files changed, 7 insertions, 3 deletions
diff --git a/securecookie.go b/securecookie.go
index cd4e097..c386907 100644
--- a/securecookie.go
+++ b/securecookie.go
@@ -115,7 +115,7 @@ var (
// Codec defines an interface to encode and decode cookie values.
type Codec interface {
Encode(name string, value interface{}) (string, error)
- Decode(name, value string, dst interface{}) error
+ Decode(name, value string, dst interface{}, maxAge ...int) error
}
// New returns a new SecureCookie.
@@ -300,7 +300,7 @@ func (s *SecureCookie) Encode(name string, value interface{}) (string, error) {
// The name argument is the cookie name. It must be the same name used when
// it was stored. The value argument is the encoded cookie value. The dst
// argument is where the cookie will be decoded. It must be a pointer.
-func (s *SecureCookie) Decode(name, value string, dst interface{}) error {
+func (s *SecureCookie) Decode(name, value string, dst interface{}, maxAges ...int) error {
if s.err != nil {
return s.err
}
@@ -336,7 +336,11 @@ func (s *SecureCookie) Decode(name, value string, dst interface{}) error {
if s.minAge != 0 && t1 > t2-s.minAge {
return errTimestampTooNew
}
- if s.maxAge != 0 && t1 < t2-s.maxAge {
+ maxAge := s.maxAge
+ if len(maxAges) > 0 {
+ maxAge = int64(maxAges[0])
+ }
+ if maxAge != 0 && t1 < t2-maxAge {
return errTimestampExpired
}
// 5. Decrypt (optional).