-
Notifications
You must be signed in to change notification settings - Fork 0
/
flags.go
69 lines (54 loc) · 1.76 KB
/
flags.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
63
64
65
66
67
68
69
package security
import (
"log/slog"
"sync/atomic"
)
type atomicBool int32
func (b *atomicBool) isSet() bool { return atomic.LoadInt32((*int32)(b)) != 0 }
func (b *atomicBool) setTrue() { atomic.StoreInt32((*int32)(b), 1) }
func (b *atomicBool) setFalse() { atomic.StoreInt32((*int32)(b), 0) }
// -----------------------------------------------------------------------------
var devMode atomicBool
// InDevMode returns the development mode flag status.
func InDevMode() bool {
return devMode.isSet()
}
// SetDevMode enables the local development mode in this package and returns a
// function to revert the configuration.
//
// Calling this method multiple times once the flag is enabled produces no effect.
func SetDevMode() (revert func()) {
// Prevent multiple calls to indirectly disable the flag
if devMode.isSet() {
return func() {}
}
devMode.setTrue()
slog.Debug("Secure SDK: Development mode enabled")
return func() {
devMode.setFalse()
slog.Debug("Secure SDK: Development mode disabled")
}
}
// -----------------------------------------------------------------------------
var fipsMode atomicBool
// InFIPSMode returns the FIPS compliance mode flag status.
func InFIPSMode() bool {
// FIPS mode is enabled if the flag is set
return fipsMode.isSet()
}
// SetFIPSMode enables the FIPS compliance mode in this package and returns a
// function to revert the configuration.
//
// Calling this method multiple times once the flag is enabled produces no effect.
func SetFIPSMode() (revert func()) {
// Prevent multiple calls to indirectly disable the flag
if fipsMode.isSet() {
return func() {}
}
fipsMode.setTrue()
slog.Debug("Secure SDK: FIPS mode enabled")
return func() {
fipsMode.setFalse()
slog.Debug("Secure SDK: FIPS mode disabled")
}
}