mt-multiserver-proxy/auth.go

35 lines
623 B
Go
Raw Normal View History

2021-09-06 02:03:27 -07:00
package proxy
2021-09-06 02:03:27 -07:00
import (
"errors"
"time"
)
2021-09-10 03:47:19 -07:00
var authIface authBackend
2021-09-06 02:03:27 -07:00
var ErrAuthBackendExists = errors.New("auth backend already set")
type user struct {
name string
salt []byte
verifier []byte
timestamp time.Time
}
2021-09-10 03:47:19 -07:00
type authBackend interface {
Exists(name string) bool
Passwd(name string) (salt, verifier []byte, err error)
SetPasswd(name string, salt, verifier []byte) error
Timestamp(name string) (time.Time, error)
Import(data []user)
Export() ([]user, error)
}
2021-09-06 02:03:27 -07:00
2021-09-10 03:47:19 -07:00
func setAuthBackend(ab authBackend) error {
2021-09-06 02:03:27 -07:00
if authIface != nil {
return ErrAuthBackendExists
}
authIface = ab
return nil
}