summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Kisiel <kamil@kamilkisiel.net>2015-08-06 18:27:58 +0300
committerKamil Kisiel <kamil@kamilkisiel.net>2015-08-06 18:27:58 +0300
commit5237f00be11e505c71d9fd0f2fd8580faa746614 (patch)
treed22dbf53c9545fd9c1a30214887d461b0aaa944a
parenta2b6e9f57ea55d2c7a8cf1de58593fa761a34b73 (diff)
parent84828075d0d711460567d521b07a30fd664979d5 (diff)
Merge pull request #29 from elithrar/codec-maxage-fix
Improved documentation for CodecsFromPairs.
-rw-r--r--securecookie.go24
1 files changed, 23 insertions, 1 deletions
diff --git a/securecookie.go b/securecookie.go
index 7c05972..7dd373d 100644
--- a/securecookie.go
+++ b/securecookie.go
@@ -484,7 +484,29 @@ func GenerateRandomKey(length int) []byte {
// CodecsFromPairs returns a slice of SecureCookie instances.
//
-// It is a convenience function to create a list of codecs for key rotation.
+// It is a convenience function to create a list of codecs for key rotation. Note
+// that the generated Codecs will have the default options applied: callers
+// should iterate over each Codec and type-assert the underlying *SecureCookie to
+// change these.
+//
+// Example:
+//
+// codecs := securecookie.CodecsFromPairs(
+// []byte("new-hash-key"),
+// []byte("new-block-key"),
+// []byte("old-hash-key"),
+// []byte("old-block-key"),
+// )
+//
+// // Modify each instance.
+// for _, s := range codecs {
+// if cookie, ok := s.(*securecookie.SecureCookie); ok {
+// cookie.MaxAge(86400 * 7)
+// cookie.SetSerializer(securecookie.JSONEncoder{})
+// cookie.HashFunc(sha512.New512_256)
+// }
+// }
+//
func CodecsFromPairs(keyPairs ...[]byte) []Codec {
codecs := make([]Codec, len(keyPairs)/2+len(keyPairs)%2)
for i := 0; i < len(keyPairs); i += 2 {