
    ^j                    L    d Z ddlmZ ddlZddlZddlZddlZddZddZd	dZ	y)
a  Studio access tokens: HMAC(design name) under a server-held secret.

Only the server can mint them (STUDIO_SECRET lives in .env and never leaves
the box); the Telegram bot embeds one in each customer's studio link. A token
unlocks exactly one design's data and files; the admin token ("__admin__")
unlocks the internal review/eval pages.

If STUDIO_SECRET is missing on first run, serve.py generates one and appends
it to .env. Without a secret set, auth is OPEN (local development).
    )annotationsNc                 B    t         j                  j                  dd      S )NSTUDIO_SECRET )osenvironget     !/opt/ringagent/harness/authtok.pysecretr      s    ::>>/2..r   c                0   t               syt        j                  t               j                         | j                         t        j
                        j                         }t        j                  |      j                         j                  d      d d S )Nr   =   )r   hmacnewencodehashlibsha256digestbase64urlsafe_b64encodedecoderstrip)designmacs     r   
make_tokenr      sd    8
((68??$fmmow~~
F
M
M
OC##C(//188=crBBr   c                    t               sy|syt        |       t        d      fD ]  }|st        j                  ||      s y y)NTF	__admin__)r   r   r   compare_digest)r   tokenwants      r   token_okr#      sH    8F#Z%<= D''e4 r   )returnstr)r   r%   r$   r%   )r   r%   r!   z
str | Noner$   bool)
__doc__
__future__r   r   r   r   r   r   r   r#   r
   r   r   <module>r)      s+   	 #    	/Cr   