Add basic key registration
This commit is contained in:
parent
3dfe5b8558
commit
949d1fc2ad
6 changed files with 138 additions and 55 deletions
|
@ -2,7 +2,9 @@ package sqlite_directory
|
|||
|
||||
import (
|
||||
"context"
|
||||
"crypto"
|
||||
"crypto/ed25519"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/common-fate/httpsig/alg_ed25519"
|
||||
|
@ -16,7 +18,11 @@ type InMemoryDirectory struct {
|
|||
}
|
||||
|
||||
func (dir InMemoryDirectory) GetKey(ctx context.Context, keyId string, _ string) (verifier.Algorithm, error) {
|
||||
entry := dir.records[keyId]
|
||||
entry, ok := dir.records[keyId]
|
||||
|
||||
if !ok {
|
||||
return nil, errors.New("key not found in directory")
|
||||
}
|
||||
|
||||
var alg verifier.Algorithm
|
||||
var err error
|
||||
|
@ -33,3 +39,15 @@ func (dir InMemoryDirectory) GetKey(ctx context.Context, keyId string, _ string)
|
|||
|
||||
return alg, err
|
||||
}
|
||||
|
||||
func (dir InMemoryDirectory) RegisterKey(key crypto.PublicKey, alg string, userId string) (string, error) {
|
||||
keyId := userId
|
||||
|
||||
dir.records[keyId] = keydirectory.KeyEntry{
|
||||
Alg: alg,
|
||||
PublicKey: key,
|
||||
UserId: userId,
|
||||
}
|
||||
|
||||
return keyId, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue