-
Notifications
You must be signed in to change notification settings - Fork 0
/
keymgr.go
60 lines (49 loc) · 1.39 KB
/
keymgr.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
package main
import (
"bytes"
"encoding/gob"
"fmt"
"io"
"os"
)
type KeyPayload struct {
FirstName string
MiddleInitial string
LastName string
ValidEmail string
ValidSMSNumber string
PublicKey string
// AcctUsername is the
// sha1 hmac of PublicKey, prefixed with "p" (for pelican) and
// encoded in base 36; A regex for it would be: "p[0-9a-z]{31}"
// This is to conform to the requirements of linux usernames.
// See man page for useradd; at one point there was a 32 character limit,
// (must have since been raised, but we'll be conservative and honor
// it anyway for now). Usernames must start with a letter and then contain
// be only lowercase letters and digits. Underscores and
// dashes are allowed too but we don't use them.
AcctUsername string
}
func SendKeyPayload(p *KeyPayload) {
var buf bytes.Buffer
enc := gob.NewEncoder(&buf) // Will write to buf
// Encode (send) some values.
err := enc.Encode(p)
if err != nil {
panic(fmt.Sprintf("encode error:", err))
}
toWrite := len(buf.Bytes())
n, err := io.Copy(os.Stdout, &buf)
if err != nil {
panic(err)
}
if n != int64(toWrite) {
panic(fmt.Sprintf("did not write all of buf; n=%v\n, len(buf)=%v\n", n, toWrite))
}
}
func main() {
gob.Register(KeyPayload{})
key := &KeyPayload{PublicKey: "0123456789abcdef-hello-public-key"}
SendKeyPayload(key)
fmt.Printf("\n done sending: '%#v'.\n", key)
}