mirror of
https://github.com/netbirdio/netbird.git
synced 2025-03-19 17:56:41 +01:00
* refactor: extract common message encryption logic * refactor: move letsencrypt logic to common * refactor: rename common package to encryption * test: add encryption tests
42 lines
729 B
Go
42 lines
729 B
Go
package signal
|
|
|
|
import (
|
|
"github.com/wiretrustee/wiretrustee/encryption"
|
|
"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)
|
|
if err != nil {
|
|
t.Error(err)
|
|
return
|
|
}
|
|
|
|
decryptedMessage, err := encryption.Decrypt(encryptedMessage, peerAKey.PublicKey(), peerBKey)
|
|
if err != nil {
|
|
t.Error(err)
|
|
return
|
|
}
|
|
|
|
if string(decryptedMessage) != strMsg {
|
|
t.Error()
|
|
}
|
|
|
|
}
|