kunt

golang IRC bot
git clone git://git.2f30.org/kunt.git
Log | Files | Refs | LICENSE

commit 353c8d8fec597469da337e93dd922df980fb5d9e
parent a62a7eed8f8c931d4eacaec24c6943b04ee6539d
Author: sin <sin@2f30.org>
Date:   Tue Apr 30 17:26:41 +0100

gob should contain Data as well

Diffstat:
src/bdec/bdec.go | 12+++---------
src/benc/benc.go | 8+++-----
2 files changed, 6 insertions(+), 14 deletions(-)
diff --git a/src/bdec/bdec.go b/src/bdec/bdec.go @@ -6,7 +6,6 @@ import ( "encoding/gob" "flag" "fmt" - "io/ioutil" "log" "os" ) @@ -29,6 +28,7 @@ func decryptBuf(c *blowfish.Cipher, a []byte) []byte { type hdr struct { Magic string Len uint64 + Data []byte } func main() { @@ -55,18 +55,12 @@ func main() { r := bufio.NewReader(fi) g := gob.NewDecoder(r) - // read header h := new(hdr) err = g.Decode(h) if err != nil { log.Fatal(err) } - // read body - buf, err := ioutil.ReadAll(r) - if err != nil { - log.Fatal(err) - } - - fmt.Printf("%s", decryptBuf(c, buf)[0:h.Len]) + db := decryptBuf(c, h.Data) + fmt.Printf("%s", db[0:h.Len]) } diff --git a/src/benc/benc.go b/src/benc/benc.go @@ -40,6 +40,7 @@ func encryptBuf(c *blowfish.Cipher, a []byte) []byte { type hdr struct { Magic string Len uint64 + Data []byte } func main() { @@ -61,15 +62,12 @@ func main() { if err != nil { log.Fatal(err) } + eb := encryptBuf(c, b) - // Write header out - h := &hdr{"benc", uint64(len(b))} + h := &hdr{"benc", uint64(len(b)), eb} g := gob.NewEncoder(os.Stdout) err = g.Encode(*h) if err != nil { log.Fatal(err) } - - // Write body - fmt.Printf("%s", encryptBuf(c, b)) }