forked from akash-network/node
/
types.go
70 lines (54 loc) · 1.24 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package v1beta1
import (
"bytes"
"math/big"
sdk "github.com/cosmos/cosmos-sdk/types"
)
const (
PemBlkTypeCertificate = "CERTIFICATE"
PemBlkTypeECPrivateKey = "EC PRIVATE KEY"
PemBlkTypeECPublicKey = "EC PUBLIC KEY"
)
type CertID struct {
Owner sdk.Address
Serial big.Int
}
func ToCertID(id CertificateID) (CertID, error) {
addr, err := sdk.AccAddressFromBech32(id.Owner)
if err != nil {
return CertID{}, err
}
serial, valid := new(big.Int).SetString(id.Serial, 10)
if !valid {
return CertID{}, ErrInvalidSerialNumber
}
return CertID{
Owner: addr,
Serial: *serial,
}, nil
}
// Certificates is the collection of Certificate
type Certificates []Certificate
type CertificatesResponse []CertificateResponse
// String implements the Stringer interface for a Certificates object.
func (obj Certificates) String() string {
var buf bytes.Buffer
const sep = "\n\n"
for _, p := range obj {
buf.WriteString(p.String())
buf.WriteString(sep)
}
if len(obj) > 0 {
buf.Truncate(buf.Len() - len(sep))
}
return buf.String()
}
func (obj Certificates) Contains(cert Certificate) bool {
for _, c := range obj {
// fixme is bytes.Equal right way to do it?
if bytes.Equal(c.Cert, cert.Cert) {
return true
}
}
return false
}