
    `gj                    4    d Z ddlmZ ddlZddlZddZddZy)zHAES-256-GCM utilities for QQBot scan-to-configure credential decryption.    )annotationsNc                 n    t        j                  t        j                  d            j	                         S )a  Generate a 256-bit random AES key and return it as base64.

    The key is passed to ``create_bind_task`` so the server can encrypt
    the bot's *client_secret* before returning it.  Only this CLI holds
    the key, ensuring the secret never travels in plaintext.
        )base64	b64encodeosurandomdecode     Q/root/.hermes/venv/lib/python3.12/site-packages/gateway/platforms/qqbot/crypto.pygenerate_bind_keyr   	   s&     BJJrN+2244r   c                    ddl m} t        j                  |      }t        j                  |       }|dd }|dd } ||      }|j	                  ||d      }|j                  d      S )u  Decrypt a base64-encoded AES-256-GCM ciphertext.

    Ciphertext layout (after base64-decoding)::

        IV (12 bytes) ‖ ciphertext (N bytes) ‖ AuthTag (16 bytes)

    Args:
        encrypted_base64: The ``bot_encrypt_secret`` value from
            ``poll_bind_result``.
        key_base64: The base64 AES key generated by
            :func:`generate_bind_key`.

    Returns:
        The decrypted *client_secret* as a UTF-8 string.
    r   )AESGCMN   zutf-8)+cryptography.hazmat.primitives.ciphers.aeadr   r   	b64decodedecryptr
   )	encrypted_base64
key_base64r   keyrawivciphertext_with_tagaesgcm	plaintexts	            r   decrypt_secretr      sm      C


:
&C


+
,C	SbBbc(C[Fr#6=IG$$r   )returnstr)r   r   r   r   r   r   )__doc__
__future__r   r   r   r   r   r   r   r   <module>r"      s    N "  	5%r   