1package gpg
2
3import "context"
4
5type contextKey int
6
7const (
8	ctxKeyAlwaysTrust contextKey = iota
9	ctxKeyUseCache
10)
11
12// WithAlwaysTrust will return a context with the flag for always trust set
13func WithAlwaysTrust(ctx context.Context, at bool) context.Context {
14	return context.WithValue(ctx, ctxKeyAlwaysTrust, at)
15}
16
17// IsAlwaysTrust will return the value of the always trust flag or the default
18// (false)
19func IsAlwaysTrust(ctx context.Context) bool {
20	bv, ok := ctx.Value(ctxKeyAlwaysTrust).(bool)
21	if !ok {
22		return false
23	}
24	return bv
25}
26
27// WithUseCache returns a context with the value of NoCache set
28func WithUseCache(ctx context.Context, nc bool) context.Context {
29	return context.WithValue(ctx, ctxKeyUseCache, nc)
30}
31
32// UseCache returns true if this request should ignore the cache
33func UseCache(ctx context.Context) bool {
34	nc, ok := ctx.Value(ctxKeyUseCache).(bool)
35	if !ok {
36		return false
37	}
38	return nc
39}
40