U
    6\                     @   s   d dl m Z mZ d dlmZ d dlmZ G dd deZe ddddd d	d
Zeedd Z	e
e eeZdd ZedZdd Zdd Zdd ZG dd dejZG dd deZG dd dejZG dd dejZG dd dejZd!dd ZdS )"    )datetime	timedeltaNc                   @   s   e Zd Zdd Zdd ZdS )_StoppedClockc                 C   s
   || _ d S Nt)selfr    r	   =/usr/lib/python3/dist-packages/macaroonbakery/tests/common.py__init__
   s    z_StoppedClock.__init__c                 C   s   | j S r   r   r   r	   r	   r
   utcnow   s    z_StoppedClock.utcnowN)__name__
__module____qualname__r   r   r	   r	   r	   r
   r   	   s   r   il              )ZyearZmonthZdayZhourZminutesecond   )Zdaysc                  C   s8   t  } |  dd | ddt | ddt | S )NZtestns strtrue)checkersZChecker	namespaceregister	str_check
true_check)cr	   r	   r
   test_checker   s
    r    r   c                 C   s   t t| S r   )test_contextZ
with_value_str_key)sr	   r	   r
   str_context#   s    r$   c                 C   s    | t  }||krd||S d S )N{} doesn't match {})r"   format)ctxcondargsZexpectr	   r	   r
   r   '   s    c                 C   s   d S r   r	   )r'   r(   r)   r	   r	   r
   r   .   s    r   c                   @   s    e Zd ZdZdd Zdd ZdS )OneIdentitya  An IdentityClient implementation that always returns a single identity
    from declared_identity, allowing allow(LOGIN_OP) to work even when there
    are no declaration caveats (this is mostly to support the legacy tests
    which do their own checking of declaration caveats).
    c                 C   s   dS )N)NNr	   )r   r'   r	   r	   r
   identity_from_context:   s    z!OneIdentity.identity_from_contextc                 C   s   t  S r   )_NoOne)r   r'   Zdeclaredr	   r	   r
   declared_identity=   s    zOneIdentity.declared_identityN)r   r   r   __doc__r+   r-   r	   r	   r	   r
   r*   3   s   r*   c                   @   s   e Zd Zdd Zdd ZdS )r,   c                 C   s   dS )NZnooner	   r   r	   r	   r
   idB   s    z	_NoOne.idc                 C   s   dS )Nr   r	   r   r	   r	   r
   domainE   s    z_NoOne.domainN)r   r   r   r/   r0   r	   r	   r	   r
   r,   A   s   r,   c                   @   s   e Zd Zdd Zdd ZdS )ThirdPartyStrcmpCheckerc                 C   s
   || _ d S r   )r   )r   r   r	   r	   r
   r   J   s    z ThirdPartyStrcmpChecker.__init__c                 C   sH   |j }t|j tr|j d}|| jkrDtdt|t| jg S )Nzutf-8r%   )		condition
isinstancebytesdecoder   bakeryZThirdPartyCaveatCheckFailedr&   repr)r   r'   cav_infor2   r	   r	   r
   check_third_party_caveatM   s    
z0ThirdPartyStrcmpChecker.check_third_party_caveatNr   r   r   r   r9   r	   r	   r	   r
   r1   I   s   r1   c                   @   s   e Zd ZdddZdd ZdS )ThirdPartyCheckerWithCaveatsNc                 C   s   |d krg }|| _ d S r   cavs)r   r=   r	   r	   r
   r   X   s    z%ThirdPartyCheckerWithCaveats.__init__c                 C   s   | j S r   r<   r   r'   r8   r	   r	   r
   r9   ]   s    z5ThirdPartyCheckerWithCaveats.check_third_party_caveat)Nr:   r	   r	   r	   r
   r;   W   s   
r;   c                   @   s   e Zd Zdd ZdS )ThirdPartyCaveatCheckerEmptyc                 C   s   g S r   r	   r>   r	   r	   r
   r9   b   s    z5ThirdPartyCaveatCheckerEmpty.check_third_party_caveatN)r   r   r   r9   r	   r	   r	   r
   r?   a   s   r?   c                 C   sB   t  }|d k	r*|| t j|jt jd t j|t | t |dS )N)
public_keyversion)keyZcheckerlocationZidentity_clientlocator)	r6   Zgenerate_keyZadd_infoZThirdPartyInfor@   ZLATEST_VERSIONZBakeryr    r*   )rC   rD   rB   r	   r	   r
   
new_bakeryf   s    rE   )N)r   r   Zmacaroonbakery.bakeryr6   Zmacaroonbakery.checkersr   objectr   ZepochZagesZcontext_with_clockZAuthContextr!   r    Z
ContextKeyr"   r$   r   r   ZIdentityClientr*   r,   ZThirdPartyCaveatCheckerr1   r;   r?   rE   r	   r	   r	   r
   <module>   s&   


