mirror of
https://github.com/netbirdio/netbird.git
synced 2025-08-16 01:58:16 +02:00
test: add signal encryption test
This commit is contained in:
40
signal/encryption_test.go
Normal file
40
signal/encryption_test.go
Normal file
@ -0,0 +1,40 @@
|
||||
package signal
|
||||
|
||||
import (
|
||||
"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 := Encrypt(bytesMsg, peerBKey.PublicKey(), peerAKey)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
decryptedMessage, err := Decrypt(encryptedMessage, peerAKey.PublicKey(), peerBKey)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
if string(decryptedMessage) != strMsg {
|
||||
t.Error()
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user