
    (Xc/J                         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 d dlmZ  ed      Z ed      Z ed	      Z ed
      Z G d dej&                        Zy)    N)creds)named_tuples)names)oids)import_gssapi_extension_encode_dictcred_imp_exps4u
cred_storerfc5588c                   P    e Zd ZdZdZ	 	 	 	 	 	 	 ddej                  ej                     dej                  e	   dej                  e
j                     dej                  e   dej                  ej                  ej                        d	ed
ej                  ej"                  ej$                  e	ef   ej$                  e	ef   f      dd f fdZede
j                  fd       Zedefd       Zedej.                  ej                     fd       Zedefd       Ze	 	 	 	 	 d dej                  e
j                     dej                  e   dej                  ej                  ej                        d	ed
ej                  ej"                  ej$                  e	ef   ej$                  e	ef   f      dej8                  fd       Z	 	 	 	 	 d!d
ej                  ej"                  ej$                  e	ef   ej$                  e	ef   f      d	edej                  ej                     dededej>                  fdZ 	 	 	 	 d"dej                  e
j                     dej                  e   dej                  ej                  ej                        d	edd f
dZ!	 	 	 	 d#deded	ededejD                  f
dZ#	 	 	 	 d#dej                  dededed	edejH                  fdZ%	 	 	 	 	 d$de
j                  dej                  d	edej                  e   dej                  e   dej                  ej                     d
ej                  ej"                  ej$                  e	ef   ej$                  e	ef   f      dd fdZ&de	fdZ'dejP                  ejR                  d    ejP                  de	f   f   fdZ* xZ+S )%Credentialsa  GSSAPI Credentials

    This class represents a set of GSSAPI credentials which may
    be used with and/or returned by other GSSAPI methods.

    It inherits from the low-level GSSAPI :class:`~gssapi.raw.creds.Creds`
    class, and thus may used with both low-level and high-level API methods.

    If your implementation of GSSAPI supports the credentials import-export
    extension, you may pickle and unpickle this object.

    The constructor either acquires or imports a set of GSSAPI
    credentials.

    If the `base` argument is used, an existing
    :class:`~gssapi.raw.creds.Creds` object from the low-level API is
    converted into a high-level object.

    If the `token` argument is used, the credentials
    are imported using the token, if the credentials import-export
    extension is supported (:requires-ext:`cred_imp_exp`).

    Otherwise, the credentials are acquired as per the
    :meth:`acquire` method.

    Raises:
        ~gssapi.exceptions.BadMechanismError
        ~gssapi.exceptions.BadNameTypeError
        ~gssapi.exceptions.BadNameError
        ~gssapi.exceptions.ExpiredCredentialsError
        ~gssapi.exceptions.MissingCredentialsError
     Nbasetokennamelifetimemechsusagestorereturnc                     ||}nK|'t         t        d      t         j                  |      }n"| j                  |||||      }	|	j                  }t        j                  dt        t        | '  | |            S )NWYour GSSAPI implementation does not have support for importing and exporting creditials)r   r   )
rcred_imp_expNotImplementedErrorimport_credacquirer   tcastsuperr   __new__)clsr   r   r   r   r   r   r   
base_credsres	__class__s             ./usr/lib/python3/dist-packages/gssapi/creds.pyr!   zCredentials.__new__5   s     J$) +A B B '2259J++dHeU$)  +CJvvmK5c:FH 	H    c           	          t        j                  t        j                  | j	                  dddd      j
                        S )z.Get the name associated with these credentialsTFr   r   r   r   )r   r   rnamesNameinquirer   selfs    r&   r   zCredentials.nameT   s:     vvfkklluE). # 0046 	6r'   c           	      p    t        j                  t        | j                  dddd      j                        S )z;Get the remaining lifetime of these credentials, in secondsFTr)   )r   r   intr,   r   r-   s    r&   r   zCredentials.lifetime[   s8     vvcll).e # ==EXG 	Gr'   c           	          t        j                  t         j                  t        j                     | j                  dddd      j                        S )z(Get the mechanisms for these credentialsFTr)   )r   r   SetroidsOIDr,   r   r-   s    r&   r   zCredentials.mechsb   sE     vvaeeEII&ll).d # <<AEC 	Cr'   c           	      p    t        j                  t        | j                  dddd      j                        S )z>Get the usage (initiate, accept, or both) of these credentialsFTr)   )r   r   strr,   r   r-   s    r&   r   zCredentials.usagei   s8     vvcll)-U # <<AEC 	Cr'   c                    |t        j                  ||||      }n5t        t        d      t	        |      }t        j                  |||||      }t        j                   | |j                        |j                  |j                        S )ax  Acquire GSSAPI credentials

        This method acquires credentials.  If the `store` argument is
        used, the credentials will be acquired from the given
        credential store (if supported).  Otherwise, the credentials are
        acquired from the default store.

        The credential store information is a dictionary containing
        mechanisms-specific keys and values pointing to a credential store
        or stores.

        Using a non-default store requires support for the credentials store
        extension.

        Args:
            name (~gssapi.names.Name): the name associated with the
                credentials, or None for the default name
            lifetime (int): the desired lifetime of the credentials in seconds,
                or None for indefinite
            mechs (list): the desired :class:`MechType` OIDs to be used
                with the credentials, or None for the default set
            usage (str): the usage for the credentials -- either 'both',
                'initiate', or 'accept'
            store (dict): the credential store information pointing to the
                credential store from which to acquire the credentials,
                or None for the default store (:requires-ext:`cred_store`)

        Returns:
            AcquireCredResult: the acquired credentials and information about
            them

        Raises:
            ~gssapi.exceptions.BadMechanismError
            ~gssapi.exceptions.BadNameTypeError
            ~gssapi.exceptions.BadNameError
            ~gssapi.exceptions.ExpiredCredentialsError
            ~gssapi.exceptions.MissingCredentialsError
        SYour GSSAPI implementation does not have support for manipulating credential storesr   )rcredsacquire_credrcred_cred_storer   r   acquire_cred_fromtuplesAcquireCredResultr   r   r   )r"   r   r   r   r   r   r$   b_stores           r&   r   zCredentials.acquirep   s    d =%%dH&+U4C  ') +> ? ? #5)G"44Wd5=u5:<C ''(;SYY(+6 	6r'   mech	overwriteset_defaultc                     |*t         t        d      t         j                  | ||||      S t        t        d      t	        |      }t        j                  || ||||      S )ae  Store these credentials into the given store

        This method stores the current credentials into the specified
        credentials store.  If the default store is used, support for
        :rfc:`5588` is required.  Otherwise, support for the credentials
        store extension is required.

        :requires-ext:`rfc5588` or :requires-ext:`cred_store`

        Args:
            store (dict): the store into which to store the credentials,
                or None for the default store.
            usage (str): the usage to store the credentials with -- either
                'both', 'initiate', or 'accept'
            mech (~gssapi.OID): the :class:`MechType` to associate with the
                stored credentials
            overwrite (bool): whether or not to overwrite existing credentials
                stored with the same name, etc
            set_default (bool): whether or not to set these credentials as
                the default credentials for the given store.

        Returns:
            StoreCredResult: the results of the credential storing operation

        Raises:
            ~gssapi.exceptions.GSSError
            ~gssapi.exceptions.ExpiredCredentialsError
            ~gssapi.exceptions.MissingCredentialsError
            ~gssapi.exceptions.OperationUnavailableError
            ~gssapi.exceptions.DuplicateCredentialsElementError
        z=Your GSSAPI implementation does not have support for RFC 5588z\Your GSSAPI implementation does not have support for manipulating credential stores directly)rcred_rfc5588r   
store_credr<   r   store_cred_into)r.   r   r   rA   rB   rC   r@   s          r&   r   zCredentials.store   s    T =$) +J K K !++D%,5{D D  ') +G H H #5)G#33GT5$4={L Lr'   c                     t         t        d      t         j                  | ||||      } t        |       |j                        S )a  Impersonate a name using the current credentials

        This method acquires credentials by impersonating another
        name using the current credentials.

        :requires-ext:`s4u`

        Args:
            name (~gssapi.names.Name): the name to impersonate
            lifetime (int): the desired lifetime of the new credentials in
                seconds, or None for indefinite
            mechs (list): the desired :class:`MechType` OIDs for the new
                credentials
            usage (str): the desired usage for the new credentials -- either
                'both', 'initiate', or 'accept'.  Note that some mechanisms
                may only support 'initiate'.

        Returns:
            Credentials: the new credentials impersonating the given name
        8Your GSSAPI implementation does not have support for S4Ur9   )	rcred_s4ur   acquire_cred_impersonate_nametyper   )r.   r   r   r   r   r$   s         r&   impersonatezCredentials.impersonate   sQ    8 % '= > > 55dD6>6;= tDzsyy))r'   c                     t        j                  | ||||      }|j                   t        j                  |j                        }nd}t        j                  ||j                  |j                  |j                        S )a  Inspect these credentials for information

        This method inspects these credentials for information about them.

        Args:
            name (bool): get the name associated with the credentials
            lifetime (bool): get the remaining lifetime for the credentials
            usage (bool): get the usage for the credentials
            mechs (bool): get the mechanisms associated with the credentials

        Returns:
            InquireCredResult: the information about the credentials,
            with None used when the corresponding argument was False

        Raises:
            ~gssapi.exceptions.MissingCredentialsError
            ~gssapi.exceptions.InvalidCredentialsError
            ~gssapi.exceptions.ExpiredCredentialsError
        N)
