ó
øÐLac           @   sÀ   d  Z  d d l Z e j e ƒ Z d d l m Z m Z d d l m	 Z	 d d l
 m Z m Z m Z d d l m Z d d l j j Z g  Z d Z d e j e j e j e j f d	 „  ƒ  YZ d S(
   s   passlib.handlers.sha1_crypt
iÿÿÿÿN(   t
   safe_cryptt
   test_crypt(   t   h64(   t   ut   unicodet   irange(   t   compile_hmacs    t
   sha1_cryptc           B   sø   e  Z d  Z d Z d' Z e d ƒ Z d Z e j	 Z
 d Z d Z e j	 Z d	 Z d
 Z d Z d Z e d „  ƒ Z e d „ Z d( Z e d „  ƒ Z d „  Z e d „  ƒ Z d „  Z d d
 d d d d d d d d d d d d  d! d" d# d$ d d% d& g Z RS()   s&  This class implements the SHA1-Crypt password hash, and follows the :ref:`password-hash-api`.

    It supports a variable-length salt, and a variable number of rounds.

    The :meth:`~passlib.ifc.PasswordHash.using` method accepts the following optional keywords:

    :type salt: str
    :param salt:
        Optional salt string.
        If not specified, an 8 character one will be autogenerated (this is recommended).
        If specified, it must be 0-64 characters, drawn from the regexp range ``[./0-9A-Za-z]``.

    :type salt_size: int
    :param salt_size:
        Optional number of bytes to use when autogenerating new salts.
        Defaults to 8 bytes, but can be any value between 0 and 64.

    :type rounds: int
    :param rounds:
        Optional number of rounds to use.
        Defaults to 480000, must be between 1 and 4294967295, inclusive.

    :type relaxed: bool
    :param relaxed:
        By default, providing an invalid value for one of the other
        keywords will result in a :exc:`ValueError`. If ``relaxed=True``,
        and the error can be corrected, a :exc:`~passlib.exc.PasslibHashWarning`
        will be issued instead. Correctable errors include ``rounds``
        that are too small or too large, and ``salt`` strings that are too long.

        .. versionadded:: 1.6
    R   t   saltt	   salt_sizet   roundss   $sha1$i   i   i@   i S i   Iÿÿÿÿ    t   linearc         C   s=   t  j | |  j d |  ƒ\ } } } |  d | d | d | ƒ S(   Nt   handlerR
   R   t   checksum(   t   uht	   parse_mc3t   ident(   t   clst   hashR
   R   t   chk(    (    sV   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/handlers/sha1_crypt.pyt   from_stringS   s    $c         C   s4   | r d  n |  j } t j |  j |  j |  j | ƒ S(   N(   t   NoneR   R   t
   render_mc3R   R
   R   (   t   selft   configR   (    (    sV   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/handlers/sha1_crypt.pyt	   to_stringX   s    t   os_cryptt   builtinc         C   s+   t  d d ƒ r# |  j |  j ƒ t St Sd  S(   Nt   tests-   $sha1$1$Wq3GL2Vp$C8U25GvfHS8qGHimExLaiSFlGkAe(   R   t   _set_calc_checksum_backendt   _calc_checksum_os_cryptt   Truet   False(   R   (    (    sV   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/handlers/sha1_crypt.pyt   _load_backend_os_cryptd   s    c         C   s‰   |  j  d t ƒ } t | | ƒ } | d  k r: |  j | ƒ S| j | ƒ sf t | ƒ t | ƒ d k r t j j	 |  | | ƒ ‚ n  | d S(   NR   i   iäÿÿÿ(
   R   R   R    R   t   _calc_checksum_builtint
   startswitht   lenR   t   exct   CryptBackendError(   R   t   secretR   R   (    (    sV   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/handlers/sha1_crypt.pyR   m   s    ,c         C   s   |  j  |  j ƒ t S(   N(   R   R"   R   (   R   (    (    sV   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/handlers/sha1_crypt.pyt   _load_backend_builtin{   s    c         C   s»   t  | t ƒ r! | j d ƒ } n  t | k rB t j j |  ƒ ‚ n  |  j } t d ƒ |  j	 | f j d ƒ } t
 d | ƒ } x  t | ƒ D] } | | ƒ } q‰ Wt j | |  j ƒ j d ƒ S(   Ns   utf-8s
   %s$sha1$%st   asciit   sha1(   t
   isinstanceR   t   encodet   _BNULLR   R%   t   NullPasswordErrorR
   R   R   R   R   R   t   encode_transposed_bytest   _chk_offsetst   decode(   R   R'   R
   t   resultt
   keyed_hmact   _(    (    sV   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/handlers/sha1_crypt.pyR"   €   s    	"i   i    i   i   i   i   i   i   i
   i	   i   i   i   i   i   i   i   i   (   R   R	   R
   (   R   R   (   t   __name__t
   __module__t   __doc__t   namet   setting_kwdsR   R   t   checksum_sizeR   t   HASH64_CHARSt   checksum_charst   default_salt_sizet   max_salt_sizet
   salt_charst   default_roundst
   min_roundst
   max_roundst   rounds_costt   classmethodR   R    R   t   backendsR!   R   R(   R"   R0   (    (    (    sV   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/handlers/sha1_crypt.pyR      s6    											(   R7   t   loggingt	   getLoggerR5   t   logt   passlib.utilsR    R   t   passlib.utils.binaryR   t   passlib.utils.compatR   R   R   t   passlib.crypto.digestR   t   passlib.utils.handlerst   utilst   handlersR   t   __all__R-   t   HasManyBackendst	   HasRoundst   HasSaltt   GenericHandlerR   (    (    (    sV   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/handlers/sha1_crypt.pyt   <module>   s    