-
Notifications
You must be signed in to change notification settings - Fork 1
/
context.go
62 lines (49 loc) · 1.57 KB
/
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
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
57
58
59
60
61
62
// SPDX-FileCopyrightText: 2019 Elasticsearch B.V.
// SPDX-FileCopyrightText: 2019-2023 Thibault NORMAND <me@zenithar.org>
//
// SPDX-License-Identifier: Apache-2.0 AND MIT
package signature
import (
"context"
)
var (
contextKeyDetachedSignature = contextKey("detachedSignature")
contextKeyInputHash = contextKey("inputHash")
contextKeyDeterministicSignature = contextKey("deterministic")
)
// -----------------------------------------------------------------------------
type contextKey string
func (c contextKey) String() string {
return "zntr.io/harp/v2/pkg/sdk/value/signature/" + string(c)
}
// -----------------------------------------------------------------------------
func WithDetachedSignature(ctx context.Context, value bool) context.Context {
return context.WithValue(ctx, contextKeyDetachedSignature, value)
}
func IsDetached(ctx context.Context) bool {
value, ok := ctx.Value(contextKeyDetachedSignature).(bool)
if !ok {
return false
}
return value
}
func WithInputPreHashed(ctx context.Context, value bool) context.Context {
return context.WithValue(ctx, contextKeyInputHash, value)
}
func IsInputPreHashed(ctx context.Context) bool {
value, ok := ctx.Value(contextKeyInputHash).(bool)
if !ok {
return false
}
return value
}
func WithDetermisticSignature(ctx context.Context, value bool) context.Context {
return context.WithValue(ctx, contextKeyDeterministicSignature, value)
}
func IsDeterministic(ctx context.Context) bool {
value, ok := ctx.Value(contextKeyDeterministicSignature).(bool)
if !ok {
return false
}
return value
}