diff --git a/src/allmydata/crypto/__init__.py b/src/allmydata/crypto/__init__.py index 4ce95a24d..e69de29bb 100644 --- a/src/allmydata/crypto/__init__.py +++ b/src/allmydata/crypto/__init__.py @@ -1,21 +0,0 @@ -class BadSignature(Exception): - """ - An alleged signature did not match - """ - - -class BadPrefixError(Exception): - """ - A key did not start with the required prefix - """ - - -def remove_prefix(s_bytes, prefix): - """ - Removes `prefix` from `s_bytes` safely - """ - if not s_bytes.startswith(prefix): - raise BadPrefixError( - "did not see expected '{}' prefix".format(prefix) - ) - return s_bytes[len(prefix):] diff --git a/src/allmydata/crypto/util.py b/src/allmydata/crypto/util.py new file mode 100644 index 000000000..571f55387 --- /dev/null +++ b/src/allmydata/crypto/util.py @@ -0,0 +1,34 @@ +""" +Utilities used by allmydata.crypto modules +""" + + +class BadSignature(Exception): + """ + An alleged signature did not match + """ + + +class BadPrefixError(Exception): + """ + A key did not start with the required prefix + """ + + +def remove_prefix(s_bytes, prefix): + """ + :param bytes s_bytes: a string of bytes whose prefix is removed + + :param bytes prefix: the bytes to remove from the beginning of `s_bytes` + + Removes `prefix` from `s_bytes` and returns the new bytes or + raises `BadPrefixError` if `s_bytes` did not start with the + `prefix` specified. + + :returns: `s_bytes` with `prefix` removed from the front. + """ + if not s_bytes.startswith(prefix): + raise BadPrefixError( + "did not see expected '{}' prefix".format(prefix) + ) + return s_bytes[len(prefix):]