r:   inquire_credr   r   r+   r>   InquireCredResultr   r   r   )r.   r   r   r   r   r$   res_names          r&   r,   zCredentials.inquire  se    6 !!$huE88zz#((+HH''#,,(+		399> 	>r'   init_lifetimeaccept_lifetimec                     t        j                  | |||||      }|j                   t        j                  |j                        }nd}t        j                  ||j                  |j                  |j                        S )a$  Inspect these credentials for per-mechanism information

        This method inspects these credentials for per-mechanism information
        about them.

        Args:
            mech (~gssapi.OID): the mechanism for which to retrieve the
                information
            name (bool): get the name associated with the credentials
            init_lifetime (bool): get the remaining initiate lifetime for
                the credentials in seconds
            accept_lifetime (bool): get the remaining accept lifetime for
                the credentials in seconds
            usage (bool): get the usage for the credentials

        Returns:
            InquireCredByMechResult: the information about the credentials,
            with None used when the corresponding argument was False
        N)
r:   inquire_cred_by_mechr   r   r+   r>   InquireCredByMechResultrR   rS   r   )r.   rA   r   rR   rS   r   r$   rQ   s           r&   inquire_by_mechzCredentials.inquire_by_mech;  ss    8 ))$dM*95B 88zz#((+HH--h.1.?.?.1.A.A.1ii9 	9r'   impersonatorc           	      P   ||t        d      |8t        t        d      t        |      }t        j	                  || |||||      }	nI|-t
        t        d      t
        j                  | ||||||      }	nt        j                  | |||||      }	t        |	j                        S )a	  Acquire more credentials to add to the current set

        This method works like :meth:`acquire`, except that it adds the
        acquired credentials for a single mechanism to a copy of the current
        set, instead of creating a new set for multiple mechanisms.
        Unlike :meth:`acquire`, you cannot pass None desired name or
        mechanism.

        If the `impersonator` argument is used, the credentials will
        impersonate the given name using the impersonator credentials
        (:requires-ext:`s4u`).

        If the `store` argument is used, the credentials will be acquired
        from the given credential store (:requires-ext:`cred_store`).
        Otherwise, the credentials are acquired from the default store.

        The credential store information is a dictionary containing
        mechanisms-specific keys and values pointing to a credential store
        or stores.

        Note that the `store` argument is not compatible with the
        `impersonator` argument.

        Args:
            name (~gssapi.names.Name): the name associated with the
                credentials
            mech (~gssapi.OID): the desired :class:`MechType` to be used with
                the credentials
            usage (str): the usage for the credentials -- either 'both',
                'initiate', or 'accept'
            init_lifetime (int): the desired initiate lifetime of the
                credentials in seconds, or None for indefinite
            accept_lifetime (int): the desired accept lifetime of the
                credentials in seconds, or None for indefinite
            impersonator (Credentials): the credentials to use to impersonate
                the given name, or None to not acquire normally
                (:requires-ext:`s4u`)
            store (dict): the credential store information pointing to the
                credential store from which to acquire the credentials,
                or None for the default store (:requires-ext:`cred_store`)

        Returns:
            Credentials: the credentials set containing the current credentials
            and the newly acquired ones.

        Raises:
            ~gssapi.exceptions.BadMechanismError
            ~gssapi.exceptions.BadNameTypeError
            ~gssapi.exceptions.BadNameError
            ~gssapi.exceptions.DuplicateCredentialsElementError
            ~gssapi.exceptions.ExpiredCredentialsError
            ~gssapi.exceptions.MissingCredentialsError
        zMYou cannot use both the `impersonator` and `store` arguments at the same timer8   rI   )
