-
Notifications
You must be signed in to change notification settings - Fork 53
Description
From BitTorrent's BEP 3, we need to calculate a hash of the info value (itself a bencoded dict) from a .torrent file:
Note that this is a substring of the metainfo file. The info-hash must be the hash of the encoded form as found in the .torrent file, which is identical to bdecoding the metainfo file, extracting the info dictionary and encoding it if and only if the bdecoder fully validated the input (e.g. key ordering, absence of leading zeros). Conversely that means clients must either reject invalid metainfo files or extract the substring directly. They must not perform a decode-encode roundtrip on invalid data.
Because info has optional fields like private, it's impossible to predictably unmarshal/marshal it to calculate the hash. It would be nice if there were a way to access the raw bytes of a bencoded value.