forked from cossacklabs/acra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
context.go
27 lines (22 loc) · 888 Bytes
/
context.go
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
package encryptor
import (
"context"
"github.com/cossacklabs/acra/encryptor/config"
)
type settingKey struct{}
// NewContextWithEncryptionSetting makes a new context containing column encryption settings.
func NewContextWithEncryptionSetting(ctx context.Context, setting config.ColumnEncryptionSetting) context.Context {
return context.WithValue(ctx, settingKey{}, setting)
}
// EncryptionSettingFromContext extracts column encryption settings for a context,
// or returns "nil" if there the context does not contain it.
func EncryptionSettingFromContext(ctx context.Context) (config.ColumnEncryptionSetting, bool) {
// Explicitly check for presence and return explicit "nil" value
// so that returned interface is "== nil".
value := ctx.Value(settingKey{})
if value == nil {
return nil, false
}
setting, ok := value.(config.ColumnEncryptionSetting)
return setting, ok
}