mirror of https://github.com/perkeep/perkeep.git
signhandler: inject the claimdate (if present) in the signrequest
This allows to set a signature time (instead of using time.Now()), so that identical files will result in identical permanodes. Change-Id: I315c06bd30e8ac5e4d36b0e3f758483c22a31063
This commit is contained in:
parent
f1f670079b
commit
83fa932f3c
|
@ -255,5 +255,13 @@ func (h *Handler) Sign(bb *schema.Builder) (string, error) {
|
|||
ServerMode: true,
|
||||
SecretKeyringPath: h.secretRing,
|
||||
}
|
||||
claimTime, err := bb.Blob().ClaimDate()
|
||||
if err != nil {
|
||||
if !schema.IsMissingField(err) {
|
||||
return "", err
|
||||
}
|
||||
} else {
|
||||
sreq.SignatureTime = claimTime
|
||||
}
|
||||
return sreq.Sign()
|
||||
}
|
||||
|
|
|
@ -27,6 +27,19 @@ import (
|
|||
"camlistore.org/pkg/blobref"
|
||||
)
|
||||
|
||||
// A MissingFieldError represents a missing JSON field in a schema blob.
|
||||
type MissingFieldError string
|
||||
|
||||
func (e MissingFieldError) Error() string {
|
||||
return fmt.Sprintf("schema: missing field %q", string(e))
|
||||
}
|
||||
|
||||
// IsMissingField returns whether error is of type MissingFieldError.
|
||||
func IsMissingField(err error) bool {
|
||||
_, ok := err.(MissingFieldError)
|
||||
return ok
|
||||
}
|
||||
|
||||
// AnyBlob represents any type of schema blob.
|
||||
type AnyBlob interface {
|
||||
Blob() *Blob
|
||||
|
@ -73,6 +86,17 @@ func (b *Blob) FileName() string {
|
|||
return b.ss.FileNameString()
|
||||
}
|
||||
|
||||
// ClaimDate returns the "claimDate" field.
|
||||
// If there is no claimDate, the error will be a MissingFieldError.
|
||||
func (b *Blob) ClaimDate() (time.Time, error) {
|
||||
var ct time.Time
|
||||
claimDate := b.ss.ClaimDate
|
||||
if claimDate == "" {
|
||||
return ct, MissingFieldError("claimDate")
|
||||
}
|
||||
return time.Parse(time.RFC3339, claimDate)
|
||||
}
|
||||
|
||||
// ByteParts returns the "parts" field. The caller owns the returned
|
||||
// slice.
|
||||
func (b *Blob) ByteParts() []BytesPart {
|
||||
|
|
Loading…
Reference in New Issue