aboutsummaryrefslogtreecommitdiff
path: root/types
diff options
context:
space:
mode:
authorRasmus Dahlberg <rasmus.dahlberg@kau.se>2021-06-01 21:37:54 +0200
committerRasmus Dahlberg <rasmus.dahlberg@kau.se>2021-06-01 21:37:54 +0200
commit2dcaf038655426c572c5d292973001c581f0a1a2 (patch)
treef52f2c93404a3f13e590c4af87ff349d563eae14 /types
parent2c2c6936a93ce4f18302426a665ed5782910ab85 (diff)
moved endpoint type into types
Diffstat (limited to 'types')
-rw-r--r--types/types.go41
-rw-r--r--types/types_test.go53
2 files changed, 72 insertions, 22 deletions
diff --git a/types/types.go b/types/types.go
index 2da40da..d031b29 100644
--- a/types/types.go
+++ b/types/types.go
@@ -3,17 +3,34 @@ package types
import (
"crypto/ed25519"
"crypto/sha256"
+ "strings"
)
const (
HashSize = sha256.Size
SignatureSize = ed25519.SignatureSize
VerificationKeySize = ed25519.PublicKeySize
+
+ EndpointAddLeaf = Endpoint("add-leaf")
+ EndpointAddCosignature = Endpoint("add-cosignature")
+ EndpointGetTreeHeadLatest = Endpoint("get-tree-head-latest")
+ EndpointGetTreeHeadToSign = Endpoint("get-tree-head-to-sign")
+ EndpointGetTreeHeadCosigned = Endpoint("get-tree-head-cosigned")
+ EndpointGetProofByHash = Endpoint("get-proof-by-hash")
+ EndpointGetConsistencyProof = Endpoint("get-consistency-proof")
+ EndpointGetLeaves = Endpoint("get-leaves")
)
+// Endpoint is a named HTTP API endpoint
+type Endpoint string
+
+// Path joins a number of components to form a full endpoint path. For example,
+// EndpointAddLeaf.Path("example.com", "st/v0") -> example.com/st/v0/add-leaf.
+func (e Endpoint) Path(components ...string) string {
+ return strings.Join(append(components, string(e)), "/")
+}
+
// Leaf is the log's Merkle tree leaf.
-//
-// Ref: https://github.com/system-transparency/stfe/blob/design/doc/api.md#merkle-tree-leaf
type Leaf struct {
Message
SigIdent
@@ -35,18 +52,12 @@ type SigIdent struct {
// SignedTreeHead is composed of a tree head and a list of signature-signer
// pairs. Each signature is computed over the Trunnel-serialized tree head.
-//
-// Ref: https://github.com/system-transparency/stfe/blob/design/doc/api.md#get-tree-head-cosigned
-// Ref: https://github.com/system-transparency/stfe/blob/design/doc/api.md#get-tree-head-to-sign
-// Ref: https://github.com/system-transparency/stfe/blob/design/doc/api.md#get-tree-head-latest
type SignedTreeHead struct {
TreeHead
SigIdent []*SigIdent
}
// TreeHead is the log's tree head.
-//
-// Ref: https://github.com/system-transparency/stfe/blob/design/doc/api.md#merkle-tree-head
type TreeHead struct {
Timestamp uint64
TreeSize uint64
@@ -55,8 +66,6 @@ type TreeHead struct {
// ConsistencyProof is a consistency proof that proves the log's append-only
// property.
-//
-// Ref: https://github.com/system-transparency/stfe/blob/design/doc/api.md#get-consistency-proof
type ConsistencyProof struct {
NewSize uint64
OldSize uint64
@@ -65,8 +74,6 @@ type ConsistencyProof struct {
// InclusionProof is an inclusion proof that proves a leaf is included in the
// log.
-//
-// Ref: https://github.com/system-transparency/stfe/blob/design/doc/api.md#get-proof-by-hash
type InclusionProof struct {
TreeSize uint64
LeafIndex uint64
@@ -77,32 +84,24 @@ type InclusionProof struct {
type LeafList []*Leaf
// ConsistencyProofRequest is a get-consistency-proof request
-//
-// Ref: https://github.com/system-transparency/stfe/blob/design/doc/api.md#get-consistency-proof
type ConsistencyProofRequest struct {
NewSize uint64
OldSize uint64
}
// InclusionProofRequest is a get-proof-by-hash request
-//
-// Ref: https://github.com/system-transparency/stfe/blob/design/doc/api.md#get-proof-by-hash
type InclusionProofRequest struct {
LeafHash *[HashSize]byte
TreeSize uint64
}
// LeavesRequest is a get-leaves request
-//
-// Ref: https://github.com/system-transparency/stfe/blob/design/doc/api.md#get-leaves
type LeavesRequest struct {
StartSize uint64
EndSize uint64
}
// LeafRequest is an add-leaf request
-//
-// Ref: https://github.com/system-transparency/stfe/blob/design/doc/api.md#add-leaf
type LeafRequest struct {
Message
Signature *[SignatureSize]byte
@@ -111,8 +110,6 @@ type LeafRequest struct {
}
// CosignatureRequest is an add-cosignature request
-//
-// Ref: https://github.com/system-transparency/stfe/blob/design/doc/api.md#add-cosignature
type CosignatureRequest struct {
SigIdent
}
diff --git a/types/types_test.go b/types/types_test.go
new file mode 100644
index 0000000..9d76c73
--- /dev/null
+++ b/types/types_test.go
@@ -0,0 +1,53 @@
+package types
+
+import (
+ "testing"
+)
+
+func TestEndpointPath(t *testing.T) {
+ base, prefix, proto := "example.com", "log", "st/v0"
+ for _, table := range []struct {
+ endpoint Endpoint
+ want string
+ }{
+ {
+ endpoint: EndpointAddLeaf,
+ want: "example.com/log/st/v0/add-leaf",
+ },
+ {
+ endpoint: EndpointAddCosignature,
+ want: "example.com/log/st/v0/add-cosignature",
+ },
+ {
+ endpoint: EndpointGetTreeHeadLatest,
+ want: "example.com/log/st/v0/get-tree-head-latest",
+ },
+ {
+ endpoint: EndpointGetTreeHeadToSign,
+ want: "example.com/log/st/v0/get-tree-head-to-sign",
+ },
+ {
+ endpoint: EndpointGetTreeHeadCosigned,
+ want: "example.com/log/st/v0/get-tree-head-cosigned",
+ },
+ {
+ endpoint: EndpointGetConsistencyProof,
+ want: "example.com/log/st/v0/get-consistency-proof",
+ },
+ {
+ endpoint: EndpointGetProofByHash,
+ want: "example.com/log/st/v0/get-proof-by-hash",
+ },
+ {
+ endpoint: EndpointGetLeaves,
+ want: "example.com/log/st/v0/get-leaves",
+ },
+ } {
+ if got, want := table.endpoint.Path(base+"/"+prefix+"/"+proto), table.want; got != want {
+ t.Errorf("got endpoint\n%s\n\tbut wanted\n%s\n\twith one component", got, want)
+ }
+ if got, want := table.endpoint.Path(base, prefix, proto), table.want; got != want {
+ t.Errorf("got endpoint\n%s\n\tbut wanted\n%s\n\tmultiple components", got, want)
+ }
+ }
+}