-
Notifications
You must be signed in to change notification settings - Fork 98
Expand file tree
/
Copy pathstore.go
More file actions
40 lines (31 loc) · 1.24 KB
/
Copy pathstore.go
File metadata and controls
40 lines (31 loc) · 1.24 KB
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
package store
import (
"errors"
"github.com/knadh/otpgateway/v3/internal/models"
)
var (
// ErrNotExist is thrown when an OTP (requested by namespace / ID)
// does not exist.
ErrNotExist = errors.New("the OTP does not exist")
// ErrTooManyAttempts is thrown when an OTP (requested by namespace / ID)
// attempts are maxed out.
ErrTooManyAttempts = errors.New("too many attempts")
)
// Store represents a storage backend where OTP data is stored.
type Store interface {
// Set sets an OTP against an ID. Every Set() increments the attempts
// count against the ID that was initially set.
Set(namespace, id string, otp models.OTP) (models.OTP, error)
// SetAddress sets (updates) the address on an existing OTP.
SetAddress(namespace, id, address string) error
// Check checks the attempt count and TTL duration against an ID.
// Passing counter=true increments the attempt counter.
Check(namespace, id string, counter bool) (models.OTP, error)
// Close closes an OTP and marks it as done (verified).
// After this, the OTP has to expire after a TTL or be deleted.
Close(namespace, id string) error
// Delete deletes the OTP saved against a given ID.
Delete(namespace, id string) error
// Ping checks if store is reachable
Ping() error
}