aboutsummaryrefslogtreecommitdiff
path: root/setter.go
blob: 2ad7052f2a0db7c495b822794a46d1f33c10a68c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package securecookie

import (
	"crypto/cipher"
	"hash"
)

func SetMaxLength(codecs []Codec, l int) {
	for _, c := range codecs {
		if codec, ok := c.(*SecureCookie); ok {
			codec.MaxLength(l)
		}
	}
}

func SetMaxAge(codecs []Codec, l int) {
	for _, c := range codecs {
		if codec, ok := c.(*SecureCookie); ok {
			codec.MaxAge(l)
		}
	}
}

func SetMinAge(codecs []Codec, l int) {
	for _, c := range codecs {
		if codec, ok := c.(*SecureCookie); ok {
			codec.MinAge(l)
		}
	}
}

func SetHashFunc(codecs []Codec, f func() hash.Hash) {
	for _, c := range codecs {
		if codec, ok := c.(*SecureCookie); ok {
			codec.HashFunc(f)
		}
	}
}

func SetBlockFunc(codecs []Codec, f func([]byte) (cipher.Block, error)) {
	for _, c := range codecs {
		if codec, ok := c.(*SecureCookie); ok {
			codec.BlockFunc(f)
		}
	}
}

func SetSerializer(codecs []Codec, sz Serializer) {
	for _, c := range codecs {
		if codec, ok := c.(*SecureCookie); ok {
			codec.SetSerializer(sz)
		} else if codec, ok := c.(*LiteCodec); ok {
			codec.SetSerializer(sz)
		}
	}
}