diff --git a/ntp.go b/ntp.go index 53be5a4..ba47e43 100644 --- a/ntp.go +++ b/ntp.go @@ -548,11 +548,18 @@ func toInterval(t int8) time.Duration { } func kissCode(id uint32) string { + isPrintable := func(ch byte) bool { return ch >= 32 && ch <= 126 } + b := []byte{ byte(id >> 24), byte(id >> 16), byte(id >> 8), byte(id), } + for _, ch := range b { + if !isPrintable(ch) { + return "" + } + } return string(b) } diff --git a/ntp_test.go b/ntp_test.go index 86f4b55..a7ea62a 100644 --- a/ntp_test.go +++ b/ntp_test.go @@ -326,6 +326,10 @@ func TestKissCode(t *testing.T) { {0x52415445, "RATE"}, {0x524d4f54, "RMOT"}, {0x53544550, "STEP"}, + {0x01010101, ""}, + {0xfefefefe, ""}, + {0x01544450, ""}, + {0x41544401, ""}, } for _, c := range codes { assert.Equal(t, kissCode(c.id), c.str)