U
    
W[â
  ã                   @   sä   d Z ddlmZm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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}.
é    )Úabsolute_importÚdivisionN)Úimplementer)Úcredentials)ÚnativeString)ÚIllegalClientResponse)ÚIClientAuthenticationÚIChallengeResponsec                   @   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   ú4/usr/lib/python3/dist-packages/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  ||¡ ¡  d¡}| jd | S )NÚasciió    )ÚhmacZHMACZ	hexdigestÚencoder   )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#   5   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   =   s    zPLAINAuthenticator.__init__c                 C   s   dS )Ns   PLAINr   r   r   r   r   r   A   s    zPLAINAuthenticator.getNamec                 C   s   d| j  d | S )Nó    r   r$   r   r   r   r   E   s    z$PLAINAuthenticator.challengeResponseNr   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 )
Ú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   L   s    

zLOGINCredentials.__init__c                 C   s
   | j  ¡ S r   )r(   Úpopr   r   r   r   ÚgetChallengeR   s    zLOGINCredentials.getChallengec                 C   s   t | t| j ¡ ƒ|ƒ d S r   )Úsetattrr   r)   r+   )r   r   r   r   r   ÚsetResponseV   s    zLOGINCredentials.setResponsec                 C   s
   t | jƒS r   )Úboolr(   r   r   r   r   ÚmoreChallengesZ   s    zLOGINCredentials.moreChallengesN©r   r   r    r   r,   r.   r0   r   r   r   r   r'   J   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   a   s    zPLAINCredentials.__init__c                 C   s   dS )Nó    r   r   r   r   r   r,   e   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   ZusernameZpassword)r   r   ÚpartsZuselessr   r   r   r.   i   s    
ÿzPLAINCredentials.setResponsec                 C   s   dS )NFr   r   r   r   r   r0   q   s    zPLAINCredentials.moreChallengesNr1   r   r   r   r   r2   _   s   r2   )Ú__doc__Z
__future__r   r   r   Zzope.interfacer   Ztwisted.credr   Ztwisted.python.compatr   Ztwisted.mail._exceptr   Ztwisted.mail.interfacesr   r	   r
   r!   r%   r*   r'   r2   Ú__all__r   r   r   r   Ú<module>   s.     ý