o
    ¯br  ã                   @   sr   d Z ddlmZ ddlmZ ddlmZ ddlmZ eee	 
d¡ƒ d¡jƒZG dd	„ d	ejƒZG d
d„ dƒZdS )z“
Helper classes for twisted.test.test_ssl.

They are in a separate module so they will not prevent test_ssl importing if
pyOpenSSL is unavailable.
é    )ÚSSL)Ússl)ÚnativeString)ÚFilePathzutf-8s
   server.pemc                   @   s   e Zd ZdZdZdd„ ZdS )ÚClientTLSContextz:
    SSL Context Factory for client-side connections.
    é   c                 C   s   t  t j¡S )zæ
        Return an L{SSL.Context} to be use for client-side connections.

        Will not return a cached context.
        This is done to improve the test coverage as most implementation
        are caching the context.
        )r   ÚContextÚSSLv23_METHOD)Úself© r   ú:/usr/lib/python3/dist-packages/twisted/test/ssl_helpers.pyÚ
getContext   s   zClientTLSContext.getContextN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚisClientr   r   r   r   r   r      s    r   c                   @   s*   e Zd ZdZdZedfdd„Zdd„ ZdS )ÚServerTLSContextz:
    SSL Context Factory for server-side connections.
    r   Nc                 C   s   || _ |d u r
tj}|| _d S )N)Úfilenamer   r	   Ú_method)r
   r   Úmethodr   r   r   Ú__init__-   s   
zServerTLSContext.__init__c                 C   s(   t  | j¡}| | j¡ | | j¡ |S )zæ
        Return an L{SSL.Context} to be use for server-side connections.

        Will not return a cached context.
        This is done to improve the test coverage as most implementation
        are caching the context.
        )r   r   r   Úuse_certificate_filer   Úuse_privatekey_file)r
   Úctxr   r   r   r   4   s   zServerTLSContext.getContext)r   r   r   r   r   ÚcertPathr   r   r   r   r   r   r   &   s
    r   N)r   ÚOpenSSLr   Útwisted.internetr   Útwisted.python.compatr   Útwisted.python.filepathr   Ú__file__ÚencodeÚsiblingÚpathr   ÚClientContextFactoryr   r   r   r   r   r   Ú<module>   s   