On Sat, Sep 20, 2008 at 10:53 PM, Sandro Noel <[EMAIL PROTECTED]> wrote: > Greetings. > > i'm playing around with the torrent specification. and i'm trying to talk to > a tracker. > for that i need to generate an info_hash > acording to the protocol definition the string needs to be escaped. > > The 20 byte sha1 hash of the bencoded form of the info value from the > metainfo file. Note that this is a substring of the metainfo file. This > value will almost certainly have to be escaped.
This is an assumption which happens not to be true. Your problem is in thinking of a .torrent file as a string. It is not. It is a plain old sequence of bytes, with no encoding. The sha1 hash data is embedded raw, right in the file. No escaping is done, because there is no need: the length of the data is given in the file. Note that documentation which discusses bencode generally talks about "strings". But don't be confused. They correspond to NSData, not to NSString. I also want to point out that your question, aside from not applying to the given situation, is also somewhat ill-founded. The reason for this is that "string escaping" is a very vague concept that is not well defined. The escaping used for URLs is completely different from the escaping used for C constant strings, and that in turn is different from the escaping used for passing arguments to a command in the shell, and all of those are different from the escaping needed for regular expressions. (And the necessary escaping can depend on what flavor of regex!) There are so many different ways to escape strings that it makes little sense to just choose one arbitrarily in an attempt to make things work. Find out exactly what kind of escaping is needed by the protocol or format you're using, and then use *that* kind of escaping. Or in this case, don't use any. Mike _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]