U
    n5{i½
  ã                   @   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d	ddddgZdS )z*
Credential managers for L{twisted.mail}.
é    N)Úimplementer)Úcredentials)ÚIllegalClientResponse)ÚIChallengeResponseÚIClientAuthentication)ÚnativeStringc                   @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )ÚCramMD5ClientAuthenticatorc                 C   s
   || _ d S ©N©Úuser©Úselfr   © r   ú6/tmp/pip-unpacked-wheel-mnhg7r0q/twisted/mail/_cred.pyÚ__init__   s    z#CramMD5ClientAuthenticator.__init__c                 C   s   dS )Ns   CRAM-MD5r   ©r   r   r   r   ÚgetName   s    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      s   r   c                   @   s,   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   s   dS )Ns   LOGINr   r   r   r   r   r   '   s    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                   @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )ÚPLAINAuthenticatorc                 C   s
   || _ d S r	   r
   r   r   r   r   r   6   s    zPLAINAuthenticator.__init__c                 C   s   dS )Ns   PLAINr   r   r   r   r   r   9   s    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   s   r(   c                   @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
Ú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	   )r+   Úpopr   r   r   r   ÚgetChallengeG   s    zLOGINCredentials.getChallengec                 C   s   t | t| j ¡ ƒ|ƒ d S r	   )Úsetattrr   r,   r.   )r   r   r   r   r   ÚsetResponseJ   s    zLOGINCredentials.setResponsec                 C   s
   t | jƒS r	   )Úboolr+   r   r   r   r   ÚmoreChallengesM   s    zLOGINCredentials.moreChallengesN©r!   r"   r#   r   r/   r1   r3   r   r   r   r   r*   @   s   r*   c                   @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚPLAINCredentialsc                 C   s   t j | d d ¡ d S r	   )r   r-   r   r   r   r   r   r   S   s    zPLAINCredentials.__init__c                 C   s   dS )Nó    r   r   r   r   r   r/   V   s    zPLAINCredentials.getChallengec                 C   s0   |  d¡}t|ƒdkrtdƒ‚|\}| _| _d S )Nr)   é   z*Malformed Response - wrong number of parts)ÚsplitÚlenr   ÚusernameÚpassword)r   r   ÚpartsZuselessr   r   r   r1   Y   s    
zPLAINCredentials.setResponsec                 C   s   dS )NFr   r   r   r   r   r3   _   s    zPLAINCredentials.moreChallengesNr4   r   r   r   r   r5   Q   s   r5   )Ú__doc__r   r   Zzope.interfacer   Ztwisted.credr   Ztwisted.mail._exceptr   Ztwisted.mail.interfacesr   r   Ztwisted.python.compatr   r   r$   r(   r-   r*   r5   Ú__all__r   r   r   r   Ú<module>   s.   û