
    E#i                     X    S r SSKrSSKJrJr  SSKJr  SSKJr  SSKJ	r	   " S	 S
5      r
g)z)Module with some bytes utility functions.    N)ListUnion   )	AlgoUtils)IntegerUtils   )Literalc            
          \ rS rSrSr\S\S\4S j5       r\S\S\S\4S j5       r\S\S\S\4S	 j5       r	\S\S
\
S\4S j5       r\ SS\S\
S\4S jj5       r\  SS\S\S   S\S\
4S jj5       r\ SS\\\4   S\
S\4S jj5       r\ SS\S\S\4S jj5       r\S\\\4   S\4S j5       r\S\\
   S\4S j5       r\S\S\\
   4S j5       rSrg) 
BytesUtils    z,Class container for bytes utility functions.
data_bytesreturnc                 N    [        U 5      nUR                  5         [        U5      $ )z
Reverse the specified bytes.

Args:
    data_bytes (bytes): Data bytes

Returns:
    bytes: Original bytes in the reverse order
)	bytearrayreversebytes)r   tmps     g/home/james-whalen/.local/lib/python3.13/site-packages/ccxt/static_dependencies/bip/utils/misc/bytes.pyReverseBytesUtils.Reverse#   s!     
#Sz    data_bytes_1data_bytes_2c                 d    [        [        X5       VVs/ s H	  u  p#X#-  PM     snn5      $ s  snnf )z
XOR the specified bytes.

Args:
    data_bytes_1 (bytes): Data bytes 1
    data_bytes_2 (bytes): Data bytes 2

Returns:
    bytes: XORed bytes
r   zipr   r   b1b2s       r   XorBytesUtils.Xor2   s1     #&|#BC#BRW#BC
 	
Cs   ,
c                 j    [        [        X5       VVs/ s H  u  p#X#-   S-  PM     snn5      $ s  snnf )z
Add the specified bytes (byte-by-byte, no carry).

Args:
    data_bytes_1 (bytes): Data bytes 1
    data_bytes_2 (bytes): Data bytes 2

Returns:
    bytes: XORed bytes
   r   r   s       r   
AddNoCarryBytesUtils.AddNoCarryC   s6     ,/,KL,K&"bg,KL
 	
Ls   /
scalarc                 N    [        U  Vs/ s H
  o"U-  S-  PM     sn5      $ s  snf )z
Multiply the specified bytes with the specified scalar (byte-by-byte, no carry).

Args:
    data_bytes (bytes): Data bytes
    scalar (int)      : Scalar

Returns:
    bytes: XORed bytes
r#   r   )r   r&   bs      r   MultiplyScalarNoCarry BytesUtils.MultiplyScalarNoCarryT   s-     *45*Q&jD *5
 	
5s   "zero_pad_bit_lenc                 V    [         R                  " [        R                  U 5      U5      $ )z
Convert the specified bytes to a binary string.

Args:
    data_bytes (bytes)              : Data bytes
    zero_pad_bit_len (int, optional): Zero pad length in bits, 0 if not specified

Returns:
    str: Binary string
)r   ToBinaryStrr   	ToInteger)r   r,   s     r   r.   BytesUtils.ToBinaryStre   s#     ''
(<(<Z(HJZ[[r   
endianness)littlebigsignedc                 *    [         R                  XUS9$ )a:  
Convert the specified bytes to integer.

Args:
    data_bytes (bytes)                      : Data bytes
    endianness ("big" or "little", optional): Endianness (default: big)
    signed (bool, optional)                 : True if signed, false otherwise (default: false)

Returns:
    int: Integer representation
)	byteorderr4   )int
from_bytes)r   r1   r4   s      r   r/   BytesUtils.ToIntegert   s     ~~jv~NNr   datazero_pad_byte_lenc                     [         R                  " [        [        R                  " U 5      5      SS R                  U5      5      $ )z
Convert the specified binary string to bytes.

Args:
    data (str or bytes)              : Data
    zero_pad_byte_len (int, optional): Zero pad length in bytes, 0 if not specified

Returns:
    bytes: Bytes representation
r   N)binascii	unhexlifyhexr   FromBinaryStrzfill)r:   r;   s     r   r@   BytesUtils.FromBinaryStr   s8     !!#l&@&@&F"G"K"Q"QRc"deer   encodingc                 X    [         R                  " [        R                  " U 5      U5      $ )z
Convert bytes to hex string.

Args:
    data_bytes (bytes)      : Data bytes
    encoding (str, optional): Encoding type, utf-8 by default

Returns:
    str: Bytes converted to hex string
)r   Decoder=   hexlify)r   rC   s     r   ToHexStringBytesUtils.ToHexString   s"      0 0 <hGGr   c                 V    [         R                  " [        R                  " U 5      5      $ )z{
Convert hex string to bytes.

Args:
    data (str or bytes): Data bytes

Returns
    bytes: Hex string converted to bytes
)r=   r>   r   Encode)r:   s    r   FromHexStringBytesUtils.FromHexString   s      !!)"2"24"899r   	data_listc                     [        U 5      $ )z
Convert the specified list of integers to bytes.

Args:
    data_list (list[int]): List of integers

Returns:
    bytes: Bytes representation
r(   )rM   s    r   FromListBytesUtils.FromList   s     Yr   c                     [        U 5      $ )z
Convert the specified bytes to a list of integers.

Args:
    data_bytes (bytes): Data bytes

Returns:
    list[int]: List of integers
)list)r   s    r   ToListBytesUtils.ToList   s     Jr    N)r   )r3   F)zutf-8)__name__
__module____qualname____firstlineno____doc__staticmethodr   r   r    r$   r7   r*   strr.   r	   boolr/   r   r@   rG   rK   r   rO   rS   __static_attributes__rU   r   r   r   r       s   6E e   
% 

$)
 
  
 
!&
+0
 
  
% 
&)
.3
 
  ,-\ \&)\25\ \ 9>!&Oe O%o6OO+.O O  /0fE%*- f),f5:f f $+H H!H03H H 
:E%*- 
:% 
: 
: 
 DI 
 % 
  
  
 5 
 T#Y 
  
 r   r   )rZ   r=   typingr   r   algor   integerr   r	   r   rU   r   r   <module>rb      s'   * 0    ! h  h r   