-
Notifications
You must be signed in to change notification settings - Fork 3
/
types.go
55 lines (41 loc) · 1.23 KB
/
types.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
package logclient
import (
"crypto/x509"
ctgo "github.com/google/certificate-transparency-go"
)
type Entry struct {
Id int64
Log *Log
Certificate *x509.Certificate
Chain []*x509.Certificate
CertData []byte
}
func ParseRawLogEntry(id int64, log *Log, rawEntry *ctgo.RawLogEntry) Entry {
entry := Entry{Id: id, Log: log, Chain: make([]*x509.Certificate, 0), CertData: rawEntry.Cert.Data}
if cert, err := x509.ParseCertificate(rawEntry.Cert.Data); err == nil {
entry.Certificate = cert
}
for _, rawCert := range rawEntry.Chain {
if cert, err := x509.ParseCertificate(rawCert.Data); err == nil {
entry.Chain = append(entry.Chain, cert)
}
}
return entry
}
type LogMap map[string]*Log
type Page struct {
start int64
end int64
}
func NewPage(start int64, pageSize int) (page Page) {
page = Page{start: start, end: start + int64(pageSize) - 1}
if page.start%int64(pageSize) != 0 {
// align end to page size
page.end = (page.start/int64(pageSize))*int64(pageSize) + int64(pageSize) - 1
}
return
}
type ById []Entry
func (a ById) Len() int { return len(a) }
func (a ById) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a ById) Less(i, j int) bool { return a[i].Id < a[j].Id }