
ÛùnWW  ã               @   sZ  d  Z  d d l Z d d l Z d d l m Z d d l m Z	 e j
 e j d Z e ƒ  Z Gd d „  d e	 d d ƒ ƒ Z d d	 d
 „ Z d d d „ Z e d d d d ƒ Z e d d d d ƒ Z e d d d d ƒ Z e d d d d ƒ Z g  Z xN e e e f D]= Z e d e ƒ Z e re e ƒ e j k re j e ƒ qWe j e ƒ [ [ d S)zEWrapper to the POSIX crypt library call and associated functionality.é    N)ÚSystemRandom)Ú
namedtuplez./c               @   s"   e  Z d  Z d Z d d „  Z d S)Ú_MethodziClass representing a salt method per the Modular Crypt Format or the
    legacy 2-character crypt method.c             C   s   d j  |  j ƒ S)Nz<crypt.METHOD_{}>)ÚformatÚname)Úself© r   úL/afs/cs.wisc.edu/s/python-3.5.2/src/amd64_ubu16/../Python-3.5.2/Lib/crypt.pyÚ__repr__   s    z_Method.__repr__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r
   r   r   r   r	   r      s   r   z name ident salt_chars total_sizec             C   sd   |  d k r t  d }  |  j r1 d j |  j ƒ n d } | d j d d „  t |  j ƒ Dƒ ƒ 7} | S)zsGenerate a salt for the specified method.

    If not specified, the strongest available method will be used.

    Nr   z${}$Ú c             s   s   |  ] } t  j t ƒ Vq d  S)N)Ú_srÚchoiceÚ
_saltchars)Ú.0Úcharr   r   r	   ú	<genexpr>   s    zmksalt.<locals>.<genexpr>)ÚmethodsÚidentr   ÚjoinÚrangeZ
salt_chars)ÚmethodÚsr   r   r	   Úmksalt   s
    
!)r   c             C   s7   | d k s t  | t ƒ r' t | ƒ } t j |  | ƒ S)aR  Return a string representing the one-way hash of a password, with a salt
    prepended.

    If ``salt`` is not specified or is ``None``, the strongest
    available method will be selected and a salt generated.  Otherwise,
    ``salt`` may be one of the ``crypt.METHOD_*`` values, or a string as
    returned by ``crypt.mksalt()``.

    N)Ú
isinstancer   r   Ú_cryptÚcrypt)ZwordZsaltr   r   r	   r   #   s    
r   ZCRYPTé   é   ÚMD5Ú1é   é"   ÚSHA256Ú5é   é?   ÚSHA512Ú6éj   r   )r   r   ÚstringÚ_stringÚrandomr   Z_SystemRandomÚcollectionsr   Z_namedtupleÚascii_lettersÚdigitsr   r   r   r   r   ZMETHOD_CRYPTZ
METHOD_MD5ZMETHOD_SHA256ZMETHOD_SHA512r   Ú_methodÚ_resultÚlenZ
total_sizeÚappendr   r   r   r	   Ú<module>   s(   		