Do you need space padding with that bitstring
I'm working with a non text based protocol in perl, so pack/unpack to the rescue. The pack/unpack functions is one of the most overlooked pieces of perl. It can some pretty nice stuff, but it makes mod_rewrite look easy.
As part of a challenge/response one of the fields in the packet type I'm interested in is a length encoded sha1 sum. A length encoded value consists of the length of the value and then the value itself. A sha1-sum is always 20 bytes long but I guess it is some sort of backwards compatibility.
Looking at the documentation this can be solved by something like unpack("C/A*",$packet);
. Which means "a byte which is the length of a variable length string". And it works ... as long my challenge stays the same. Otherwise something fails roughly 1/50 of the times.
Actually A*
isn't just a variable length string, but a space padded variable length string. So unpack ignores any spaces at the end.
Took me some time to find this bug...