2024-08-11 03:51:22 +02:00
|
|
|
package lysand
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"crypto/ed25519"
|
|
|
|
|
"crypto/x509"
|
|
|
|
|
"encoding/base64"
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
"testing"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestSPKIPublicKey_UnmarshalJSON(t *testing.T) {
|
|
|
|
|
expectedPk := must(x509.ParsePKIXPublicKey, must(base64.StdEncoding.DecodeString, "MCowBQYDK2VwAyEAgKNt+9eyOXdb7MSrrmHlsFD2H9NGwC+56PjpWD46Tcs="))
|
|
|
|
|
|
2024-08-20 22:43:26 +02:00
|
|
|
pk := UserPublicKey{}
|
2024-08-11 03:51:22 +02:00
|
|
|
raw := []byte(`{"public_key":"MCowBQYDK2VwAyEAgKNt+9eyOXdb7MSrrmHlsFD2H9NGwC+56PjpWD46Tcs="}`)
|
|
|
|
|
if err := json.Unmarshal(raw, &pk); err != nil {
|
|
|
|
|
t.Error(err)
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-20 22:43:26 +02:00
|
|
|
assert.Equal(t, expectedPk, ed25519.PublicKey(pk.Key))
|
2024-08-11 03:51:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestSPKIPublicKey_MarshalJSON(t *testing.T) {
|
|
|
|
|
expectedPk := must(x509.ParsePKIXPublicKey, must(base64.StdEncoding.DecodeString, "MCowBQYDK2VwAyEAgKNt+9eyOXdb7MSrrmHlsFD2H9NGwC+56PjpWD46Tcs=")).(ed25519.PublicKey)
|
|
|
|
|
|
2024-08-20 22:43:26 +02:00
|
|
|
pk := UserPublicKey{
|
|
|
|
|
Key: SPKIPublicKey(expectedPk),
|
2024-08-11 03:51:22 +02:00
|
|
|
}
|
|
|
|
|
if _, err := json.Marshal(pk); err != nil {
|
|
|
|
|
t.Error(err)
|
|
|
|
|
}
|
|
|
|
|
}
|