Separate out key directory
This commit is contained in:
parent
b7671b9a97
commit
3dfe5b8558
6 changed files with 85 additions and 60 deletions
35
sqlite_directory/sqlite_directory.go
Normal file
35
sqlite_directory/sqlite_directory.go
Normal 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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue