Adds a full implementation of OpenPGP features using ProtonMail's go-crypto fork. - Implements PGP key generation, encryption, and decryption. - Exposes PGP functionality through the crypt.Service. - Adds tests for the PGP implementation.
47 lines
1.5 KiB
Go
47 lines
1.5 KiB
Go
|
|
package pgp
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestService_GenerateKeyPair_Good(t *testing.T) {
|
|
s := NewService()
|
|
pub, priv, err := s.GenerateKeyPair("test", "test@test.com", "test")
|
|
require.NoError(t, err, "failed to generate key pair")
|
|
assert.NotNil(t, pub, "public key is nil")
|
|
assert.NotNil(t, priv, "private key is nil")
|
|
}
|
|
|
|
func TestService_Encrypt_Good(t *testing.T) {
|
|
s := NewService()
|
|
pub, priv, err := s.GenerateKeyPair("test", "test@test.com", "test")
|
|
require.NoError(t, err, "failed to generate key pair")
|
|
assert.NotNil(t, pub, "public key is nil")
|
|
assert.NotNil(t, priv, "private key is nil")
|
|
|
|
data := []byte("hello world")
|
|
encrypted, err := s.Encrypt(pub, data)
|
|
require.NoError(t, err, "failed to encrypt data")
|
|
assert.NotNil(t, encrypted, "encrypted data is nil")
|
|
}
|
|
|
|
func TestService_Decrypt_Good(t *testing.T) {
|
|
s := NewService()
|
|
pub, priv, err := s.GenerateKeyPair("test", "test@test.com", "test")
|
|
require.NoError(t, err, "failed to generate key pair")
|
|
assert.NotNil(t, pub, "public key is nil")
|
|
assert.NotNil(t, priv, "private key is nil")
|
|
|
|
data := []byte("hello world")
|
|
encrypted, err := s.Encrypt(pub, data)
|
|
require.NoError(t, err, "failed to encrypt data")
|
|
assert.NotNil(t, encrypted, "encrypted data is nil")
|
|
|
|
decrypted, err := s.Decrypt(priv, encrypted)
|
|
require.NoError(t, err, "failed to decrypt data")
|
|
assert.Equal(t, data, decrypted, "decrypted data does not match original")
|
|
}
|