mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-10-10 12:53:33 +02:00
fix nip04 decryption padding and add tests.
This commit is contained in:
47
nip04/nip04_test.go
Normal file
47
nip04/nip04_test.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package nip04
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestEncryptionAndDecryption(t *testing.T) {
|
||||
sharedSecret := make([]byte, 32)
|
||||
message := "hello hellow"
|
||||
|
||||
ciphertext, err := Encrypt(message, sharedSecret)
|
||||
if err != nil {
|
||||
t.Errorf("failed to encrypt: %s", err.Error())
|
||||
}
|
||||
|
||||
plaintext, err := Decrypt(ciphertext, sharedSecret)
|
||||
if err != nil {
|
||||
t.Errorf("failed to decrypt: %s", err.Error())
|
||||
}
|
||||
|
||||
if message != plaintext {
|
||||
t.Errorf("original '%s' and decrypted '%s' messages differ", message, plaintext)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEncryptionAndDecryptionWithMultipleLengths(t *testing.T) {
|
||||
sharedSecret := make([]byte, 32)
|
||||
|
||||
for i := 0; i < 150; i++ {
|
||||
message := strings.Repeat("a", i)
|
||||
|
||||
ciphertext, err := Encrypt(message, sharedSecret)
|
||||
if err != nil {
|
||||
t.Errorf("failed to encrypt: %s", err.Error())
|
||||
}
|
||||
|
||||
plaintext, err := Decrypt(ciphertext, sharedSecret)
|
||||
if err != nil {
|
||||
t.Errorf("failed to decrypt: %s", err.Error())
|
||||
}
|
||||
|
||||
if message != plaintext {
|
||||
t.Errorf("original '%s' and decrypted '%s' messages differ", message, plaintext)
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user