
    F2j
                    j    d dl mZ d dlZd dlZd dlZd dlZd dlZd dlmZ ej	        rd dl
Z
	 	 dddZdS )    )annotationsN)UnsupportedOperationctxssl.SSLContextcertdatastr | byteskeydatastr | bytes | Nonepassword5typing.Callable[[], str | bytes] | str | bytes | NonereturnNonec                F   t          t          d          st          d          t          |t                    r|                    d          }|*t          |t                    r|                    d          }t          j        d          }t          j        	                    |d          }| t          j        	                    |d          nd}	 t          j
        |t          j        t          j        z             |,t          j
        |t          j        t          j        z             ddfd}t          j        |||fd          }|                                 d}	|/|-t          j        |||fd          }	|	                                 |                     |||           |	                    d           |	|		                    d           t          d           	 ||fD ]*}
|
&	 t          j        |
           # t&          $ r Y &w xY w+	 t          j        |           dS # t&          $ r Y dS w xY w# ||fD ]*}
|
&	 t          j        |
           # t&          $ r Y &w xY w+	 t          j        |           w # t&          $ r Y w w xY wxY w)a  Load cert chain using named pipes (FIFOs) instead of shm (linux).

    Creates temporary FIFOs, feeds PEM data through background threads,
    and lets ssl.SSLContext.load_cert_chain read from them. Data flows
    through kernel pipe buffers without ever touching disk.

    A single FIFO would deadlock on the second open.

    The idea came from https://github.com/jawah/urllib3.future/issues/325#issuecomment-4069433443

    :raise UnsupportedOperation: If anything goes wrong in the process.
    mkfifozhUnable to provide support for in-memory client certificate: os.mkfifo is not available on this platform.asciiNurllib3_imcc_)prefixz	cert.fifozkey.fifopathstrdatabytesr   r   c                    	 t          | d          5 }|                    |           d d d            d S # 1 swxY w Y   d S # t          $ r}|Y d }~d S d }~ww xY w)Nwb)openwriteBaseException)r   r   fe
writer_excs       b/home/thesage/.hermes/hermes-agent/venv/lib/python3.11/site-packages/urllib3/contrib/imcc/_fifo.py_write_fifoz$load_cert_chain.<locals>._write_fifo7   s    $%% "GGDMMM" " " " " " " " " " " " " " " " " "    






s2   A 6A :A :A 
AAAT)targetargsdaemon)keyfiler   g      ?)timeoutzPUnable to provide support for in-memory client certificate: FIFO writer failed: )r   r   r   r   r   r   )hasattrosr   
isinstancer   encodetempfilemkdtempr   joinr   statS_IRUSRS_IWUSR	threadingThreadstartload_cert_chainunlinkOSErrorrmdir)r   r   r	   r   tmpdir	cert_fifokey_fifor!   cert_thread
key_threadpr   s              @r    r4   r4      s@   $ 2x   
";
 
 	

 (C   ,??7++z'377..))_555FV[11I3:3Frw||FJ///DH3
	)T\DL8999Iht| ;<<<+/
	 	 	 	 	 	  &i%:4
 
 
 	.2
G$7")"(G)<T  J Ix(KKK%%%!OOCO(((!&4'14 4   " X& 	 	A}IaLLLL   D 
	HV 	 	 	DD	 X& 	 	A}IaLLLL   D 
	HV 	 	 	D	sy   DI
 <H
HH#H9 9
II
	J I)(J )
I6	3J 5I6	6J ;JJ 
JJ JJ )NN)
r   r   r   r   r	   r
   r   r   r   r   )
__future__r   r(   r.   r+   r1   typingior   TYPE_CHECKINGsslr4        r    <module>rE      s    " " " " " " 				        # # # # # #	 JJJ #'FJ	T T T T T T TrD   