'Given a (part of a) DER element, and an index to the first byte of
a DER length tag (L), return a tuple with the payload size,
and the index of the first byte of the such payload (V).
Raises a ValueError exception if the DER length is invalid.
Raises an IndexError exception if the DER element is too short.'

def _decodeLen(self, idx, der):

    length = bord(der[idx])
    if (length <= 127):
        return (length, (idx + 1))
    payloadLength = bytes_to_long(der[(idx + 1):((idx + 1) + (length & 127))])
    if (payloadLength <= 127):
        raise ValueError('Not    a    DER    length    tag.')
    return (payloadLength, ((idx + 1) + (length & 127)))
