o
    œ¨Êh%  ã                   @   s\  d dl Z d dlZd dlZd dlmZmZmZmZmZmZ d dl	m
Z
mZ e ZZeZG dd„ dƒZdjZe edd�¡Ze ed	d�¡ZejZeeeƒfe_ee_ejZeeƒfe_ee_G d
d„ deƒZG dd„ deƒZe jdd„ ƒZejZeeeeeeeƒeeƒeeƒfe_ee_dd„ Zej Z eeeeeeeeeeeeeeƒeeƒeeƒfe _ee _G dd„ de!ƒZ"ee"ƒG dd„ de#ƒƒZ$ee"ƒG dd„ de#ƒƒZ%dd„ Z&ej'Z'eeeeeeeeeƒfe'_ee'_dd„ Z(ej)Z)eeeeeeeeeeeeeeeeƒfe)_ee)_dd„ Z*ej+Z+eeeefe+_ee+_ej,Z,eefe,_ee,_ej-Z-efe-_ee-_dd„ Z.dS ) é    N)Úc_void_pÚc_uint16Úc_uint32Úc_int32Úc_char_pÚPOINTER)Ústring_typesÚadd_metaclassc                   @   s   e Zd ZdZdS )Úerrori,�ÿÿN)Ú__name__Ú
__module__Ú__qualname__Úitem_not_found© r   r   úL/var/www/html/env/lib/python3.10/site-packages/keyring/backends/_OS_X_API.pyr
      s    r
   z=/System/Library/Frameworks/{name}.framework/Versions/A/{name}ÚSecurity)ÚnameÚCoreServicesc                   @   ó   e Zd Zedd„ ƒZdS )ÚErrorc                 C   s   |dkrd S | ||ƒ‚)Nr   r   ©ÚclsÚstatusÚmsgr   r   r   Úraise_for_status$   s   
zError.raise_for_statusN©r   r   r   Úclassmethodr   r   r   r   r   r   #   ó    r   c                   @   r   )ÚNotFoundc                 C   s$   |t jkr
| ||ƒ‚t ||¡ d S )N)r
   r   r   r   r   r   r   r   r   ,   s   

zNotFound.raise_for_statusNr   r   r   r   r   r   +   r   r   c              	   c   sp   � t ƒ }| d u rt|ƒ}d}nt|  d¡|ƒ}djdi tƒ ¤Ž}t ||¡ z|V  W t 	|¡ d S t 	|¡ w )NzUnable to open default keychainúutf-8zUnable to open keychain {name}r   )
Úsec_keychain_refÚSecKeychainCopyDefaultÚSecKeychainOpenÚencodeÚformatÚlocalsr   r   Ú_coreÚ	CFRelease)r   Úrefr   r   r   r   r   Úopen3   s   €r)   c           	   
   C   sª   |  d¡}|  d¡}t| ƒ�}tƒ }tƒ }t|t|ƒ|t|ƒ|||d ƒ}W d   ƒ n1 s.w   Y  d}t ||¡ t 	|j
¡}t ||j
|j
¡ td |ƒ |j d¡S )Nr   ú Can't fetch password from system)r#   r)   r   r   ÚSecKeychainFindGenericPasswordÚlenr   r   ÚctypesÚcreate_string_bufferÚvalueÚmemmoveÚSecKeychainItemFreeContentÚrawÚdecode)	Úkc_nameÚserviceÚusernameÚkeychainÚlengthÚdatar   r   Úpasswordr   r   r   Úfind_generic_passwordQ   s,   


øý
r;   c                       s,   e Zd ZdZ‡ fdd„Zedd„ ƒZ‡  ZS )ÚPackedAttributeszy
    Take the attributes which use magic words
    to represent enumerated constants and generate
    the constants.
    c                    s2   |  ‡ fdd„| ¡ D ƒ¡ ttˆ ƒ ˆ |||¡S )Nc                 3   s,   � | ]\}}|  d ¡s|ˆ  |¡fV  qdS )Ú_N)Ú
startswithÚunpack)Ú.0ÚkeyÚval©r   r   r   Ú	<genexpr>‡   s   € ý
ÿz+PackedAttributes.__new__.<locals>.<genexpr>)ÚupdateÚitemsÚsuperr<   Ú__new__)r   r   ÚbasesÚdict©Ú	__class__rC   r   rH   †   s   þzPackedAttributes.__new__c                 C   s&   t | tƒs| S t d|  d¡¡\}|S )z»
        >>> PackedAttributes.unpack(0)
        0
        >>> PackedAttributes.unpack('\x00\x00\x00\x01')
        1
        >>> PackedAttributes.unpack('abcd')
        1633837924
        z!IÚascii)Ú
