This repository has been archived by the owner on Jun 6, 2023. It is now read-only.
/
userdb.go
72 lines (58 loc) · 2.53 KB
/
userdb.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// userdb.go - Katzenpost server user database interface.
// Copyright (C) 2017 Yawning Angel.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
// Package userdb defines the Katzenpost server user database abstract
// interface.
package userdb
import (
"errors"
"github.com/katzenpost/core/crypto/ecdh"
"github.com/katzenpost/core/sphinx/constants"
)
// MaxUsernameSize is the maximum username length in bytes.
const MaxUsernameSize = constants.RecipientIDLength
var (
// ErrNoSuchUser is the error returned when an operation fails due to
// a non-existent user.
ErrNoSuchUser = errors.New("userdb: no such user")
// ErrNoIdentity is the error returned when the specified user has no
// identity key set.
ErrNoIdentity = errors.New("userdb: no identity key set")
)
// UserDB is the interface provided by all user database implementations.
type UserDB interface {
// Exists returns true iff the user identified by the username exists.
Exists([]byte) bool
// IsValid returns true iff the user identified by the username and
// public key is valid.
IsValid([]byte, *ecdh.PublicKey) bool
// Link returns the user's link layer authentication key.
Link([]byte) (*ecdh.PublicKey, error)
// Add adds the user identified by the username and public key
// to the database. Existing users will have their public keys
// updated if specified, otherwise an error will be returned.
Add([]byte, *ecdh.PublicKey, bool) error
// SetIdentity sets the optional identity key for the user identified
// by the user name to the provided public key. Providing a nil key
// will remove the user's identity key iff it exists.
SetIdentity([]byte, *ecdh.PublicKey) error
// Identity returns the optional identity key for the user identified
// by the user name.
Identity([]byte) (*ecdh.PublicKey, error)
// Remove removes the user identified by the username from the database.
Remove([]byte) error
// Close closes the UserDB instance.
Close()
}