aboutsummaryrefslogtreecommitdiff
path: root/bencode
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2016-07-17 03:05:33 +0200
committerDimitri Sokolyuk <demon@dim13.org>2016-07-17 03:05:33 +0200
commit0fe086993b01f7d53c8b226bd1eb5665c1d0c18f (patch)
tree81d1289c4312baa54b3ded4ff5a61a8aaa550df1 /bencode
parentc317718d85c2881dad37dd009c4d690e599a2f34 (diff)
Replace InfoHash with Raw
Diffstat (limited to 'bencode')
-rw-r--r--bencode/bdecode.go22
1 files changed, 8 insertions, 14 deletions
diff --git a/bencode/bdecode.go b/bencode/bdecode.go
index 4c7302d..e542f9b 100644
--- a/bencode/bdecode.go
+++ b/bencode/bdecode.go
@@ -2,7 +2,6 @@ package bencode
import (
"bytes"
- "crypto/sha1"
"errors"
"reflect"
"strconv"
@@ -46,28 +45,23 @@ func (d *decodeState) unmarshalDict(v reflect.Value) error {
if d.data[d.off] != 'd' {
return ErrValue
}
+
+ rawStart := d.off
d.off++
- var infoOff, infoEnd int
for d.data[d.off] != 'e' {
key, n := parseString(d.data[d.off:])
d.off += n
- if key == "info" {
- infoOff = d.off
- }
d.unmarshalField(findKey(key, v))
- if key == "info" {
- infoEnd = d.off
- }
}
- if v.CanSet() {
- if ih := v.FieldByName("InfoHash"); ih.IsValid() && infoEnd > infoOff {
- sum := sha1.Sum(d.data[infoOff:infoEnd])
- ih.SetBytes(sum[:])
- }
- }
d.off++
+ rawEnd := d.off
+
+ if raw := v.FieldByName("Raw"); raw.IsValid() && rawEnd > rawStart {
+ raw.SetBytes(d.data[rawStart:rawEnd])
+ }
+
return nil
}