aboutsummaryrefslogtreecommitdiffstats
path: root/oae2_test.go
diff options
context:
space:
mode:
authorRose Hogenson <rosehogenson@posteo.net>2026-01-26 07:09:07 -0800
committerRose Hogenson <rosehogenson@posteo.net>2026-01-26 07:09:07 -0800
commit35076fdc4ecdfdac27d6e48c0c563716507fb6b9 (patch)
treea4a4abb30c0eff581cb0885002ccf01d8388d7d5 /oae2_test.go
parentAdd support for additional data (diff)
downloadoae2-35076fdc4ecdfdac27d6e48c0c563716507fb6b9.tar.zst
Make sure to reject a 32 byte message
Diffstat (limited to 'oae2_test.go')
-rw-r--r--oae2_test.go45
1 files changed, 45 insertions, 0 deletions
diff --git a/oae2_test.go b/oae2_test.go
index 4099aa7..f0ed37f 100644
--- a/oae2_test.go
+++ b/oae2_test.go
@@ -2,6 +2,7 @@ package oae2
import (
"bytes"
+ "crypto/rand"
"io"
"strings"
"testing"
@@ -57,6 +58,19 @@ func TestReadFromWriteTo(t *testing.T) {
}
}
+func TestInvalid(t *testing.T) {
+ t.Parallel()
+
+ const (
+ msg = "01234567890123456789012345678901"
+ key = "asdf"
+ )
+ _, err := io.ReadAll(NewReader(strings.NewReader(msg), []byte(key), 1, nil))
+ if err == nil {
+ t.Errorf("Message %q passed validation, want error", msg)
+ }
+}
+
func TestReader_Seek(t *testing.T) {
t.Parallel()
const (
@@ -196,6 +210,37 @@ func FuzzReadFromWriteTo(f *testing.F) {
})
}
+func FuzzReadInvalid(f *testing.F) {
+ f.Add(1, "", "")
+ f.Add(1, "01234567890123456789012345678901", "")
+ f.Fuzz(func(t *testing.T, segmentSize int, msg string, additionalData string) {
+ if segmentSize <= 0 {
+ return
+ }
+ password := make([]byte, 32)
+ // Get a random password so that we can be sure msg is invalid
+ rand.Read(password)
+ if _, err := io.ReadAll(NewReader(strings.NewReader(msg), password, segmentSize, []byte(additionalData))); err == nil {
+ t.Errorf("Reader.Read: message passed validation")
+ }
+ })
+}
+
+func FuzzWriteToInvalid(f *testing.F) {
+ f.Add(1, "", "")
+ f.Add(1, "01234567890123456789012345678901", "")
+ f.Fuzz(func(t *testing.T, segmentSize int, msg string, additionalData string) {
+ if segmentSize <= 0 {
+ return
+ }
+ password := make([]byte, 32)
+ rand.Read(password)
+ if _, err := NewReader(strings.NewReader(msg), password, segmentSize, []byte(additionalData)).WriteTo(io.Discard); err == nil {
+ t.Errorf("Reader.WriteTo: message passed validation")
+ }
+ })
+}
+
func FuzzSeekStart(f *testing.F) {
f.Add(1, []byte("Hello World!"), 6)
f.Add(30, []byte("000000"), 6)