From ec4741e374beeb085579ba896fdee2cd6f0f8848 Mon Sep 17 00:00:00 2001 From: Rasmus Dahlberg Date: Wed, 21 Oct 2020 18:18:43 +0200 Subject: added start on addEntry code path If the POSTed StItem can be parsed without errors it is handed over to the Trillian back-end. --- type.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'type.go') diff --git a/type.go b/type.go index e9b5ef2..031ae8d 100644 --- a/type.go +++ b/type.go @@ -55,6 +55,22 @@ func (i StItem) String() string { } } +func StItemFromB64(s string) (*StItem, error) { + b, err := base64.StdEncoding.DecodeString(s) + if err != nil { + return nil, fmt.Errorf("base64 decoding failed: %v", err) + } + + var item StItem + extra, err := tls.Unmarshal(b, &item) + if err != nil { + return nil, fmt.Errorf("tls unmarshal failed: %v", err) + } else if len(extra) > 0 { + return nil, fmt.Errorf("tls unmarshal found extra data: %v", extra) + } + return &item, nil +} + // ChecksumV1 associates a package name with an arbitrary checksum value type ChecksumV1 struct { Package []byte `tls:"minlen:0,maxlen:255"` @@ -75,3 +91,10 @@ func NewChecksumV1(name string, checksum []byte) (StItem, error) { func (i ChecksumV1) String() string { return fmt.Sprintf("%v %v", string(i.Package), base64.StdEncoding.EncodeToString(i.Checksum)) } + +// AddEntryRequest is a collection of add-entry input parameters +type AddEntryRequest struct { + Item string `json:"item"` + Signature string `json:"signature"` + Certificate string `json:"certificate"` +} -- cgit v1.2.3