diff options
author | Kamil Kisiel <kamil@kamilkisiel.net> | 2013-10-17 21:33:57 +0400 |
---|---|---|
committer | Kamil Kisiel <kamil@kamilkisiel.net> | 2013-10-17 21:33:57 +0400 |
commit | 155134204c034796bcd7a72c1e1b53ba005735c6 (patch) | |
tree | 55bd8c60e047c352c881b6c66af76c341426d666 /securecookie.go | |
parent | 6186150e83a63fbc943913bc96d4528460d79a28 (diff) |
Better errors for {En,De}codeMulti.
Diffstat (limited to 'securecookie.go')
-rw-r--r-- | securecookie.go | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/securecookie.go b/securecookie.go index 892b412..2f34bfe 100644 --- a/securecookie.go +++ b/securecookie.go @@ -357,12 +357,17 @@ func CodecsFromPairs(keyPairs ...[]byte) []Codec { return codecs } +var errNoCodecs = errors.New("securecookie: no codecs provided") + // EncodeMulti encodes a cookie value using a group of codecs. // // The codecs are tried in order. Multiple codecs are accepted to allow // key rotation. -func EncodeMulti(name string, value interface{}, - codecs ...Codec) (string, error) { +func EncodeMulti(name string, value interface{}, codecs ...Codec) (string, error) { + if len(codecs) == 0 { + return "", errNoCodecs + } + var errors MultiError for _, codec := range codecs { if encoded, err := codec.Encode(name, value); err == nil { @@ -378,8 +383,11 @@ func EncodeMulti(name string, value interface{}, // // The codecs are tried in order. Multiple codecs are accepted to allow // key rotation. -func DecodeMulti(name string, value string, dst interface{}, - codecs ...Codec) error { +func DecodeMulti(name string, value string, dst interface{}, codecs ...Codec) error { + if len(codecs) == 0 { + return errNoCodecs + } + var errors MultiError for _, codec := range codecs { if err := codec.Decode(name, value, dst); err == nil { |