mirror of https://github.com/perkeep/perkeep.git
some sig discovery work
This commit is contained in:
parent
73a7329401
commit
962d65877d
|
@ -120,9 +120,9 @@ type MemoryStore struct {
|
|||
m map[string]string
|
||||
}
|
||||
|
||||
func (s *MemoryStore) AddBlob(hashtype crypto.Hash, data string) os.Error {
|
||||
func (s *MemoryStore) AddBlob(hashtype crypto.Hash, data string) (*BlobRef, os.Error) {
|
||||
if hashtype != crypto.SHA1 {
|
||||
return os.NewError("blobref: unsupported hash type")
|
||||
return nil, os.NewError("blobref: unsupported hash type")
|
||||
}
|
||||
hash := hashtype.New()
|
||||
hash.Write([]byte(data))
|
||||
|
@ -134,7 +134,7 @@ func (s *MemoryStore) AddBlob(hashtype crypto.Hash, data string) os.Error {
|
|||
}
|
||||
s.m[bstr] = data
|
||||
log.Printf("added %s", bstr)
|
||||
return nil
|
||||
return Parse(bstr), nil
|
||||
}
|
||||
|
||||
func (s *MemoryStore) FetchStreaming(b *BlobRef) (file io.ReadCloser, size int64, err os.Error) {
|
||||
|
|
|
@ -29,6 +29,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"camli/blobref"
|
||||
"camli/httputil"
|
||||
"camli/jsonconfig"
|
||||
"camli/jsonsign"
|
||||
)
|
||||
|
@ -45,6 +46,7 @@ type JSONSignHandler struct {
|
|||
// of the longer forms.
|
||||
keyId string
|
||||
|
||||
pubKeyBlobRef *blobref.BlobRef
|
||||
pubKeyFetcher blobref.StreamingFetcher
|
||||
|
||||
entity *openpgp.Entity
|
||||
|
@ -100,7 +102,7 @@ func createJSONSignHandler(conf jsonconfig.Obj) (http.Handler, os.Error) {
|
|||
log.Printf("got key: %s", buf.String())
|
||||
|
||||
ms := new(blobref.MemoryStore)
|
||||
err = ms.AddBlob(crypto.SHA1, buf.String())
|
||||
h.pubKeyBlobRef, err = ms.AddBlob(crypto.SHA1, buf.String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -111,6 +113,15 @@ func createJSONSignHandler(conf jsonconfig.Obj) (http.Handler, os.Error) {
|
|||
|
||||
func (h *JSONSignHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
|
||||
switch req.Method {
|
||||
case "GET":
|
||||
if strings.HasSuffix(req.URL.Path, "/camli/sig/discovery") {
|
||||
m := map[string]interface{}{}
|
||||
if h.pubKeyBlobRef != nil {
|
||||
m["publicKeyBlobRef"] = h.pubKeyBlobRef.String()
|
||||
}
|
||||
httputil.ReturnJson(rw, m)
|
||||
return
|
||||
}
|
||||
case "POST":
|
||||
switch {
|
||||
case strings.HasSuffix(req.URL.Path, "/camli/sig/sign"):
|
||||
|
|
Loading…
Reference in New Issue