Returns the input followed by enough zero bytes to become the requested length. Args: data: The data to pad. length: The length of the returned data. Returns: The padded data. Raises: ValueError: If the requested length is less than the input length.
(data: bytes, length: int)
| 8 | |
| 9 | |
| 10 | def pad_to(data: bytes, length: int) -> bytes: |
| 11 | """Returns the input followed by enough zero bytes to become the requested length. |
| 12 | |
| 13 | Args: |
| 14 | data: The data to pad. |
| 15 | length: The length of the returned data. |
| 16 | Returns: |
| 17 | The padded data. |
| 18 | Raises: |
| 19 | ValueError: If the requested length is less than the input length. |
| 20 | """ |
| 21 | if length < len(data): |
| 22 | raise ValueError(f"Data length {len(data)} > padded length {length}") |
| 23 | if length > len(data): |
| 24 | data = data + b"\x00" * (length - len(data)) |
| 25 | assert len(data) == length |
| 26 | return data |
| 27 | |
| 28 | |
| 29 | def padding_required(offset: int, alignment: int) -> int: |
no outgoing calls
no test coverage detected