This will be useful when BitTorrent 2 is implemented, and helps with creating arbitrary Info.Pieces
"fmt"
)
+const HashSize = 20
+
// 20-byte SHA1 hash used for info and pieces.
-type Hash [20]byte
+type Hash [HashSize]byte
func (h Hash) Bytes() []byte {
return h[:]
}
func (h *Hash) FromHexString(s string) (err error) {
- if len(s) != 40 {
+ if len(s) != 2*HashSize {
err = fmt.Errorf("hash hex string has bad length: %d", len(s))
return
}
if err != nil {
return
}
- if n != 20 {
+ if n != HashSize {
panic(n)
}
return
}
func (p Piece) Hash() (ret Hash) {
- missinggo.CopyExact(&ret, p.Info.Pieces[p.i*20:(p.i+1)*20])
+ missinggo.CopyExact(&ret, p.Info.Pieces[p.i*HashSize:(p.i+1)*HashSize])
return
}