This will be useful when BitTorrent 2 is implemented, and helps with creating arbitrary Info.Pieces
// 20-byte SHA1 hash used for info and pieces.
// 20-byte SHA1 hash used for info and pieces.
+type Hash [HashSize]byte
func (h Hash) Bytes() []byte {
return h[:]
func (h Hash) Bytes() []byte {
return h[:]
}
func (h *Hash) FromHexString(s string) (err error) {
}
func (h *Hash) FromHexString(s string) (err error) {
+ if len(s) != 2*HashSize {
err = fmt.Errorf("hash hex string has bad length: %d", len(s))
return
}
err = fmt.Errorf("hash hex string has bad length: %d", len(s))
return
}
}
func (p Piece) Hash() (ret Hash) {
}
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])