source: trunk/src/allmydata/crypto/util.py

Last change on this file was 1cfe843d, checked in by Alexandre Detiste <alexandre.detiste@…>, at 2024-02-22T23:40:25Z

more python2 removal

  • Property mode set to 100644
File size: 704 bytes
Line 
1"""
2Utilities used by allmydata.crypto modules
3
4Ported to Python 3.
5"""
6
7from allmydata.crypto.error import BadPrefixError
8
9
10def remove_prefix(s_bytes, prefix):
11    """
12    :param bytes s_bytes: a string of bytes whose prefix is removed
13
14    :param bytes prefix: the bytes to remove from the beginning of `s_bytes`
15
16    Removes `prefix` from `s_bytes` and returns the new bytes or
17    raises `BadPrefixError` if `s_bytes` did not start with the
18    `prefix` specified.
19
20    :returns: `s_bytes` with `prefix` removed from the front.
21    """
22    if s_bytes.startswith(prefix):
23        return s_bytes[len(prefix):]
24    raise BadPrefixError(
25        "did not see expected '{!r}' prefix".format(prefix)
26    )
Note: See TracBrowser for help on using the repository browser.