...
1 package timestamp_test
2
3 import (
4 "bytes"
5 "crypto"
6 "fmt"
7 "io"
8 "log"
9 "net/http"
10 "strings"
11
12 "github.com/digitorus/timestamp"
13 )
14
15
16
17
18 func ExampleCreateRequest_ParseResponse() {
19 tsq, err := timestamp.CreateRequest(strings.NewReader("ExampleCreateRequestParseResponse"), ×tamp.RequestOptions{
20 Hash: crypto.SHA256,
21 Certificates: true,
22 })
23 if err != nil {
24 log.Fatal(err)
25 }
26
27 tsr, err := http.Post("https://freetsa.org/tsr", "application/timestamp-query", bytes.NewReader(tsq))
28 if err != nil {
29 log.Fatal(err)
30 }
31
32 if tsr.StatusCode > 200 {
33 log.Fatal(tsr.Status)
34 }
35
36 resp, err := io.ReadAll(tsr.Body)
37 if err != nil {
38 log.Fatal(err)
39 }
40
41 tsResp, err := timestamp.ParseResponse(resp)
42 if err != nil {
43 log.Fatal(err)
44 }
45
46 fmt.Println(tsResp.HashedMessage)
47 fmt.Println(tsResp.Policy)
48 for _, c := range tsResp.Certificates {
49 fmt.Println(c.Subject.Organization, c.Subject.OrganizationalUnit)
50 }
51
52
53
54
55
56
57
58 }
59
View as plain text