blob: 9625cc7f8256619e780208347839613d5a5e9c13 (
plain) (
blame)
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
|
package auth
import (
"fmt"
"time"
)
const (
// Maximum number of bytes in a username.
MaxUnameSize = 64
// Number of bytes in a session ID.
SessIdSize = 32
SessTimeout = 1 * time.Hour
)
// User name.
type Uname string
// Session ID.
type SessId [SessIdSize]byte
func ParseUname(s string) (Uname, error) {
if len(s) > MaxUnameSize {
return "", fmt.Errorf("username longer than %d bytes: %q", MaxUnameSize, s)
}
return Uname(s), nil
}
func ParseSessId(s string) (SessId, error) {
if len(s) != SessIdSize {
return SessId{}, fmt.Errorf("wrong session ID size: %d (want %d): %q", len(s), SessIdSize, s)
}
var id SessId
copy(id[:], s)
return id, nil
}
|