Reog and implement sqlite
This commit is contained in:
parent
30cdf2c7e7
commit
61aa1be730
9 changed files with 223 additions and 76 deletions
45
keydirectory/in_memory_directory.go
Normal file
45
keydirectory/in_memory_directory.go
Normal file
|
@ -0,0 +1,45 @@
|
|||
package keydirectory
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto"
|
||||
"errors"
|
||||
|
||||
"github.com/common-fate/httpsig/verifier"
|
||||
)
|
||||
|
||||
type inMemoryDirectory struct {
|
||||
records map[string]keyEntry
|
||||
}
|
||||
|
||||
func CreateMemoryDirectory() inMemoryDirectory {
|
||||
return inMemoryDirectory{
|
||||
records: map[string]keyEntry{},
|
||||
}
|
||||
}
|
||||
|
||||
func (dir inMemoryDirectory) GetKey(ctx context.Context, keyId string, _ string) (verifier.Algorithm, error) {
|
||||
entry, ok := dir.records[keyId]
|
||||
|
||||
if !ok {
|
||||
return nil, errors.New("key not found in directory")
|
||||
}
|
||||
|
||||
return entry.toAlg()
|
||||
}
|
||||
|
||||
func (dir inMemoryDirectory) RegisterKey(key crypto.PublicKey, alg string, userId string) (string, error) {
|
||||
keyId, err := generateKeyId()
|
||||
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
dir.records[keyId] = keyEntry{
|
||||
Alg: alg,
|
||||
PublicKey: key,
|
||||
UserId: userId,
|
||||
}
|
||||
|
||||
return keyId, nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue