ó
    Ë<iq  ã                   óÚ   • S r SSKrSSKr\R                  " S5      r\R                  " S5      r\R                  " S5      r\R                  " S5      rSS jr	S r
S	 rS
 rS rSS jrS rg)an  
Miscellaneous utility functions for working with tor.

.. versionadded:: 1.2.0

**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_valid_connection_id - checks if a string is a valid tor connection id
  is_valid_hidden_service_address - checks if a string is a valid hidden service address
  is_hex_digits - checks if a string is only made up of hex digits
é    Nz^[a-zA-Z0-9]{1,19}$z^[a-zA-Z0-9]{1,16}$z^[a-z2-7]{16}$z^[a-z2-7]{56}$c                 óò   • [        U [        5      (       a)  [        R                  R                  R                  U 5      n  U(       a  U (       a	  U S   S:w  a  gU SS n [        U S5      $ ! [         a     gf = f)aQ  
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.

:param str entry: string to be checked
:param bool check_prefix: checks for a '$' prefix

:returns: **True** if the string could be a relay fingerprint, **False** otherwise
r   Ú$Fé   Né(   )Ú
isinstanceÚbytesÚstemÚutilÚ	str_toolsÚ_to_unicodeÚis_hex_digitsÚ	TypeError)ÚentryÚcheck_prefixs     ÚM/home/james-whalen/.local/lib/python3.13/site-packages/stem/util/tor_tools.pyÚis_valid_fingerprintr   0   sm   € ô ”u×ÑÜI‰I×Ñ×+Ñ+¨EÓ2€Eð	ÞÞe˜A‘h #“oØàABˆi€eä˜ Ó#Ð#øÜ	ó Ùðús   Á A) ÁA) Á)
A6Á5A6c                 óÜ   • [        U [        5      (       a)  [        R                  R                  R                  U 5      n  [        [        R                  U 5      5      $ ! [         a     gf = f)z¯
Checks if a string is a valid format for being a nickname.

:param str entry: string to be checked

:returns: **True** if the string could be a nickname, **False** otherwise
F)
r   r   r	   r
   r   r   ÚboolÚNICKNAME_PATTERNÚmatchr   ©r   s    r   Úis_valid_nicknamer   K   sY   € ô ”u×ÑÜI‰I×Ñ×+Ñ+¨EÓ2€EðÜÔ ×&Ñ& uÓ-Ó.Ð.øÜ	ó Ùðúó   Á A Á
A+Á*A+c                 óÜ   • [        U [        5      (       a)  [        R                  R                  R                  U 5      n  [        [        R                  U 5      5      $ ! [         a     gf = f)z“
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
F)
r   r   r	   r
   r   r   r   ÚCIRC_ID_PATTERNr   r   r   s    r   Úis_valid_circuit_idr   ]   sX   € ô ”u×ÑÜI‰I×Ñ×+Ñ+¨EÓ2€EðÜ”×%Ñ% eÓ,Ó-Ð-øÜ	ó Ùðúr   c                 ó   • [        U 5      $ )zç
Checks if a string is a valid format for being a stream identifier.
Currently, this is just an alias to :func:`~stem.util.tor_tools.is_valid_circuit_id`.

:returns: **True** if the string could be a stream id, **False** otherwise
©r   r   s    r   Úis_valid_stream_idr   m   ó   € ô 
˜UÓ	#Ð#ó    c                 ó   • [        U 5      $ )zï
Checks if a string is a valid format for being a connection identifier.
Currently, this is just an alias to :func:`~stem.util.tor_tools.is_valid_circuit_id`.

:returns: **True** if the string could be a connection id, **False** otherwise
r   r   s    r   Úis_valid_connection_idr#   x   r    r!   c                 ó   • [        U [        5      (       a)  [        R                  R                  R                  U 5      n Uc  SnOU[        U[        5      (       a  U/nO<[        U[        [        45      (       d!  [        S[        U5      R                  -  5      e SU;   a$  [        [        R                  U 5      5      (       a  gSU;   a$  [        [        R                  U 5      5      (       a  gg! [          a     gf = f)að  
Checks if a string is a valid format for being a hidden service address (not
including the '.onion' suffix).

.. versionchanged:: 1.8.0
   Added the **version** argument, and responds with **True** if a version 3
   hidden service address rather than just version 2 addresses.

:param int,list version: versions to check for, if unspecified either v2 or v3
  hidden service address will provide **True**

:returns: **True** if the string could be a hidden service address, **False**
  otherwise
)é   é   z;Hidden service version must be an integer or list, not a %sr%   Tr&   F)r   r   r	   r
   r   r   ÚintÚlistÚtupleÚ
ValueErrorÚtypeÚ__name__r   ÚHS_V2_ADDRESS_PATTERNr   ÚHS_V3_ADDRESS_PATTERNr   )r   Úversions     r   Úis_valid_hidden_service_addressr0   ƒ   sÒ   € ô  ”u×ÑÜI‰I×Ñ×+Ñ+¨EÓ2€Eà_ØGÜ'œ3×ÑØˆiGÜg¤¤e˜}×-Ñ-Ü
ÐRÔUYÐZaÓUb×UkÑUkÑkÓ
lÐlð	ØˆGƒ|œÔ2×8Ñ8¸Ó?×@Ñ@ØàˆGƒ|œÔ2×8Ñ8¸Ó?×@Ñ@ØàøÜ	ó Ùðús   Â)C0 Ã)C0 Ã0
C=Ã<C=c                 ój   •  [        U 5      U:w  a  g[        U S5        g! [        [        4 a     gf = f)a  
Checks if a string is the given number of hex digits. Digits represented by
letters are case insensitive.

:param str entry: string to be checked
:param int count: number of hex digits to be checked for

:returns: **True** if the given number of hex digits, **False** otherwise
Fé   T)Úlenr'   r*   r   )r   Úcounts     r   r   r   ©   s9   € ðÜ
ˆ5ƒzUÓØäˆˆr„NØøÜ
”iÐ	 ó Ùðús   ‚ ’ Ÿ2±2)F)N)Ú__doc__ÚreÚstem.util.str_toolsr	   Úcompiler   r   r-   r.   r   r   r   r   r#   r0   r   © r!   r   Ú<module>r:      sy   ðñó$ 
ã ð —:’:Ð3Ó4Ð Ø—*’*Ð2Ó3€ð Ÿ
š
Ð#3Ó4Ð ØŸ
š
Ð#3Ó4Ð ôò6ò$ò $ò$ô#óLr!   