2021-06-03 11:39:19 +02:00
|
|
|
package signal
|
|
|
|
|
|
|
|
import (
|
2021-07-22 15:23:24 +02:00
|
|
|
"github.com/wiretrustee/wiretrustee/encryption"
|
2021-06-03 11:39:19 +02:00
|
|
|
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestEncryptDecrypt(t *testing.T) {
|
|
|
|
strMsg := "message to encrypt"
|
|
|
|
bytesMsg := []byte(strMsg)
|
|
|
|
|
|
|
|
peerAKey, err := wgtypes.GenerateKey()
|
|
|
|
if err != nil {
|
|
|
|
t.Error()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
peerBKey, err := wgtypes.GenerateKey()
|
|
|
|
if err != nil {
|
|
|
|
t.Error()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-07-22 15:23:24 +02:00
|
|
|
encryptedMessage, err := encryption.Encrypt(bytesMsg, peerBKey.PublicKey(), peerAKey)
|
2021-06-03 11:39:19 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-07-22 15:23:24 +02:00
|
|
|
decryptedMessage, err := encryption.Decrypt(encryptedMessage, peerAKey.PublicKey(), peerBKey)
|
2021-06-03 11:39:19 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if string(decryptedMessage) != strMsg {
|
|
|
|
t.Error()
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|