getTagLong :: Get ASN1Tag
getTagLong = do
    t <- fromIntegral <$> getWord8
    when (t == 0x80) $ error "not canonical encoding of tag"
    if testBit t 7
        then loop (clearBit t 7)
        else return t
  where loop n = do
            t <- fromIntegral <$> getWord8
            if testBit t 7
                then loop (n `shiftL` 7 + clearBit t 7)
                else return (n `shiftL` 7 + t)


{- get the asn1 length which is either short form if 7th bit is not set,
 - indefinite form is the 7 bit is set and every other bits clear,
 - or long form otherwise, where the next bytes will represent the length
 -}
getTagLong :: Get ASN1Tag
getTagLong = do
    t <- fromIntegral <$> getWord8
    when (t == 0x80) $ error "not canonical encoding of tag"
    if testBit t 7
        then loop (clearBit t 7)
        else return t
  where loop n = do
            t <- fromIntegral <$> getWord8
            if testBit t 7
                then loop (n `shiftL` 7 + clearBit t 7)
                else return (n `shiftL` 7 + t)


{- get the asn1 length which is either short form if 7th bit is not set,
 - indefinite form is the 7 bit is set and every other bits clear,
 - or long form otherwise, where the next bytes will represent the length
 -}
getTagLong = do
    t <- fromIntegral <$> getWord8
    when (t == 0x80) $ error "not canonical encoding of tag"
    if testBit t 7
        then loop (clearBit t 7)
        else return t
  where loop n = do
            t <- fromIntegral <$> getWord8
            if testBit t 7
                then loop (n `shiftL` 7 + clearBit t 7)
                else return (n `shiftL` 7 + t)


{- get the asn1 length which is either short form if 7th bit is not set,
 - indefinite form is the 7 bit is set and every other bits clear,
 - or long form otherwise, where the next bytes will represent the length
 -}