File tree 2 files changed +16
-2
lines changed
2 files changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,9 @@ var MinimumEntropy = 128
17
17
// Waiting for entropy will time out after this amount of time. Setting to zero will never time out.
18
18
var Timeout = time .Second * 10
19
19
20
+ // The only supported OS is linux at this time.
21
+ var supportedOS = "linux"
22
+
20
23
// ErrTimeout is for when the system waits too long and gives up
21
24
var ErrTimeout = errors .New ("entropychecker: Timed out waiting for sufficient entropy" )
22
25
@@ -25,7 +28,7 @@ var ErrUnsupportedOS = errors.New("entropychecker: Unsupported OS. Only Linux is
25
28
26
29
// GetEntropy gets the entropy estimate. Returns the estimated entropy in bits
27
30
func GetEntropy () (int , error ) {
28
- if runtime .GOOS != "linux" {
31
+ if runtime .GOOS != supportedOS {
29
32
return 0 , ErrUnsupportedOS
30
33
}
31
34
@@ -38,7 +41,7 @@ func GetEntropy() (int, error) {
38
41
39
42
// WaitForEntropy blocks until sufficient entropy is available
40
43
func WaitForEntropy () error {
41
- if runtime .GOOS != "linux" {
44
+ if runtime .GOOS != supportedOS {
42
45
return ErrUnsupportedOS
43
46
}
44
47
Original file line number Diff line number Diff line change @@ -32,10 +32,21 @@ func TestEntropyChecker(t *testing.T) {
32
32
}
33
33
34
34
func TestFailure (t * testing.T ) {
35
+ // Make sure we get a an error if we time out
35
36
Timeout = 200 * time .Millisecond
36
37
MinimumEntropy = 100000
37
38
err := WaitForEntropy ()
38
39
if err == nil {
39
40
t .Error ("Should get error when timeout waited too long" )
40
41
}
42
+
43
+ // Make sure an unspported OS returns an error (instead of unkown behavior)
44
+ supportedOS = "unknown"
45
+ Timeout = 10 * time .Second
46
+ MinimumEntropy = 128
47
+ err = WaitForEntropy ()
48
+ if err == nil {
49
+ t .Error ("Should get error when using unknown OS" )
50
+ }
51
+
41
52
}
You can’t perform that action at this time.
0 commit comments