Separate out key directory

This commit is contained in:
cheddar 2025-02-17 19:55:53 -05:00
parent b7671b9a97
commit 3dfe5b8558
No known key found for this signature in database
6 changed files with 85 additions and 60 deletions

View file

@ -0,0 +1,23 @@
package sqlite_directory
import (
"crypto"
"crispbyte.dev/sig-auth/keydirectory"
)
func CreateDirectory(alg string, publicKey crypto.PublicKey) InMemoryDirectory {
keyDir := InMemoryDirectory{
records: map[string]keydirectory.KeyEntry{},
}
keyId := "test-id"
keyDir.records[keyId] = keydirectory.KeyEntry{
Alg: alg,
PublicKey: publicKey,
UserId: "test_user",
}
return keyDir
}

View file

@ -0,0 +1,35 @@
package sqlite_directory
import (
"context"
"crypto/ed25519"
"fmt"
"github.com/common-fate/httpsig/alg_ed25519"
"github.com/common-fate/httpsig/verifier"
"crispbyte.dev/sig-auth/keydirectory"
)
type InMemoryDirectory struct {
records map[string]keydirectory.KeyEntry
}
func (dir InMemoryDirectory) GetKey(ctx context.Context, keyId string, _ string) (verifier.Algorithm, error) {
entry := dir.records[keyId]
var alg verifier.Algorithm
var err error
switch entry.Alg {
case "ed25519":
alg = alg_ed25519.Ed25519{
PublicKey: entry.PublicKey.(ed25519.PublicKey),
Attrs: entry.UserId,
}
default:
err = fmt.Errorf("unknown algoritm: %s", entry.Alg)
}
return alg, err
}