feat: initial commit
All checks were successful
Cadoles/bouncer/pipeline/head This commit looks good
All checks were successful
Cadoles/bouncer/pipeline/head This commit looks good
This commit is contained in:
40
internal/jwk/jwk_test.go
Normal file
40
internal/jwk/jwk_test.go
Normal file
@ -0,0 +1,40 @@
|
||||
package jwk
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func TestJWK(t *testing.T) {
|
||||
privateKey, err := Generate(DefaultKeySize)
|
||||
if err != nil {
|
||||
t.Fatalf("%+v", errors.WithStack(err))
|
||||
}
|
||||
|
||||
keySet, err := PublicKeySet(privateKey)
|
||||
if err != nil {
|
||||
t.Fatalf("%+v", errors.WithStack(err))
|
||||
}
|
||||
|
||||
metadata := map[string]any{
|
||||
"Foo": "bar",
|
||||
"Test": 1,
|
||||
}
|
||||
|
||||
signature, err := Sign(privateKey, metadata)
|
||||
if err != nil {
|
||||
t.Fatalf("%+v", errors.WithStack(err))
|
||||
}
|
||||
|
||||
t.Logf("Signature: %s", signature)
|
||||
|
||||
matches, err := Verify(keySet, signature, metadata)
|
||||
if err != nil {
|
||||
t.Fatalf("%+v", errors.WithStack(err))
|
||||
}
|
||||
|
||||
if !matches {
|
||||
t.Error("signature should match")
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user