getLength :: Get ASN1Length
getLength = do
    l1 <- fromIntegral <$> getWord8
    if testBit l1 7
        then case clearBit l1 7 of
            0   -> return LenIndefinite
            len -> do
                lw <- getBytes len
                return (LenLong len $ uintbs lw)
        else
            return (LenShort l1)
  where
        {- uintbs return the unsigned int represented by the bytes -}
        uintbs = B.foldl (\acc n -> (acc `shiftL` 8) + fromIntegral n) 0

-- | putIdentifier encode an ASN1 Identifier into a marshalled value
getLength :: Get ASN1Length
getLength = do
    l1 <- fromIntegral <$> getWord8
    if testBit l1 7
        then case clearBit l1 7 of
            0   -> return LenIndefinite
            len -> do
                lw <- getBytes len
                return (LenLong len $ uintbs lw)
        else
            return (LenShort l1)
  where
        {- uintbs return the unsigned int represented by the bytes -}
        uintbs = B.foldl (\acc n -> (acc `shiftL` 8) + fromIntegral n) 0

-- | putIdentifier encode an ASN1 Identifier into a marshalled value
getLength = do
    l1 <- fromIntegral <$> getWord8
    if testBit l1 7
        then case clearBit l1 7 of
            0   -> return LenIndefinite
            len -> do
                lw <- getBytes len
                return (LenLong len $ uintbs lw)
        else
            return (LenShort l1)
  where
        {- uintbs return the unsigned int represented by the bytes -}
        uintbs = B.foldl (\acc n -> (acc `shiftL` 8) + fromIntegral n) 0

-- | putIdentifier encode an ASN1 Identifier into a marshalled value