ó
øÐLac           @   s  d  Z  d d l m Z m Z d d l m Z m Z m Z m Z d d l	 Z	 e	 j
 e ƒ Z d d l Z d d l m Z d d l m Z m Z d d l m Z m Z m Z d d l m Z d d l j j Z d	 d
 d d d d d d d d d d d d g Z d e j f d „  ƒ  YZ d e j  e j! e j" f d „  ƒ  YZ# d
 e f d „  ƒ  YZ$ d e f d „  ƒ  YZ% d e# f d „  ƒ  YZ& d e# f d „  ƒ  YZ' d e# f d „  ƒ  YZ( d e# f d  „  ƒ  YZ) d	 e f d! „  ƒ  YZ* g  e D] Z+ d" e+ ^ qØZ, d# „  Z- e- ƒ  d S($   s.   passlib.handlers.digests - plain hash digests
iÿÿÿÿ(   t	   b64encodet	   b64decode(   t   md5t   sha1t   sha256t   sha512N(   t	   plaintext(   t   unix_crypt_schemest
   to_unicode(   t   uascii_to_strt   unicodet   u(   t   classpropertyt   ldap_plaintextt   ldap_md5t	   ldap_sha1t   ldap_salted_md5t   ldap_salted_sha1t   ldap_salted_sha256t   ldap_salted_sha512t   ldap_des_cryptt   ldap_bsdi_cryptt   ldap_md5_cryptt   ldap_sha1_cryptt   ldap_bcryptt   ldap_sha256_cryptt   ldap_sha512_cryptt   _Base64DigestHelperc           B   sA   e  Z d  Z d Z d Z d Z e j Z	 e
 d „  ƒ Z d „  Z RS(   s   helper for ldap_md5 / ldap_sha1c         C   s   |  j  S(   s/   tell StaticHandler to strip ident from checksum(   t   ident(   t   cls(    (    sX   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/handlers/ldap_digests.pyt   _hash_prefix2   s    c         C   sI   t  | t ƒ r! | j d ƒ } n  |  j | ƒ j ƒ  } t | ƒ j d ƒ S(   Ns   utf-8t   ascii(   t
   isinstanceR
   t   encodet
   _hash_funct   digestR    t   decode(   t   selft   secrett   chk(    (    sX   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/handlers/ldap_digests.pyt   _calc_checksum7   s    N(   t   __name__t
   __module__t   __doc__t   NoneR   R"   t   _hash_regext   uht   PADDED_BASE64_CHARSt   checksum_charsR   R   R(   (    (    (    sX   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/handlers/ldap_digests.pyR   )   s   	t   _SaltedBase64DigestHelperc           B   sl   e  Z d  Z d Z e j Z d	 Z d	 Z	 d	 Z
 d Z Z d Z d Z d Z e d „  ƒ Z d „  Z d „  Z RS(
   s-   helper for ldap_salted_md5 / ldap_salted_sha1t   saltt	   salt_sizei   i   c         C   s·   t  | d d ƒ } |  j j | ƒ } | s? t j j |  ƒ ‚ n  y" t | j d ƒ j d ƒ ƒ } Wn# t	 k
 r† t j j
 |  ƒ ‚ n X|  j } | sœ t ‚ |  d | |  d | | ƒ S(   NR   t   hasht   tmpt   checksumR2   (   R   R-   t   matchR.   t   exct   InvalidHashErrorR   t   groupR!   t	   TypeErrort   MalformedHashErrort   checksum_sizet   AssertionError(   R   R4   t   mt   datat   cs(    (    sX   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/handlers/ldap_digests.pyt   from_stringN   s    "	c         C   s6   |  j  |  j } |  j t | ƒ j d ƒ } t | ƒ S(   NR   (   R6   R2   R   R    R$   R	   (   R%   R@   R4   (    (    sX   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/handlers/ldap_digests.pyt	   to_string\   s    c         C   s;   t  | t ƒ r! | j d ƒ } n  |  j | |  j ƒ j ƒ  S(   Ns   utf-8(   R    R
   R!   R"   R2   R#   (   R%   R&   (    (    sX   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/handlers/ldap_digests.pyR(   a   s    (   R2   R3   N(   R)   R*   R+   t   setting_kwdsR.   R/   R0   R,   R   R"   R-   t   min_salt_sizet   max_salt_sizet   default_salt_sizet   classmethodRB   RC   R(   (    (    (    sX   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/handlers/ldap_digests.pyR1   =   s   	
	c           B   s;   e  Z d  Z d Z e d ƒ Z e Z e j	 e d ƒ ƒ Z
 RS(   sì   This class stores passwords using LDAP's plain MD5 format, and follows the :ref:`password-hash-api`.

    The :meth:`~passlib.ifc.PasswordHash.hash` and :meth:`~passlib.ifc.PasswordHash.genconfig` methods have no optional keywords.
    R   s   {MD5}s%   ^\{MD5\}(?P<chk>[+/a-zA-Z0-9]{22}==)$(   R)   R*   R+   t   nameR   R   R   R"   t   ret   compileR-   (    (    (    sX   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/handlers/ldap_digests.pyR   i   s
   c           B   s;   e  Z d  Z d Z e d ƒ Z e Z e j	 e d ƒ ƒ Z
 RS(   sí   This class stores passwords using LDAP's plain SHA1 format, and follows the :ref:`password-hash-api`.

    The :meth:`~passlib.ifc.PasswordHash.hash` and :meth:`~passlib.ifc.PasswordHash.genconfig` methods have no optional keywords.
    R   s   {SHA}s$   ^\{SHA\}(?P<chk>[+/a-zA-Z0-9]{27}=)$(   R)   R*   R+   RI   R   R   R   R"   RJ   RK   R-   (    (    (    sX   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/handlers/ldap_digests.pyR   s   s
   c           B   sA   e  Z d  Z d Z e d ƒ Z d Z e Z e	 j
 e d ƒ ƒ Z RS(   sÏ  This class stores passwords using LDAP's salted MD5 format, and follows the :ref:`password-hash-api`.

    It supports a 4-16 byte salt.

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

    :type salt: bytes
    :param salt:
        Optional salt string.
        If not specified, one will be autogenerated (this is recommended).
        If specified, it may be any 4-16 byte string.

    :type salt_size: int
    :param salt_size:
        Optional number of bytes to use when autogenerating new salts.
        Defaults to 4 bytes for compatibility with the LDAP spec,
        but some systems use larger salts, and Passlib supports
        any value between 4-16.

    :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
        ``salt`` strings that are too long.

        .. versionadded:: 1.6

    .. versionchanged:: 1.6
        This format now supports variable length salts, instead of a fix 4 bytes.
    R   s   {SMD5}i   s+   ^\{SMD5\}(?P<tmp>[+/a-zA-Z0-9]{27,}={0,2})$(   R)   R*   R+   RI   R   R   R=   R   R"   RJ   RK   R-   (    (    (    sX   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/handlers/ldap_digests.pyR   }   s    c           B   sA   e  Z d  Z d Z e d ƒ Z d Z e Z e	 j
 e d ƒ ƒ Z RS(   sÛ  
    This class stores passwords using LDAP's "Salted SHA1" format,
    and follows the :ref:`password-hash-api`.

    It supports a 4-16 byte salt.

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

    :type salt: bytes
    :param salt:
        Optional salt string.
        If not specified, one will be autogenerated (this is recommended).
        If specified, it may be any 4-16 byte string.

    :type salt_size: int
    :param salt_size:
        Optional number of bytes to use when autogenerating new salts.
        Defaults to 4 bytes for compatibility with the LDAP spec,
        but some systems use larger salts, and Passlib supports
        any value between 4-16.

    :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
        ``salt`` strings that are too long.

        .. versionadded:: 1.6

    .. versionchanged:: 1.6
        This format now supports variable length salts, instead of a fix 4 bytes.
    R   s   {SSHA}i   s+   ^\{SSHA\}(?P<tmp>[+/a-zA-Z0-9]{32,}={0,2})$(   R)   R*   R+   RI   R   R   R=   R   R"   RJ   RK   R-   (    (    (    sX   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/handlers/ldap_digests.pyR   ¤   s   "c           B   sG   e  Z d  Z d Z e d ƒ Z d Z d Z e Z	 e
 j e d ƒ ƒ Z RS(   sC  
    This class stores passwords using LDAP's "Salted SHA2-256" format,
    and follows the :ref:`password-hash-api`.

    It supports a 4-16 byte salt.

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

    :type salt: bytes
    :param salt:
        Optional salt string.
        If not specified, one will be autogenerated (this is recommended).
        If specified, it may be any 4-16 byte string.

    :type salt_size: int
    :param salt_size:
        Optional number of bytes to use when autogenerating new salts.
        Defaults to 8 bytes for compatibility with the LDAP spec,
        but Passlib supports any value between 4-16.

    :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
        ``salt`` strings that are too long.

    .. versionadded:: 1.7.3
    R   s	   {SSHA256}i    i   s.   ^\{SSHA256\}(?P<tmp>[+/a-zA-Z0-9]{48,}={0,2})$(   R)   R*   R+   RI   R   R   R=   RG   R   R"   RJ   RK   R-   (    (    (    sX   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/handlers/ldap_digests.pyR   Ð   s   c           B   sG   e  Z d  Z d Z e d ƒ Z d Z d Z e Z	 e
 j e d ƒ ƒ Z RS(   sC  
    This class stores passwords using LDAP's "Salted SHA2-512" format,
    and follows the :ref:`password-hash-api`.

    It supports a 4-16 byte salt.

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

    :type salt: bytes
    :param salt:
        Optional salt string.
        If not specified, one will be autogenerated (this is recommended).
        If specified, it may be any 4-16 byte string.

    :type salt_size: int
    :param salt_size:
        Optional number of bytes to use when autogenerating new salts.
        Defaults to 8 bytes for compatibility with the LDAP spec,
        but Passlib supports any value between 4-16.

    :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
        ``salt`` strings that are too long.

    .. versionadded:: 1.7.3
    R   s	   {SSHA512}i@   i   s.   ^\{SSHA512\}(?P<tmp>[+/a-zA-Z0-9]{91,}={0,2})$(   R)   R*   R+   RI   R   R   R=   RG   R   R"   RJ   RK   R-   (    (    (    sX   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/handlers/ldap_digests.pyR   ø   s   c           B   s_   e  Z d  Z d Z e j e d ƒ ƒ Z e j	 d d d d ƒ e
 d „  ƒ ƒ Z e
 d „  ƒ Z RS(	   sY  This class stores passwords in plaintext, and follows the :ref:`password-hash-api`.

    This class acts much like the generic :class:`!passlib.hash.plaintext` handler,
    except that it will identify a hash only if it does NOT begin with the ``{XXX}`` identifier prefix
    used by RFC2307 passwords.

    The :meth:`~passlib.ifc.PasswordHash.hash`, :meth:`~passlib.ifc.PasswordHash.genhash`, and :meth:`~passlib.ifc.PasswordHash.verify` methods all require the
    following additional contextual keyword:

    :type encoding: str
    :param encoding:
        This controls the character encoding to use (defaults to ``utf-8``).

        This encoding will be used to encode :class:`!unicode` passwords
        under Python 2, and decode :class:`!bytes` hashes under Python 3.

    .. versionchanged:: 1.6
        The ``encoding`` keyword was added.
    R   s   ^\{\w+\}.*$t
   deprecateds   1.7t   removeds   2.0c         C   s   d S(   Nt   !(    (   R   (    (    sX   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/handlers/ldap_digests.pyt	   genconfig:  s    c         C   s1   t  j | ƒ } t | ƒ o0 |  j j | ƒ d  k S(   N(   R.   t   to_unicode_for_identifyt   boolt	   _2307_patR7   R,   (   R   R4   (    (    sX   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/handlers/ldap_digests.pyt   identifyA  s    (   R)   R*   R+   RI   RJ   RK   R   RR   R.   t   deprecated_methodRH   RO   RS   (    (    (    sX   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/handlers/ldap_digests.pyR      s   t   ldap_c          C   sS   t  ƒ  }  x@ t D]8 } d | } t j | | d t d ƒ d t ƒ|  | <q W~  d  S(   NRU   t   prefixs   {CRYPT}t   lazy(   t   globalsR   R.   t   PrefixWrapperR   t   True(   t   gt   wnameRI   (    (    sX   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/handlers/ldap_digests.pyt   _init_ldap_crypt_handlersN  s
    	
,(.   R+   t   base64R    R   t   hashlibR   R   R   R   t   loggingt	   getLoggerR)   t   logRJ   t   passlib.handlers.miscR   t   passlib.utilsR   R   t   passlib.utils.compatR	   R
   R   t   passlib.utils.decorR   t   passlib.utils.handlerst   utilst   handlersR.   t   __all__t   StaticHandlerR   t
   HasRawSaltt   HasRawChecksumt   GenericHandlerR1   R   R   R   R   R   R   R   RI   t   ldap_crypt_schemesR]   (    (    (    sX   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/handlers/ldap_digests.pyt   <module>   sH   " 	%,

',((,	