§
    0büi‚  ã                  ó6   — d Z ddlmZ ddlZddlZd
d„Zdd	„ZdS )zHAES-256-GCM utilities for QQBot scan-to-configure credential decryption.é    )ÚannotationsNÚreturnÚstrc                 ór   — t          j        t          j        d¦  «        ¦  «                             ¦   «         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© ó    ú</DATA/AppData/hermes-agent/gateway/platforms/qqbot/crypto.pyÚgenerate_bind_keyr   	   s)   € õ ÔBœJ r™NœNÑ+Ô+×2Ò2Ñ4Ô4Ð4r   Úencrypted_base64Ú
key_base64c                óô   — ddl m} t          j        |¦  «        }t          j        | ¦  «        }|dd…         }|dd…         } ||¦  «        }|                     ||d¦  «        }|                     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   )	r   r   r   ÚkeyÚrawÚivÚciphertext_with_tagÚaesgcmÚ	plaintexts	            r   Údecrypt_secretr      sŠ   € ð  CÐBÐBÐBÐBÐBå
Ô
˜:Ñ
&Ô
&€CÝ
Ô
Ð+Ñ
,Ô
,€Cà	ˆSˆbˆSŒ€BØ˜b˜c˜cœ(ÐàˆVC‰[Œ[€FØ—’˜rÐ#6¸Ñ=Ô=€IØ×Ò˜GÑ$Ô$Ð$r   )r   r   )r   r   r   r   r   r   )Ú__doc__Ú
__future__r   r   r
   r   r   r   r   r   ú<module>r"      sa   ðØ NÐ Nà "Ð "Ð "Ð "Ð "Ð "à €€€Ø 	€	€	€	ð5ð 5ð 5ð 5ð%ð %ð %ð %ð %ð %r   