HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //proc/thread-self/root/lib/python3/dist-packages/secretstorage/__pycache__/util.cpython-38.pyc
U

h��Ws�@s�dZddlZddlZddlmZmZmZmZmZm	Z	m
Z
mZmZm
Z
ddlmZmZddlmZmZddlmZmZmZddlmZddlmZd	Zed
ZGdd�dej�Zdd
d�Z dd�Z!dd�Z"dd�Z#dd�Z$dd�Z%ddd�Z&dd�Z'dS)zkThis module provides some utility functions, but these shouldn't
normally be used by external applications.�N)
�DBUS_UNKNOWN_METHOD�DBUS_NO_SUCH_OBJECT�DBUS_SERVICE_UNKNOWN�
DBUS_NO_REPLY�DBUS_NOT_SUPPORTED�DBUS_EXEC_FAILED�SS_PATH�	SS_PREFIX�ALGORITHM_DH�ALGORITHM_PLAIN)�Session�int_to_bytes)�ItemNotFoundException�"SecretServiceNotAvailableException)�Cipher�
algorithms�modes)�default_backend)�int_from_byteszorg.freedesktop.secrets�Servicec@s eZdZdZdd�Zdd�ZdS)�InterfaceWrapperzxWraps :cls:`dbus.Interface` class and replaces some D-Bus exceptions
	with :doc:`SecretStorage exceptions <exceptions>`.cs�fdd�}|S)Nc
s�z�||�WStjjk
r|}zN|��tkr6td��|��tkrNt|����|��tt	fkrjt
|�����W5d}~XYnXdS)NzItem does not exist!)�dbus�
exceptions�
DBusException�
get_dbus_namerrr�get_dbus_messagerrr)�args�kwargs�e��function_in��4/usr/lib/python3/dist-packages/secretstorage/util.py�function_outs�z3InterfaceWrapper.catch_errors.<locals>.function_outr!)�selfr r#r!rr"�catch_errorsszInterfaceWrapper.catch_errorscCs$tj�||�}t|�r |�|�}|S�N)r�	Interface�__getattr__�callabler%)r$Z	attribute�resultr!r!r"r(+s
zInterfaceWrapper.__getattr__N)�__name__�
__module__�__qualname__�__doc__r%r(r!r!r!r"rsrc
Csf|pt}z|j||dd�WStjjk
r`}z$|��tttfkrNt	|�
����W5d}~XYnXdS)z�A wrapper around :meth:`SessionBus.get_object` that raises
	:exc:`~secretstorage.exceptions.SecretServiceNotAvailableException`
	when appropriate.F)Z
introspectN)�BUS_NAMEZ
get_objectrrrrrrrrr)�bus�object_pathZservice_name�namerr!r!r"�bus_get_object1s
�r3c
Cs�t|t�}t�|td�}t�}z$|jtt�t	|j
��dd�\}}WnNtjjk
r�}z,|�
�tkrh�|jtddd�\}}d|_W5d}~XYnXtt|�d�}|�|�||_|S)z%Returns a new Secret Service session.rZsv�Z	signature�FNZbig)r3rrr'r	rZOpenSessionr
�	ByteArrayr
Z
my_public_keyrrrrr�	encryptedr�	bytearrayZset_server_public_keyr1)r0�service_obj�
service_iface�session�outputr*rr!r!r"�open_session>s,
��

r=cCs�t|t�s|�d�}|js4t�|jdt�|�|f�Sdt|�d@}|tt	|f�|�7}t
�d�}t�
|j�}t|t�|�t����}|�|�|��}t�|jt�|�t�t	|��|f�S)zHFormats `secret` to make possible to pass it to the
	Secret Service API.zutf-8r5��)�
isinstance�bytes�encoder7rZStructr1r6�lenr8�os�urandomrZAESZaes_keyrrZCBCr�	encryptor�update�finalize�Array)r;ZsecretZcontent_typeZpaddingZaes_ivZaesrFZencrypted_secretr!r!r"�
format_secretXs&


�
�rJcsDt||�}t�|td�}|jddd��fdd�}|�d|�dS)	aExecutes the given `prompt`, when complete calls `callback`
	function with two arguments: a boolean representing whether the
	operation was dismissed and a list of unlocked item paths. A main
	loop should be running and registered for this function to work.�Promptr5�sr4cs&t|tj�rt|�}�t|�|�dSr&)r@rrI�list�bool�Z	dismissedZunlocked��callbackr!r"�new_callbackvsz!exec_prompt.<locals>.new_callbackZ	CompletedN)r3rr'r	rKZconnect_to_signal)r0�promptrQZ
prompt_objZprompt_ifacerRr!rPr"�exec_promptns

rTcsJddlm}|���g���fdd�}t|||�����d�dfS)znLike :func:`exec_prompt`, but synchronous (uses loop from GLib
	API). Returns (*dismissed*, *unlocked*) tuple.r)�GLibcs ��|���|����dSr&��append�quitrO�Zloopr*r!r"rQ�s

z"exec_prompt_glib.<locals>.callback�)Z
gi.repositoryrUZMainLooprT�run)r0rSrUrQr!rYr"�exec_prompt_glib|sr\csJddlm}|g��g���fdd�}t|||�����d�dfS)zoLike :func:`exec_prompt`, but synchronous (uses loop from PyQt5
	API). Returns (*dismissed*, *unlocked*) tuple.r)�QCoreApplicationcs ��|���|����dSr&rVrO�Zappr*r!r"rQ�s

z exec_prompt_qt.<locals>.callbackrZ)ZPyQt5.QtCorer]rTZexec_)r0rSr]rQr!r^r"�exec_prompt_qt�sr_cCsnt|t�}t|t�}|j|dd�\}}t|�}t|�dkr\|rLt|||�qjt||�dSn|rj|d|�dS)a0Requests unlocking objects specified in `paths`. If `callback`
	is specified, calls it when unlocking is complete (see
	:func:`exec_prompt` description for details).
	Otherwise, uses the loop from GLib API and returns a boolean
	representing whether the operation was dismissed.

	.. versionadded:: 2.1.2Zaor4rZrFN)	r3rr�
SERVICE_IFACEZUnlockrMrCrTr\)r0�pathsrQr9r:Zunlocked_pathsrSr!r!r"�unlock_objects�s

rbcCs,z
t|�WStk
r&t|�YSXdS)z(Converts D-Bus string to unicode string.N)Zunicode�	NameError�str)�stringr!r!r"�
to_unicode�s
rf)N)N)(r.rrDZsecretstorage.definesrrrrrrrr	r
rZsecretstorage.dhcryptorr
Zsecretstorage.exceptionsrrZ&cryptography.hazmat.primitives.ciphersrrrZcryptography.hazmat.backendsrZcryptography.utilsrr/r`r'rr3r=rJrTr\r_rbrfr!r!r!r"�<module>s&0