
    .`i"                        d dl mZ d dlZd dlZd dlmZmZ d dlmZ d dl	m
Z
 d dlZ	 d dlZ eed          sdZn# e$ r dZY nw xY wddZddZddZddZddZddZdddZdS )     )annotationsN)HASHUnsupportedDigestmodError)Callable)Anyxxh3_128_digestinputr   returnbytesc                    t          j        | t           j                  }t          j        |                                          S )u  Hash any picklable Python object using SHA-256.

    The input is serialized using pickle before hashing, which allows
    arbitrary Python objects to be used. Note that this function does
    not use a hash seed—if you need one, prepend it explicitly to the input.

    Args:
        input: Any picklable Python object.

    Returns:
        Bytes representing the SHA-256 hash of the serialized input.
    protocol)pickledumpsHIGHEST_PROTOCOLhashlibsha256digestr	   input_bytess     f/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/vllm/utils/hashing.pyr   r      s7     ,uv/FGGGK>+&&--///    c                z    t          j        | d          }t          j        |                                          S )a  Hash objects using CBOR serialization and SHA-256.

    This option is useful for non-Python-dependent serialization and hashing.

    Args:
        input: Object to be serialized and hashed. Supported types include
            basic Python types and complex structures like lists, tuples, and
            dictionaries.
            Custom classes must implement CBOR serialization methods.

    Returns:
        Bytes representing the SHA-256 hash of the CBOR serialized input.
    T	canonical)cbor2r   r   r   r   r   s     r   sha256_cborr   +   s4     +et444K>+&&--///r   r   c                V    t           t          d          t          j        |           S )Nzhxxhash is required for the 'xxhash' prefix caching hash algorithms. Install it via `pip install xxhash`.)_xxhashModuleNotFoundErrorr   )r   s    r   _xxhash_digestr!   =   s1    !3
 
 	
 ";///r   c                `    t          j        | t           j                  }t          |          S )z$Hash picklable objects using xxHash.r   )r   r   r   r!   r   s     r   xxhashr#   F   s'    ,uv/FGGGK+&&&r   c                L    t          j        | d          }t          |          S )z/Hash objects serialized with CBOR using xxHash.Tr   )r   r   r!   r   s     r   xxhash_cborr%   L   s$    +et444K+&&&r   hash_fn_namestrCallable[[Any], bytes]c                    | dk    rt           S | dk    rt          S | dk    rt          S | dk    rt          S t	          d|            )zGet a hash function by name, or raise an error if the function is not found.

    Args:
        hash_fn_name: Name of the hash function.

    Returns:
        A hash function.
    r   r   r#   r%   zUnsupported hash function: )r   r   r#   r%   
ValueError)r&   s    r   get_hash_fn_by_namer+   R   s]     x}$$x}$$
A<AA
B
BBr   Tdatausedforsecurityboolr   c                    	 t          j        | |          S # t          t          f$ r t          j        |           cY S w xY w)zHash for configs, defaulting to md5 but falling back to sha256
    in FIPS constrained environments.

    Args:
        data: bytes
        usedforsecurity: Whether the hash is used for security purposes

    Returns:
        Hash object
    )r-   )r   md5r   r*   r   )r,   r-   s     r   	safe_hashr1   g   sR    ${4AAAA%z2 $ $ $~d#####$s    %A A )r	   r   r
   r   )r   r   r
   r   )r&   r'   r
   r(   )T)r,   r   r-   r.   r
   r   )
__future__r   r   r   _hashlibr   r   collections.abcr   typingr   r   r#   r   hasattrImportErrorr   r   r!   r%   r+   r1    r   r   <module>r9      sa   # " " " " "   4 4 4 4 4 4 4 4 $ $ $ $ $ $       	 77-..    GGG0 0 0 0"0 0 0 0$0 0 0 0' ' ' '' ' ' 'C C C C*$ $ $ $ $ $ $s   ; AA