Remove the pad from the *line*.
(line: bytes)
| 236 | |
| 237 | |
| 238 | def _remove_pad(line: bytes) -> bytes | Literal[False]: |
| 239 | """Remove the pad from the *line*.""" |
| 240 | try: |
| 241 | # Determine pad length. |
| 242 | pad_length = ord(line[-1:]) |
| 243 | except TypeError: |
| 244 | # ord() was unable to get the value of the byte. |
| 245 | logger.warning("Unable to remove pad.") |
| 246 | return False |
| 247 | |
| 248 | if pad_length > len(line) or len(set(line[-pad_length:])) != 1: |
| 249 | # Pad length should be less than or equal to the length of the |
| 250 | # plaintext. The pad should have a single unique byte. |
| 251 | logger.warning("Invalid pad found in login path file.") |
| 252 | return False |
| 253 | |
| 254 | return line[:-pad_length] |