'Remove the trailing padding, using what appears to be the CMS
algorithm from RFC 5652 6.3'

def __removeaespadding(self, contents):

    lastchar = binascii.b2a_hex(contents[(-1):])
    strlen = int(lastchar, 16)
    padding = strlen
    if (strlen == 1):
        return contents[:(-1)]
    if (strlen < 16):
        for i in range(strlen):
            testchar = binascii.b2a_hex(contents[(- strlen):(- (strlen - 1))])
            if (testchar != lastchar):
                padding = 0
    if (padding > 0):
        contents = contents[:(- padding)]
    return contents
