o
    .j                     @  sz   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Zd dlm	Z	 d dl
mZ ejr1d dlZ		ddddZdZdS )    )annotationsN)sha256)UnsupportedOperationctxssl.SSLContextcertdatastr | byteskeydatastr | bytes | Nonepassword5typing.Callable[[], str | bytes] | str | bytes | NonereturnNonec              
   C  st  t jdkrt jddu rt jddu rtdt j ttd  d}t|t	r3|
d}|d	urAt|t	rA|
d}ttd
rNt|tj}neddlm}m}m}m}	m}
m} |dpg|d}|sntd||}|j}|	| }z|||tjtjB |tjtjB }W n ty } ztd| d	}~ww |dkrtdt |
  d| }d| }tj!"|du rtj!"|r|}nt#|$  tdt%|tjtjB  t&|d}|'| |r|'| |j(}W d	   n	1 sw   Y  | j)||d t#|$  tj!"|r"t*| tj!"|s0tj!"|r8t+,dt- d	S d	S )z
    Unique workaround the known limitation of CPython inability to initialize the mTLS context without files.
    Only supported on Linux, FreeBSD, and OpenBSD.
    :raise UnsupportedOperation: If anything goes wrong in the process.
    linuxfreebsdFopenbsdzQUnable to provide support for in-memory client certificate: Unsupported platform     z.pemasciiNmemfd_creater   )c_intc_ushortcdllcreate_string_buffer	get_errnoutilrtczTUnable to provide support for in-memory client certificate: libc or librt not found.z<Unable to provide support for in-memory client certificate: z/proc/self/fd/z	/dev/shm/zWUnable to provide support for in-memory client certificate: no virtual patch available?w)r   zcIn-memory client certificate: The kernel leaked a file descriptor outside of its expected lifetime.).sysplatform
startswithr   r   secretstoken_bytes	hexdigest
isinstancebytesdecodehasattrosr   MFD_CLOEXECctypesr   r   r   r   r   r   find_libraryLoadLibraryshm_openencodeO_RDWRO_CREATstatS_IRUSRS_IWUSRSystemErrorstrerrorpathexistsfdopenclosechmodopenwritenameload_cert_chainunlinkwarningswarnResourceWarning)r   r   r	   r   unique_namefdr   r   r   r   r   r   loclib	_shm_openbuf_nameer7   shm_pathfp rM   U/home/thesage/.local/lib/python3.10/site-packages/urllib3_future/contrib/imcc/_shm.pyr?      s   






 





r?   )r?   )NN)
r   r   r   r   r	   r
   r   r   r   r   )
__future__r   r)   r"   r2   r   typingrA   hashlibr   ior   TYPE_CHECKINGsslr?   __all__rM   rM   rM   rN   <module>   s    j