ValueErrorr<   r   r   add_cred_fromrJ   add_cred_impersonate_namer:   add_credr   r   )
r.   r   rA   r   rR   rS   rX   r   r@   r$   s
             r&   addzCredentials.addd  s    D !9 B C C ') +> ? ? #5)G"00$d161@BC % ) +E F F55dL6:D%6C6EGC
 //$dE="13C 399%%r'   c                 N    t         t        d      t         j                  |       S )ay  Export these credentials into a token

        This method exports the current credentials to a token that can
        then be imported by passing the `token` argument to the constructor.

        This is often used to pass credentials between processes.

        :requires-ext:`cred_imp_exp`

        Returns:
            bytes: the exported credentials in token form
        r   )r   r   export_credr-   s    r&   exportzCredentials.export  s/      % '= > > ((..r'   c                 <    t        |       d | j                         ffS )N)rL   ra   r-   s    r&   
__reduce__zCredentials.__reduce__  s     T
T4;;=122r'   )NNNNNbothN)NNNrd   N)Nrd   NFF)NNNinitiate)TTTT)rd   NNNN),__name__
__module____qualname____doc__	__slots__r   Optionalr:   Credsbytesr*   r+   r0   Iterabler3   r4   r6   DictUnionr!   propertyr   r   r2   r   r   classmethodr>   r?   r   boolStoreCredResultr   rM   rP   r,   rV   rW   r^   ra   TupleTyperc   __classcell__)r%   s   @r&   r   r      s   B I *.#'(,$(37 Hjj&H zz% H jj%	H
 **S/H zz!**UYY/0H H zzFF1775#:&s
(;;<
H 
H> 6fkk 6 6 G# G G CquuUYY' C C Cs C C  )-$(37 A6jj%A6 **S/A6 zz!**UYY/0	A6
 A6 zzFF1775#:&s
(;;<
A6 
	!	!A6 A6N &*!:LzzFF1775#:&s
(;;<
:L
 :L jj#:L :L :L 
		:L| )-$(37$*jj%$* **S/$* zz!**UYY/0	$*
 $* 
$*P #>#> #> 	#>
 #> 
	!	!#>P " $'9ii'9 '9 	'9
 '9 '9 
	'	''9Z )-+/15 \&kk\& ii\& 	\&
 zz#\& C\& jj.\& zzFF1775#:&s
(;;<
\& 
\&|/ /,3	
&e(<<	=3r'   r   )typingr   
gssapi.rawr   r:   r   r>   r   r*   r   r3   gssapi._utilsr   r   gssapir   rJ   r<   rE   rl   r   r   r'   r&   <module>r|      sU     & - & $ ? '7#E*	*<8 '	2K3&,, K3r'   