forked from kolesa-team/ncanode-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tsp_verify.go
45 lines (37 loc) · 1.06 KB
/
tsp_verify.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
package ncanode
import "bytes"
type tspVerifyRequest struct {
CMS string `json:"cms"`
}
// TSPVerifyResponse describes json response from TSPVerify.
type TSPVerifyResponse struct {
apiResponse
Result struct {
TSPHashAlgorithm HashAlgorithm `json:"tspHashAlgorithm"`
SerialNumber string `json:"serialNumber"`
GenTime Time `json:"genTime"`
Hash string `json:"hash"`
Policy string `json:"policy"`
} `json:"result"`
}
// TSPVerify validates tsp signature.
//
// See https://ncanode.kz/docs.php?go=c2e4ebcfdb0ce789aa3f985ad96d1d223c835284
func (c *Client) TSPVerify(cms string) (*TSPVerifyResponse, error) {
if len(cms) == 0 {
return nil, ErrInvalidRequestBody
}
body := apiRequest{
Version: c.version,
Method: "TSP.verify",
Params: tspVerifyRequest{CMS: cms},
}
mod := func(in []byte) ([]byte, error) {
return bytes.Replace(in, []byte(`\\`), []byte(`\`), -1), nil
}
var reply TSPVerifyResponse
if err := c.call(body, &reply, mod); err != nil {
return nil, err
}
return &reply, nil
}