How to use the padding.PKCS1_v15.MIN_PAD_LEN function in Padding

To help you get started, we’ve selected a few Padding examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github alexmgr / pybleach / padding.py View on Github external
Traceback (most recent call last):
    ValueError: Cleartext too long to be conforming: max => 5 bytes, provided => 6 bytes
    >>> m = pad.conforming_message("12345")
    >>> m.startswith("\x00\x02")
    True
    >>> "\x00" not in m[2:10]
    True
    >>> "\x00" in m[10:]
    True
    >>> m[-6] == "\x00"
    True
    >>> m[-5:] == "12345"
    True
    """
    padding_len = self.k - len(data) - len(PKCS1_v15.HEADER) - len(PKCS1_v15.DELIMITER)
    if padding_len < PKCS1_v15.MIN_PAD_LEN:
      raise ValueError("Cleartext too long to be conforming: max => %i bytes, provided => %i bytes" % (self.k - PKCS1_v15.MIN_LEN, len(data)))
    random_padding = self.get_random_padding(padding_len)
    return PKCS1_v15.HEADER + random_padding + PKCS1_v15.DELIMITER + data