From a92d5e96eceba314fc06b6324a3a76643a201fc0 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Sat, 14 May 2011 16:58:55 -0700 Subject: [PATCH] Update for Go public key serialization change: http://code.google.com/p/go/source/detail?r=920f1bc872eed92199065a2a1dcd95bf134b96e9 --- server/go/camlistored/sig.go | 45 ++++-------------------------------- 1 file changed, 4 insertions(+), 41 deletions(-) diff --git a/server/go/camlistored/sig.go b/server/go/camlistored/sig.go index 02cf48db2..6ca8331a2 100644 --- a/server/go/camlistored/sig.go +++ b/server/go/camlistored/sig.go @@ -23,7 +23,6 @@ import ( "crypto/openpgp/armor" "fmt" "http" - "io" "log" "os" "path/filepath" @@ -98,19 +97,15 @@ func (hl *handlerLoader) createJSONSignHandler(conf jsonconfig.Obj) (http.Handle return nil, fmt.Errorf("Encrypted keys aren't yet supported") } - var buf1 bytes.Buffer - var buf2 bytes.Buffer - h.entity.PrivateKey.PublicKey.Serialize(&buf1) - - wc, err := armor.Encode(&buf2, openpgp.PublicKeyType, nil) + var buf bytes.Buffer + wc, err := armor.Encode(&buf, openpgp.PublicKeyType, nil) if err != nil { return nil, err } - serializeHeader(wc, buf1.Len()) - io.Copy(wc, &buf1) + h.entity.PrivateKey.PublicKey.Serialize(wc) wc.Close() - armoredPublicKey := buf2.String() + armoredPublicKey := buf.String() ms := new(blobref.MemoryStore) h.pubKeyBlobRef, err = ms.AddBlob(crypto.SHA1, armoredPublicKey) if err != nil { @@ -127,38 +122,6 @@ func (hl *handlerLoader) createJSONSignHandler(conf jsonconfig.Obj) (http.Handle return h, nil } -// TODO(bradfitz): this isn't exported in openpgp/packet/packet.go, so copied here -// for now. -// -// serializeHeader writes an OpenPGP packet header to w. See RFC 4880, section -// 4.2. -func serializeHeader(w io.Writer, length int) (err os.Error) { - ptype := byte(6) - var buf [6]byte - var n int - - buf[0] = 0x80 | 0x40 | byte(ptype) - if length < 192 { - buf[1] = byte(length) - n = 2 - } else if length < 8384 { - length -= 192 - buf[1] = 192 + byte(length>>8) - buf[2] = byte(length) - n = 3 - } else { - buf[1] = 255 - buf[2] = byte(length >> 24) - buf[3] = byte(length >> 16) - buf[4] = byte(length >> 8) - buf[5] = byte(length) - n = 6 - } - - _, err = w.Write(buf[:n]) - return -} - func (h *JSONSignHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) { base := req.Header.Get("X-PrefixHandler-PathBase") subPath := req.Header.Get("X-PrefixHandler-PathSuffix")