aboutsummaryrefslogtreecommitdiff
path: root/objects
diff options
context:
space:
mode:
Diffstat (limited to 'objects')
-rw-r--r--objects/id.go10
-rw-r--r--objects/object_snapshot.go17
2 files changed, 25 insertions, 2 deletions
diff --git a/objects/id.go b/objects/id.go
index 224b3cd..047fada 100644
--- a/objects/id.go
+++ b/objects/id.go
@@ -39,7 +39,7 @@ type ObjectId struct {
Sum []byte
}
-func (oid ObjectId) wellformed() bool {
+func (oid ObjectId) Wellformed() bool {
return oid.Algo.checkAlgo() && len(oid.Sum) == oid.Algo.sumLength()
}
@@ -61,13 +61,19 @@ func ParseObjectId(s string) (oid ObjectId, err error) {
return
}
- if !oid.wellformed() {
+ if !oid.Wellformed() {
err = errors.New("Object ID is malformed")
}
return
}
+// Set implements flag.Value for ObjectId
+func (oid *ObjectId) Set(s string) (err error) {
+ *oid, err = ParseObjectId(s)
+ return
+}
+
func MustParseObjectId(s string) ObjectId {
id, err := ParseObjectId(s)
if err != nil {
diff --git a/objects/object_snapshot.go b/objects/object_snapshot.go
index 7edbc2a..e86484d 100644
--- a/objects/object_snapshot.go
+++ b/objects/object_snapshot.go
@@ -23,6 +23,7 @@ type Snapshot struct {
Archive string
Comment string
Signed bool
+ raw []byte
}
func (s Snapshot) Type() ObjectType {
@@ -62,6 +63,20 @@ func (s Snapshot) Payload() (out []byte) {
return out
}
+type Verifyer interface {
+ Verify([]byte) error
+}
+
+// Verify verifies that the snapshot has a valid signature.
+// Only works with unserialized snapshots, i.e. a freshly created snapshot can not be verified.
+func (s Snapshot) Verify(v Verifyer) error {
+ if !s.Signed {
+ return nil
+ }
+
+ return v.Verify(s.raw)
+}
+
type Signer interface {
Sign([]byte) ([]byte, error)
}
@@ -73,6 +88,8 @@ func (s Snapshot) SignedPayload(signer Signer) ([]byte, error) {
func (s *Snapshot) FromPayload(payload []byte) error {
r := bytes.NewBuffer(payload)
+ s.raw = payload
+
seenArchive := false
seenDate := false
seenTree := false