Fix parsing of long format DER octet string.

When parsing a DER octet string of more than 128 bytes, the "long format"
flag, which is the most significant bit, is set on the length byte. When
Java does a signed upcast from byte to int, it sign extends it and all
the high bits are set. This causes to width to be negative.

Use readNumber instead which takes care of the upcast properly.
Also adds test to verify the behaviour.

Change-Id: I6f700ac2970eac4bd7e18ed0776d64cb91277acd
2 files changed