Exemplo n.º 1
0
py27plus = sys.version_info[:2] > (2, 6)  # type: bool

from M2Crypto import m2, six
if py27plus:
    from typing import AnyStr, Tuple, Union  # noqa
    # see https://github.com/python/typeshed/issues/222
    AddrType = Union[Tuple[str, int], str]

log = logging.getLogger('util')


class UtilError(Exception):
    pass


m2.util_init(UtilError)


def pkcs5_pad(data, blklen=8):
    # type: (str, int) -> str
    pad = (8 - (len(data) % 8))
    return data + chr(pad) * pad


def pkcs7_pad(data, blklen):
    # type: (str, int) -> str
    if blklen > 255:
        raise ValueError('illegal block size')
    pad = (blklen - (len(data) % blklen))
    return data + chr(pad) * pad
Exemplo n.º 2
0
from M2Crypto import m2

log = logging.getLogger('util')

# Python 2 has int() and long().
# Python 3 and higher only has int().
# Work around this.
if sys.version_info > (3,):
    long = int
    unicode = str


class UtilError(Exception):
    pass

m2.util_init(UtilError)


def pkcs5_pad(data, blklen=8):
    pad = (8 - (len(data) % 8))
    return data + chr(pad) * pad


def pkcs7_pad(data, blklen):
    if blklen > 255:
        raise ValueError('illegal block size')
    pad = (blklen - (len(data) % blklen))
    return data + chr(pad) * pad


def octx_to_num(x):