make infohash and peerID byte arrays (#169)

This commit is contained in:
mrd0ll4r
2016-05-16 23:48:23 -04:00
committed by Jimmy Zelinskie
parent a081e5195b
commit 7f16c55d81
16 changed files with 113 additions and 46 deletions

View File

@@ -20,6 +20,10 @@ import (
// it.
var ErrKeyNotFound = errors.New("query: value for the provided key does not exist")
// ErrInvalidInfohash is returned when parsing a query encounters an infohash
// with invalid length.
var ErrInvalidInfohash = errors.New("query: invalid infohash")
// Query represents a parsed URL.Query.
type Query struct {
query string
@@ -71,7 +75,10 @@ func New(query string) (*Query, error) {
}
if keyStr == "info_hash" {
q.infoHashes = append(q.infoHashes, chihaya.InfoHash(valStr))
if len(valStr) != 20 {
return nil, ErrInvalidInfohash
}
q.infoHashes = append(q.infoHashes, chihaya.InfoHashFromString(valStr))
} else {
q.params[strings.ToLower(keyStr)] = valStr
}