aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRasmus Dahlberg <rasmus.dahlberg@kau.se>2021-06-05 17:15:47 +0200
committerRasmus Dahlberg <rasmus.dahlberg@kau.se>2021-06-05 17:15:47 +0200
commitebd9efbf32065baa261b2af1625991100ed23bf7 (patch)
treed3a764600d64a79e8372f5eaab95e6ea4461f47d
parente6ac59fd3d3eca51cc732dd5dc33942be79ffb9b (diff)
attached sign and verify methods to the basic types
-rw-r--r--types/types.go40
-rw-r--r--types/types_test.go5
2 files changed, 44 insertions, 1 deletions
diff --git a/types/types.go b/types/types.go
index d031b29..405c825 100644
--- a/types/types.go
+++ b/types/types.go
@@ -1,9 +1,12 @@
package types
import (
+ "crypto"
+ "fmt"
+ "strings"
+
"crypto/ed25519"
"crypto/sha256"
- "strings"
)
const (
@@ -113,3 +116,38 @@ type LeafRequest struct {
type CosignatureRequest struct {
SigIdent
}
+
+// Sign signs the tree head using the log's signature scheme
+func (th *TreeHead) Sign(signer crypto.Signer) (*SignedTreeHead, error) {
+ sig, err := signer.Sign(nil, th.Marshal(), crypto.Hash(0))
+ if err != nil {
+ return nil, fmt.Errorf("Sign: %v", err)
+ }
+
+ sigident := SigIdent{
+ KeyHash: Hash(signer.Public().(ed25519.PublicKey)[:]),
+ Signature: &[SignatureSize]byte{},
+ }
+ copy(sigident.Signature[:], sig)
+ return &SignedTreeHead{
+ TreeHead: *th,
+ SigIdent: []*SigIdent{
+ &sigident,
+ },
+ }, nil
+}
+
+// Verify verifies the tree head signature using the log's signature scheme
+func (th *TreeHead) Verify(pub crypto.PublicKey) error { // TODO
+ return nil
+}
+
+// Verify checks if a leaf is included in the log
+func (p *InclusionProof) Verify(leaf *Leaf, th *TreeHead) error { // TODO
+ return nil
+}
+
+// Verify checks if two tree heads are consistent
+func (p *ConsistencyProof) Verify(oldTH, newTH *TreeHead) error { // TODO
+ return nil
+}
diff --git a/types/types_test.go b/types/types_test.go
index 9d76c73..22a03d4 100644
--- a/types/types_test.go
+++ b/types/types_test.go
@@ -51,3 +51,8 @@ func TestEndpointPath(t *testing.T) {
}
}
}
+
+func TestTreeHeadSign(t *testing.T) {}
+func TestTreeHeadVerify(t *testing.T) {}
+func TestInclusionProofVerify(t *testing.T) {}
+func TestConsistencyProofVerify(t *testing.T) {}