private int GetLengthOfHeader(
byte[] data)
{
int length = data[1]; // TODO: assumes 1 byte tag
if (length == 0x80)
{
return 2; // indefinite-length encoding
}
if (length > 127)
{
int size = length & 0x7f;
// Note: The invalid long form "0xff" (see X.690 8.1.3.5c) will be caught here
if (size > 4)
{
throw new InvalidOperationException("DER length more than 4 bytes: " + size);
}
return size + 2;
}
return 2;
}