
    <[j]                        d dl Z d dlZd dlZd dlmZ d dlmZ d dlmZ d dl	m
Z
 ddlmZ 	 d dlZn# e$ r Y nw xY w	 ddlmZ n# e$ r Y nw xY w e            j        Zed	             Z G d
 dej                  Z G d de          ZdS )    N)
properties)ExceptionTrap)KeyringBackend)PasswordDeleteError   )	file_base)_win_cryptoc                      t           j         dS )z
    Does this environment have wincrypto?
    Should return False even when Mercurial's Demand Import allowed import of
    _win_crypto, so accesses an attribute of the module.
    N)r	   __name__     \/home/thesage/.hermes/hermes-agent/venv/lib/python3.11/site-packages/keyrings/alt/Windows.pyhas_wincryptor      s     r   c                   J    e Zd ZdZdZej        d             ZdZddZ	ddZ
dS )	EncryptedKeyringz=
    A File-based keyring secured by Windows Crypto API.
    z1.0c                 R    t          j                    dk    st          d          dS )zr
        Preferred over file.EncryptedKeyring but not other, more sophisticated
        Windows backends.
        WindowsRequires Windowsg?)platformsystemRuntimeErrorselfs    r   priorityzEncryptedKeyring.priority,   s+       I--1222sr   zwincrypto_pass.cfgNc                 *    t          j        |          S )z(Encrypt the password using the CryptAPI.)r	   encrypt)r   passwordassocs      r   r   zEncryptedKeyring.encrypt8   s    "8,,,r   c                 *    t          j        |          S )z(Decrypt the password using the CryptAPI.)r	   decrypt)r   password_encryptedr   s      r   r    zEncryptedKeyring.decrypt<   s    "#5666r   )N)r   
__module____qualname____doc__versionr   classpropertyr   filenamer   r    r   r   r   r   r   %   sq          G   $H- - - -7 7 7 7 7 7r   r   c                   `    e Zd ZdZej        d             Zed             Zd Z	d Z
d Zd ZdS )	RegistryKeyringz
    RegistryKeyring is a keyring which use Windows CryptAPI to encrypt
    the user's passwords and store them under registry keys
    c                     t          j                    dk    rt          d          t                      st          d          dS )zC
        Preferred on Windows when pywin32 isn't installed
        r   r   zRequires ctypes   )r   r   r   r   r   s    r   r   zRegistryKeyring.priorityG   sF    
 ?	))1222 	20111qr   c                 `    |                      dd          } dj        di t                      S )N\__0x5c__zSoftware\{escaped}\Keyringr   )replaceformatlocals)serviceescapeds     r   _key_for_servicez RegistryKeyring._key_for_serviceR   s3    //$
333,3??fhh???r   c                 l   	 |                      |          }t          j        t          j        |          }t          j        ||          d         }|                    d          }t          j        |          }t          j	        |          
                    d          }n# t          $ r d}Y nw xY w|S )z,Get password of the username for the servicer   asciiutf-8N)r4   winregOpenKeyHKEY_CURRENT_USERQueryValueExencodebase64decodebytesr	   r    decodeOSError)	r   r2   usernamekeyhkeypassword_savedpassword_base64r!   r   s	            r   get_passwordzRegistryKeyring.get_passwordW   s    	''00C>&":C@@D#0x@@CN,33G<<O!'!3O!D!D"*+=>>EEgNNHH 	 	 	HHH	s   BB" "B10B1c                 R   t          j        |                    d                    }t          j        |          }|                    d          }|                     |          }t          j        t          j	        |          }t          j
        ||dt          j        |           dS )z"Write the password to the registryr7   r6   r   N)r	   r   r<   r=   encodebytesr?   r4   r8   	CreateKeyr:   
SetValueExREG_SZ)	r   r2   rA   r   r!   rE   rD   key_namerC   s	            r   set_passwordzRegistryKeyring.set_passwordg   s     )01I1IJJ ,-?@@(//88 ((11 8(CC$!V]NKKKKKr   c                 r   	 |                      |          }t          j        t          j        |dt          j                  }t          j        ||           t          j        |           n6# t          $ r) t          j	                    d         }t          |          w xY w|                     |           dS )z4Delete the password for the username of the service.r   r   N)r4   r8   r9   r:   KEY_ALL_ACCESSDeleteValueCloseKeyr@   sysexc_infor   _delete_key_if_empty)r   r2   rA   rL   rC   es         r   delete_passwordzRegistryKeyring.delete_passwordu   s    		),,W55H>((Av7L D tX...OD!!!! 	) 	) 	)q!A%a(((	) 	!!'*****s   A)A, ,3Bc                    |                      |          }t          j        t          j        |dt          j                  }	 t          j        |d           d S # t          $ r Y nw xY wt          j        |           |dk    rw|                    d          \  }}}t          j        t          j        |dt          j                  }t          j	        ||           t          j        |           |}|dk    ud S d S )Nr   Softwarer-   )
r4   r8   r9   r:   rO   	EnumValuer@   rQ   
rpartition	DeleteKey)r   r2   rL   rB   parentsepbases          r   rT   z$RegistryKeyring._delete_key_if_empty   s   ((11n$h63H
 
	S!$$$F 	 	 	D	 *$$ ( 3 3D 9 9FC.(&!V5J C S$'''OC   H *$$$$$$s   A 
A&%A&N)r   r"   r#   r$   r   r&   r   staticmethodr4   rF   rM   rV   rT   r   r   r   r)   r)   A   s         
    @ @ \@   L L L+ + +    r   r)   )r=   r   rR   jaraco.classesr   jaraco.contextr   keyring.backendr   keyring.errorsr    r   r8   ImportErrorr	   passesr   Keyringr   r)   r   r   r   <module>rh      sz     



 % % % % % % ( ( ( ( ( ( * * * * * * . . . . . .      	MMMM 	 	 	D		 	 	 	D	
 
	   7 7 7 7 7y( 7 7 78V V V V Vn V V V V Vs   1 99A AA