-
Notifications
You must be signed in to change notification settings - Fork 11
/
disabled.go
39 lines (31 loc) · 1.02 KB
/
disabled.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
// Copyright (C) 2023 Storj Labs, Inc.
// See LICENSE for copying information.
package signing
import (
"context"
"os"
"strconv"
)
var (
disabledGlobally, _ = strconv.ParseBool(os.Getenv("STORJ_DISABLE_SIGNING"))
// Takes the place of signatures when they are disabled. The presence
// of a "signature" is required because some components check that the
// signature field has len > 0.
disabledSignature = []byte("DISABLED-SIGNATURE")
)
type signaturesDisabledForTestKey struct{}
// Disabled returns true if signatures are disabled. If disabled, signatures
// are set to "DISABLED-SIGNATURE" and are ignored during verification.
func Disabled() bool {
return disabledGlobally
}
func areSignaturesDisabled(ctx context.Context) bool {
if disabledGlobally {
return true
}
_, disabledForTest := ctx.Value(signaturesDisabledForTestKey{}).(struct{})
return disabledForTest
}
func withSignaturesDisabledForTest(ctx context.Context) context.Context {
return context.WithValue(ctx, signaturesDisabledForTestKey{}, struct{}{})
}