mirror of
https://github.com/oauth2-proxy/oauth2-proxy.git
synced 2026-10-21 01:58:29 +02:00
Improvements to Session State code (#536)
* Drop SessionStateJSON wrapper * Use EncrpytInto/DecryptInto to reduce sessionstate Co-authored-by: Henry Jenkins <henry@henryjenkins.name>
This commit is contained in:
co-authored by
Henry Jenkins
parent
6a88da7f7a
commit
f7b28cb1d3
@@ -156,3 +156,30 @@ func (c *Cipher) Decrypt(s string) (string, error) {
|
||||
|
||||
return string(encrypted), nil
|
||||
}
|
||||
|
||||
// EncryptInto encrypts the value and stores it back in the string pointer
|
||||
func (c *Cipher) EncryptInto(s *string) error {
|
||||
return into(c.Encrypt, s)
|
||||
}
|
||||
|
||||
// DecryptInto decrypts the value and stores it back in the string pointer
|
||||
func (c *Cipher) DecryptInto(s *string) error {
|
||||
return into(c.Decrypt, s)
|
||||
}
|
||||
|
||||
// codecFunc is a function that takes a string and encodes/decodes it
|
||||
type codecFunc func(string) (string, error)
|
||||
|
||||
func into(f codecFunc, s *string) error {
|
||||
// Do not encrypt/decrypt nil or empty strings
|
||||
if s == nil || *s == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
d, err := f(*s)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*s = d
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user