netbird/signal/encryption_test.go

42 lines
729 B
Go
Raw Normal View History

2021-06-03 11:39:19 +02:00
package signal
import (
"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
}
encryptedMessage, err := encryption.Encrypt(bytesMsg, peerBKey.PublicKey(), peerAKey)
2021-06-03 11:39:19 +02:00
if err != nil {
t.Error(err)
return
}
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()
}
}