isinstancer   Ústructr?   r#   )ÚwordrB   r   r   r   r?   Ž   s   

zPackedAttributes.unpack)r   r   r   Ú__doc__rH   Ústaticmethodr?   Ú__classcell__r   r   rK   r   r<   €   s
    r<   c                   @   ó   e Zd ZdZdZdZdS )ÚSecProtocolTypeÚhttpÚhtpszftp N)r   r   r   ÚkSecProtocolTypeHTTPÚkSecProtocolTypeHTTPSÚkSecProtocolTypeFTPr   r   r   r   rU   ž   s    rU   c                   @   rT   )ÚSecAuthenticationTypezP
    >>> SecAuthenticationType.kSecAuthenticationTypeDefault
    1684434036
    Údfltr   N)r   r   r   rQ   ÚkSecAuthenticationTypeDefaultÚkSecAuthenticationTypeAnyr   r   r   r   r[   ¥   s    r[   c                 C   sÈ   |  d¡}d }|  d¡}d }d}t| ƒ�&}tƒ }tƒ }t|t|ƒ|d|t|ƒ|d||tjtj	||d ƒ}	W d   ƒ n1 s=w   Y  d}
t
 |	|
¡ t |j¡}t ||j|j¡ td |ƒ |j d¡S )Nr   r   r*   )r#   r)   r   r   ÚSecKeychainFindInternetPasswordr,   rU   rY   r[   r^   r   r   r-   r.   r/   r0   r1   r2   r3   )r4   r5   r6   ÚdomainÚpathÚportr7   r8   r9   r   r   r:   r   r   r   Úfind_internet_password¯   s8   


õý
rc   c              
   C   sÊ   |  d¡}|  d¡}|  d¡}t| ƒ�H}tƒ }t|t|ƒ|t|ƒ|d d |ƒ}|r?|tjkr>t|t|ƒ|t|ƒ|t|ƒ|d ƒ}nt|d t|ƒ|ƒ}t	 
|¡ t |d¡ W d   ƒ d S 1 s^w   Y  d S )Nr   úUnable to set password)r#   r)   Úsec_keychain_item_refr+   r,   r
   r   ÚSecKeychainAddGenericPasswordÚ&SecKeychainItemModifyAttributesAndDatar&   r'   r   r   )r   r5   r6   r:   r7   Úitemr   r   r   r   Úset_generic_passwordÞ   s4   




ü

ü€ÿ
"íri   c           	      C   s˜   |  d¡}d }|  d¡}|  d¡}d }d}t| ƒ�)}t|t|ƒ|d|t|ƒ|d||tjtjt|ƒ|d ƒ}t 	|d¡ W d   ƒ d S 1 sEw   Y  d S )Nr   r   rd   )
r#   r)   ÚSecKeychainAddInternetPasswordr,   rU   rY   r[   r^   r   r   )	r   r5   r6   r:   r`   ra   rb   r7   r   r   r   r   Úset_internet_password  s*   



ö"ñrk   c              
   C   sŽ   |  d¡}|  d¡}t| ƒ� }tƒ }tƒ }tƒ }t|t|ƒ|t|ƒ||||ƒ}W d   ƒ n1 s1w   Y  t |d¡ t	|ƒ t
 |¡ d S )Nr   zUnable to delete password)r#   r)   r   r   re   r+   r,   r   r   ÚSecKeychainItemDeleter&   r'   )r   r5   r6   r7   r8   r9   rh   r   r   r   r   Údelete_generic_password7  s(   


øürm   )/Ú
contextlibr-   rO   r   r   r   r   r   r   Úkeyring.py27compatr   r	   r    re   Ú	OS_statusr
   r$   ÚfwÚCDLLÚ_secr&   r"   ÚargtypesÚrestyper!   Ú	Exceptionr   r   Úcontextmanagerr)   r+   r;   r_   Útyper<   ÚobjectrU   r[   rc   rf   ri   rj   rk   rg   r1   rl   rm   r   r   r   r   Ú<module>   sÌ     þ
ø
ñ	!ø
ñÿÿ