def pkcs7_verify(seq, blocklen):
    """Verifies that seq is a properly padded PKCS#7 sequence"""
    assert(type(seq) == bytes)
    padlen = seq[-1]
    return (len(seq) % blocklen == 0) \
           and len(seq) >= padlen \
           and all(map(lambda x: x == padlen, seq[-padlen:]))