π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Add test for encrypt and decrypt chacha
Neeraj Gupta0b7752688439
diff --git a/internal/crypto/crypto_test.go b/internal/crypto/crypto_test.goindex 9fa90ec724..fc48fa768d 100644--- a/internal/crypto/crypto_test.go+++ b/internal/crypto/crypto_test.go@@ -1,6 +1,7 @@package cryptoimport (+ "crypto/rand""encoding/base64""testing")@@ -32,7 +33,6 @@ func TestDecryptChaCha20poly1305(t *testing.T) {if err != nil {t.Fatalf("Failed to derive key: %v", err)}-decodedCipherText, err := base64.StdEncoding.DecodeString(cipherText)if err != nil {t.Fatalf("Failed to decode cipher text: %v", err)@@ -52,7 +52,25 @@ func TestDecryptChaCha20poly1305(t *testing.T) {}}-// Write a test for SecretBoxOpenBase64+func TestEncryptAndDecryptChaCha20Ploy1305(t *testing.T) {+ key := make([]byte, 32)+ _, err := rand.Read(key)+ if err != nil {+ t.Fatalf("Failed to generate random key: %v", err)+ }+ cipher, nonce, err := EncryptChaCha20poly1305([]byte("plain_text"), key)+ if err != nil {+ return+ }+ plainText, err := decryptChaCha20poly1305(cipher, key, nonce)+ if err != nil {+ t.Fatalf("Failed to decrypt: %v", err)+ }+ if string(plainText) != "plain_text" {+ t.Fatalf("Decrypted text : %s does not match the expected text: %s", string(plainText), "plain_text")+ }+}+func TestSecretBoxOpenBase64(t *testing.T) {sealedCipherText := "KHwRN+RzvTu+jC7mCdkMsqnTPSLvevtZILmcR2OYFbIRPqDyjAl+m8KxD9B5fiEo"sealNonce := "jgfPDOsQh2VdIHWJVSBicMPF2sQW3HIY"