aboutsummaryrefslogtreecommitdiff
path: root/inform/codec.go
diff options
context:
space:
mode:
Diffstat (limited to 'inform/codec.go')
-rw-r--r--inform/codec.go16
1 files changed, 14 insertions, 2 deletions
diff --git a/inform/codec.go b/inform/codec.go
index e5c9296..8147986 100644
--- a/inform/codec.go
+++ b/inform/codec.go
@@ -5,6 +5,8 @@ import (
5 "encoding/binary" 5 "encoding/binary"
6 "errors" 6 "errors"
7 "io" 7 "io"
8
9 "github.com/golang/snappy"
8) 10)
9 11
10type Codec struct { 12type Codec struct {
@@ -33,6 +35,7 @@ func (c *Codec) Unmarshal(fp io.Reader) (*InformWrapper, error) {
33 35
34 var dataLen int32 36 var dataLen int32
35 binary.Read(fp, binary.BigEndian, &dataLen) 37 binary.Read(fp, binary.BigEndian, &dataLen)
38 w.DataLength = dataLen
36 39
37 p := make([]byte, dataLen) 40 p := make([]byte, dataLen)
38 io.ReadFull(fp, p) 41 io.ReadFull(fp, p)
@@ -42,12 +45,21 @@ func (c *Codec) Unmarshal(fp io.Reader) (*InformWrapper, error) {
42 return nil, errors.New("No key found") 45 return nil, errors.New("No key found")
43 } 46 }
44 47
45 u, err := Decrypt(p, iv, key) 48 u, err := Decrypt(p, iv, key, w)
46 if err != nil { 49 if err != nil {
47 return nil, err 50 return nil, err
48 } 51 }
49 52
50 w.Payload = u 53 if w.IsSnappyCompressed() {
54 w.Payload, err = snappy.Decode(nil, u)
55 if err != nil {
56 return nil, err
57 }
58 } else if w.IsZlibCompressed() {
59 return nil, errors.New("payload is zlib compressed, not supported")
60 } else {
61 w.Payload = u
62 }
51 63
52 return w, nil 64 return w, nil
53} 65}