mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-30 09:48:56 +00:00
move utility functions to their own module, better docs on remote_prefix
This commit is contained in:
parent
44cddc2ee3
commit
a88b53825c
@ -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):]
|
34
src/allmydata/crypto/util.py
Normal file
34
src/allmydata/crypto/util.py
Normal file
@ -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):]
|
Loading…
Reference in New Issue
Block a user