mirror of
https://github.com/garethgeorge/backrest.git
synced 2025-12-15 01:55:35 +00:00
30 lines
656 B
Go
30 lines
656 B
Go
package syncapi
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestIdentity(t *testing.T) {
|
|
dir := t.TempDir()
|
|
|
|
// Create a new identity
|
|
ident, err := NewIdentity("test-instance", filepath.Join(dir, "myidentity.pem"))
|
|
if err != nil {
|
|
t.Fatalf("failed to create identity: %v", err)
|
|
}
|
|
|
|
signature, err := ident.SignMessage([]byte("hello world!"))
|
|
fmt.Printf("signed message: %x\n", signature)
|
|
|
|
// Load and print identity file
|
|
bytes, _ := os.ReadFile(filepath.Join(dir, "myidentity.pem"))
|
|
t.Log(string(bytes))
|
|
|
|
// Load and print public key file
|
|
bytes, _ = os.ReadFile(filepath.Join(dir, "myidentity.pem.pub"))
|
|
t.Log(string(bytes))
|
|
}
|