@@ -25,18 +25,18 @@ var (
25
25
)
26
26
27
27
func (ctx * Context ) SetSecureCookie (name string , val string , age int64 ) error {
28
- serverConfig := ctx .Server . Config
29
- if len (serverConfig .CookieSecret ) == 0 {
28
+ server := ctx .Server
29
+ if len (server . Config .CookieSecret ) == 0 {
30
30
return ErrMissingCookieSecret
31
31
}
32
- if len (serverConfig .encKey ) == 0 || len (serverConfig .signKey ) == 0 {
32
+ if len (server .encKey ) == 0 || len (server .signKey ) == 0 {
33
33
return ErrInvalidKey
34
34
}
35
- ciphertext , err := encrypt ([]byte (val ), serverConfig .encKey )
35
+ ciphertext , err := encrypt ([]byte (val ), server .encKey )
36
36
if err != nil {
37
37
return err
38
38
}
39
- sig := sign (ciphertext , serverConfig .signKey )
39
+ sig := sign (ciphertext , server .signKey )
40
40
data := base64 .StdEncoding .EncodeToString (ciphertext ) + "|" + base64 .StdEncoding .EncodeToString (sig )
41
41
ctx .SetCookie (NewCookie (name , data , age ))
42
42
return nil
@@ -59,11 +59,11 @@ func (ctx *Context) GetSecureCookie(name string) (string, bool) {
59
59
if err != nil {
60
60
return "" , false
61
61
}
62
- expectedSig := sign ([]byte (ciphertext ), ctx .Server .Config . signKey )
62
+ expectedSig := sign ([]byte (ciphertext ), ctx .Server .signKey )
63
63
if ! bytes .Equal (expectedSig , sig ) {
64
64
return "" , false
65
65
}
66
- plaintext , err := decrypt (ciphertext , ctx .Server .Config . encKey )
66
+ plaintext , err := decrypt (ciphertext , ctx .Server .encKey )
67
67
if err != nil {
68
68
return "" , false
69
69
}
0 commit comments