o
    ¯b½
  ã                   @   sÖ   d 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
mZ ddlmZ eeƒG dd	„ d	ƒƒZeeƒG d
d„ dƒƒZeeƒG dd„ dƒƒZee
ƒG dd„ dejƒƒZee
ƒG dd„ dejƒƒZg d¢ZdS )z*
Credential managers for L{twisted.mail}.
é    N)Úimplementer)Úcredentials)ÚIllegalClientResponse)ÚIChallengeResponseÚIClientAuthentication)ÚnativeStringc                   @   ó$   e Zd Zdd„ Zdd„ Zdd„ ZdS )ÚCramMD5ClientAuthenticatorc                 C   ó
   || _ d S ©N©Úuser©Úselfr   © r   ú4/usr/lib/python3/dist-packages/twisted/mail/_cred.pyÚ__init__   ó   
z#CramMD5ClientAuthenticator.__init__c                 C   ó   dS )Ns   CRAM-MD5r   ©r   r   r   r   ÚgetName   ó   z"CramMD5ClientAuthenticator.getNamec                 C   s*   t j||tjd� ¡ }| jd | d¡ S )N)Ú	digestmodó    Úascii)ÚhmacÚHMACÚhashlibÚmd5Ú	hexdigestr   Úencode)r   ÚsecretÚchalÚresponser   r   r   ÚchallengeResponse   s   z,CramMD5ClientAuthenticator.challengeResponseN©Ú__name__Ú
__module__Ú__qualname__r   r   r$   r   r   r   r   r	      ó    r	   c                   @   ó,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚLOGINAuthenticatorc                 C   s   || _ | j| _d S r   )r   ÚchallengeUsernamer$   r   r   r   r   r   #   s   zLOGINAuthenticator.__init__c                 C   r   )Ns   LOGINr   r   r   r   r   r   '   r   zLOGINAuthenticator.getNamec                 C   s   | j | _| jS r   )ÚchallengeSecretr$   r   ©r   r!   r"   r   r   r   r,   *   s   z$LOGINAuthenticator.challengeUsernamec                 C   s   |S r   r   r.   r   r   r   r-   /   s   z"LOGINAuthenticator.challengeSecretN)r&   r'   r(   r   r   r,   r-   r   r   r   r   r+   !   s
    r+   c                   @   r   )ÚPLAINAuthenticatorc                 C   r
   r   r   r   r   r   r   r   6   r   zPLAINAuthenticator.__init__c                 C   r   )Ns   PLAINr   r   r   r   r   r   9   r   zPLAINAuthenticator.getNamec                 C   s   d| j  d | S )Nó    r   r.   r   r   r   r$   <   s   z$PLAINAuthenticator.challengeResponseNr%   r   r   r   r   r/   4   r)   r/   c                   @   r*   )
ÚLOGINCredentialsc                 C   s(   ddg| _ ddg| _tj | d d ¡ d S )Ns	   Password s
   User Name s   passwords   username)Ú
challengesÚ	responsesr   ÚUsernamePasswordr   r   r   r   r   r   B   s   

zLOGINCredentials.__init__c                 C   s
   | j  ¡ S r   )r2   Úpopr   r   r   r   ÚgetChallengeG   r   zLOGINCredentials.getChallengec                 C   s   t | t| j ¡ ƒ|ƒ d S r   )Úsetattrr   r3   r5   )r   r#   r   r   r   ÚsetResponseJ   s   zLOGINCredentials.setResponsec                 C   s
   t | jƒS r   )Úboolr2   r   r   r   r   ÚmoreChallengesM   r   zLOGINCredentials.moreChallengesN©r&   r'   r(   r   r6   r8   r:   r   r   r   r   r1   @   s
    r1   c                   @   r*   )
ÚPLAINCredentialsc                 C   s   t j | d d ¡ d S r   )r   r4   r   r   r   r   r   r   S   s   zPLAINCredentials.__init__c                 C   r   )Nó    r   r   r   r   r   r6   V   r   zPLAINCredentials.getChallengec                 C   s0   |  d¡}t|ƒdkrtdƒ‚|\}| _| _d S )Nr0   é   z*Malformed Response - wrong number of parts)ÚsplitÚlenr   ÚusernameÚpassword)r   r#   ÚpartsÚuselessr   r   r   r8   Y   s   
zPLAINCredentials.setResponsec                 C   r   )NFr   r   r   r   r   r:   _   r   zPLAINCredentials.moreChallengesNr;   r   r   r   r   r<   Q   s
    r<   )r	   r1   r+   r<   r/   )Ú__doc__r   r   Úzope.interfacer   Útwisted.credr   Útwisted.mail._exceptr   Útwisted.mail.interfacesr   r   Útwisted.python.compatr   r	   r+   r/   r4   r1   r<   Ú__all__r   r   r   r   Ú<module>   s&   