Skip to content

Commit ccf6a96

Browse files
committed
Making sure unknown OS returns error
1 parent a0b3c52 commit ccf6a96

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

entropychecker.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ var MinimumEntropy = 128
1717
// Waiting for entropy will time out after this amount of time. Setting to zero will never time out.
1818
var Timeout = time.Second * 10
1919

20+
// The only supported OS is linux at this time.
21+
var supportedOS = "linux"
22+
2023
// ErrTimeout is for when the system waits too long and gives up
2124
var ErrTimeout = errors.New("entropychecker: Timed out waiting for sufficient entropy")
2225

@@ -25,7 +28,7 @@ var ErrUnsupportedOS = errors.New("entropychecker: Unsupported OS. Only Linux is
2528

2629
// GetEntropy gets the entropy estimate. Returns the estimated entropy in bits
2730
func GetEntropy() (int, error) {
28-
if runtime.GOOS != "linux" {
31+
if runtime.GOOS != supportedOS {
2932
return 0, ErrUnsupportedOS
3033
}
3134

@@ -38,7 +41,7 @@ func GetEntropy() (int, error) {
3841

3942
// WaitForEntropy blocks until sufficient entropy is available
4043
func WaitForEntropy() error {
41-
if runtime.GOOS != "linux" {
44+
if runtime.GOOS != supportedOS {
4245
return ErrUnsupportedOS
4346
}
4447

entropychecker_test.go

+11
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,21 @@ func TestEntropyChecker(t *testing.T) {
3232
}
3333

3434
func TestFailure(t *testing.T) {
35+
// Make sure we get a an error if we time out
3536
Timeout = 200 * time.Millisecond
3637
MinimumEntropy = 100000
3738
err := WaitForEntropy()
3839
if err == nil {
3940
t.Error("Should get error when timeout waited too long")
4041
}
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+
4152
}

0 commit comments

Comments
 (0)