diff options
Diffstat (limited to 'whisper/whisperv6/message_test.go')
-rw-r--r-- | whisper/whisperv6/message_test.go | 67 |
1 files changed, 63 insertions, 4 deletions
diff --git a/whisper/whisperv6/message_test.go b/whisper/whisperv6/message_test.go index 912b90f14..c90bcc01e 100644 --- a/whisper/whisperv6/message_test.go +++ b/whisper/whisperv6/message_test.go @@ -174,10 +174,8 @@ func TestMessageSeal(t *testing.T) { t.Fatalf("failed to create new message with seed %d: %s.", seed, err) } params.TTL = 1 - aesnonce := make([]byte, 12) - mrand.Read(aesnonce) - env := NewEnvelope(params.TTL, params.Topic, aesnonce, msg) + env := NewEnvelope(params.TTL, params.Topic, msg) if err != nil { t.Fatalf("failed Wrap with seed %d: %s.", seed, err) } @@ -242,7 +240,12 @@ func singleEnvelopeOpenTest(t *testing.T, symmetric bool) { t.Fatalf("failed Wrap with seed %d: %s.", seed, err) } - f := Filter{KeyAsym: key, KeySym: params.KeySym} + var f Filter + if symmetric { + f = Filter{KeySym: params.KeySym} + } else { + f = Filter{KeyAsym: key} + } decrypted := env.Open(&f) if decrypted == nil { t.Fatalf("failed to open with seed %d.", seed) @@ -413,3 +416,59 @@ func TestPadding(t *testing.T) { singlePaddingTest(t, n) } } + +func TestPaddingAppendedToSymMessages(t *testing.T) { + params := &MessageParams{ + Payload: make([]byte, 246), + KeySym: make([]byte, aesKeyLength), + } + + // Simulate a message with a payload just under 256 so that + // payload + flag + aesnonce > 256. Check that the result + // is padded on the next 256 boundary. + msg := sentMessage{} + msg.Raw = make([]byte, len(params.Payload)+1+AESNonceLength) + + err := msg.appendPadding(params) + + if err != nil { + t.Fatalf("Error appending padding to message %v", err) + return + } + + if len(msg.Raw) != 512 { + t.Errorf("Invalid size %d != 512", len(msg.Raw)) + } +} + +func TestPaddingAppendedToSymMessagesWithSignature(t *testing.T) { + params := &MessageParams{ + Payload: make([]byte, 246), + KeySym: make([]byte, aesKeyLength), + } + + pSrc, err := crypto.GenerateKey() + + if err != nil { + t.Fatalf("Error creating the signature key %v", err) + return + } + params.Src = pSrc + + // Simulate a message with a payload just under 256 so that + // payload + flag + aesnonce > 256. Check that the result + // is padded on the next 256 boundary. + msg := sentMessage{} + msg.Raw = make([]byte, len(params.Payload)+1+AESNonceLength+signatureLength) + + err = msg.appendPadding(params) + + if err != nil { + t.Fatalf("Error appending padding to message %v", err) + return + } + + if len(msg.Raw) != 512 { + t.Errorf("Invalid size %d != 512", len(msg.Raw)) + } +} |