Stem Docs

Tor Utilities

Tor Utilities

Miscellaneous utility functions for working with tor.

These functions are not being vended to stem users. They may change in the future, use them at your own risk.

Module Overview:

is_valid_fingerprint - checks if a string is a valid tor relay fingerprint
is_valid_nickname - checks if a string is a valid tor relay nickname
is_valid_circuit_id - checks if a string is a valid tor circuit id
is_valid_stream_id - checks if a string is a valid tor stream id
is_hex_digits - checks if a string is only made up of hex digits
stem.util.tor_tools.is_valid_fingerprint(entry, check_prefix=False)[source]

Checks if a string is a properly formatted relay fingerprint. This checks for a ‘$’ prefix if check_prefix is true, otherwise this only validates the hex digits.

Parameters:
  • entry (str) – string to be checked
  • check_prefix (bool) – checks for a ‘$’ prefix
Returns:

True if the string could be a relay fingerprint, False otherwise

stem.util.tor_tools.is_valid_nickname(entry)[source]

Checks if a string is a valid format for being a nickname.

Parameters:entry (str) – string to be checked
Returns:True if the string could be a nickname, False otherwise
stem.util.tor_tools.is_valid_circuit_id(entry)[source]

Checks if a string is a valid format for being a circuit identifier.

Returns:True if the string could be a circuit id, False otherwise
stem.util.tor_tools.is_valid_stream_id(entry)[source]

Checks if a string is a valid format for being a stream identifier. Currently, this is just an alias to is_valid_circuit_id().

Returns:True if the string could be a stream id, False otherwise
stem.util.tor_tools.is_hex_digits(entry, count)[source]

Checks if a string is the given number of hex digits. Digits represented by letters are case insensitive.

Parameters:
  • entry (str) – string to be checked
  • count (int) – number of hex digits to be checked for
Returns:

True if the string matches this number