new helpers for drive decryption (#73)

* new helpers for drive decryption

* modular helper functions and reciprocals

* removed duplicates helper functions

* added mobile wrapper

* unit tests for new helpers

Co-authored-by: wussler <aron@wussler.it>
This commit is contained in:
marinthiercelin 2020-08-27 17:34:46 +02:00 committed by GitHub
parent af371097e0
commit 39c2fa863e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 231 additions and 38 deletions

View file

@ -1,6 +1,7 @@
package helper
import (
"bytes"
"testing"
"github.com/ProtonMail/gopenpgp/v2/crypto"
@ -154,3 +155,64 @@ func TestArmoredBinaryMessageEncryption(t *testing.T) {
assert.Exactly(t, plainData, decrypted)
}
func TestEncryptSignArmoredDetached(t *testing.T) {
plainData := []byte("Secret message")
privateKeyString := readTestFile("keyring_privateKey", false)
privateKey, err := crypto.NewKeyFromArmored(privateKeyString)
if err != nil {
t.Fatal("Error reading the test private key: ", err)
}
publicKeyString, err := privateKey.GetArmoredPublicKey()
if err != nil {
t.Fatal("Error reading the test public key: ", err)
}
armoredCiphertext, armoredSignature, err := EncryptSignArmoredDetached(
publicKeyString,
privateKeyString,
testMailboxPassword, // Password defined in base_test
plainData,
)
if err != nil {
t.Fatal("Expected no error while encrypting and signing, got:", err)
}
decrypted, err := DecryptVerifyArmoredDetached(
publicKeyString,
privateKeyString,
testMailboxPassword,
armoredCiphertext,
armoredSignature,
)
if err != nil {
t.Fatal("Expected no error while decrypting and verifying, got:", err)
}
if !bytes.Equal(decrypted, plainData) {
t.Error("Decrypted is not equal to the plaintext")
}
_, modifiedSignature, err := EncryptSignArmoredDetached(
publicKeyString,
privateKeyString,
testMailboxPassword, // Password defined in base_test
[]byte("Different message"),
)
if err != nil {
t.Fatal("Expected no error while encrypting and signing, got:", err)
}
_, err = DecryptVerifyArmoredDetached(
publicKeyString,
privateKeyString,
testMailboxPassword,
armoredCiphertext,
modifiedSignature,
)
if err == nil {
t.Fatal("Expected an error while decrypting and verifying with a wrong signature")
}
}