1
0
Fork 0
forked from jriou/coller

Initial commit

Signed-off-by: Julien Riou <julien@riou.xyz>
This commit is contained in:
Julien Riou 2025-08-21 16:22:03 +02:00
commit ef9aca1f3b
Signed by: jriou
GPG key ID: 9A099EDA51316854
26 changed files with 1668 additions and 0 deletions

View file

@ -0,0 +1,44 @@
package internal
import (
"testing"
)
func TestEncryptAndDecrypt(t *testing.T) {
plaintext := "test"
password := "test"
wrongPassword := password + "wrong"
ciphertext, err := Encrypt([]byte(plaintext), password)
if err != nil {
t.Errorf("unexpected error when encrypting: %v", err)
return
}
if plaintext == string(ciphertext) {
t.Errorf("plaintext and ciphertext are equal")
return
}
cleartext, err := Decrypt(ciphertext, password)
if err != nil {
t.Errorf("unexpected error when decrypting: %v", err)
return
}
if string(cleartext) != string(plaintext) {
t.Errorf("got '%s', expected '%s'", cleartext, plaintext)
return
}
if password == wrongPassword {
t.Errorf("passwords must be different")
return
}
_, err = Decrypt(ciphertext, wrongPassword)
if err == nil {
t.Errorf("expected error when decrypting with a wrong password, got none")
return
}
}