-
Notifications
You must be signed in to change notification settings - Fork 2
/
auth.go
48 lines (43 loc) · 924 Bytes
/
auth.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
package spki
import (
"github.com/eadmund/sexprs"
)
type AuthCert struct {
Expr sexprs.Sexp // the originally-parsed S-expression, for hashing
Issuer Name
Subject Subject
Delegate bool
Valid *Valid
Tag sexprs.Sexp
}
func (a AuthCert) Certificate() sexprs.Sexp {
return a.Sexp()
}
func (a AuthCert) Sexp() sexprs.Sexp {
switch {
case a.Expr != nil:
return a.Expr
}
var ds, vs sexprs.Sexp
var s sexprs.List
if a.Delegate {
ds = sexprs.List{sexprs.Atom{Value: []byte("delegate")}}
}
if a.Valid != nil {
vs = a.Valid.Sexp()
}
s = sexprs.List{sexprs.Atom{Value: []byte("cert")},
sexprs.List{sexprs.Atom{Value: []byte("issuer")}, a.Issuer.Sexp()},
sexprs.List{sexprs.Atom{Value: []byte("subject")}, a.Subject.Subject()}}
if ds != nil {
s = append(s, ds)
}
s = append(s, a.Tag)
if vs != nil {
s = append(s, vs)
}
return s
}
func (a AuthCert) String() string {
return a.Sexp().String()
}