HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/secretstorage/__pycache__/util.cpython-310.pyc
o

��!`r�@sndZddlZddlmZmZmZddlmZmZm	Z	m
Z
mZmZm
Z
ddlmZddlmZmZmZmZmZmZmZmZmZmZddlmZmZddlmZm Z dd	l!m"Z"m#Z#m$Z$dd
l%m&Z&dZ'edZ(ed
Z)Gdd�de�Z*dedefdd�Z+dede,de-dee-e,e,e-ffdd�Z.dede-dee/ee-ffdd�Z0dedee-de/fdd�Z1deddfdd �Z2dS)!zkThis module provides some utility functions, but these shouldn't
normally be used by external applications.�N)�Any�List�Tuple)�DBusAddress�DBusErrorResponse�	MatchRule�Message�MessageType�new_method_call�
Properties)�DBusConnection)
�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_backendzorg.freedesktop.secrets�Service�Promptc@s�eZdZdZdedededdfdd�Zd	edefd
d�Z	ded
ededefdd�Z
dedefdd�Zded
ededdfdd�ZdS)�DBusAddressWrapperz�A wrapper class around :class:`jeepney.wrappers.DBusAddress`
	that adds some additional methods for calling and working with
	properties, and converts error responses to SecretStorage
	exceptions.

	.. versionadded:: 3.0
	�path�	interface�
connection�returnNcCst�||t|�||_dS�N)r�__init__�BUS_NAME�_connection)�selfr"r#r$�r+�4/usr/lib/python3/dist-packages/secretstorage/util.pyr''s
zDBusAddressWrapper.__init__�msgc
Csxz	|jj|dd�WSty;}z&|jttfvrtd�|�|jttt	fvr6|j
}t|t�r1|d}t
|�|��d}~ww)NT)�unwrapzItem does not exist!r)r)�send_and_get_replyr�namer
rrrrr�data�
isinstance�tupler)r*r-�respr1r+r+r,r/,s
�

��z%DBusAddressWrapper.send_and_get_reply�method�	signature�bodycGst||||�}|�|�Sr&)r
r/)r*r5r6r7r-r+r+r,�call:s
zDBusAddressWrapper.callr0cCs"t|��|�}|�|�\\}}|Sr&)r�getr/)r*r0r-r6�valuer+r+r,�get_property>szDBusAddressWrapper.get_propertyr:cCs t|��|||�}|�|�dSr&)r�setr/)r*r0r6r:r-r+r+r,�set_propertyCszDBusAddressWrapper.set_property)
�__name__�
__module__�__qualname__�__doc__�strrr'rrr/r8r;r=r+r+r+r,r!s
�
�r!r$r%c	
Cs�ttt|�}t�}z|�ddtdt|j�f�\}}Wn%ty?}z|j	t
kr(�|�ddtd�\}}d|_WYd}~nd}~ww|\}}|dksJJ�t
�|d�}|�|�||_|S)z%Returns a new Secret Service session.�OpenSession�sv�ay)�s�FN�big)r!r�
SERVICE_IFACErr8rr�
my_public_keyrr0rr�	encrypted�int�
from_bytes�set_server_public_key�object_path)	r$�service�session�output�resultr4r6r:�keyr+r+r,�open_sessionHs.�
���
rUrQ�secret�content_typecCs�t|t�r|�d�}n	t|t�std��|jdusJ�|js%|jd||fS|jdus,J�dt|�d@}|t|f|�7}t	�
d�}t�|j�}t
|t�|�t����}|�|�|��}|j|||fS)zHFormats `secret` to make possible to pass it to the
	Secret Service API.zutf-8zsecret must be bytesN���)r2rB�encode�bytes�	TypeErrorrOrK�aes_key�len�os�urandomr�AESrr�CBCr�	encryptor�update�finalize)rQrVrW�padding�aes_iv�aesrd�encrypted_secretr+r+r,�
format_secret_s&


�rk�prompt_pathcCs�t|t|�}t|tdtjd�}|�|��}|�ddd�|�|�j\}}Wd�n1s.wY|dus9J�|dus?J�||fS)z�Executes the prompt in a blocking mode.

	:returns: a tuple; the first element is a boolean value showing
	          whether the operation was dismissed, the second element
	          is a list of unlocked object paths
	�	Completed)r"r#�member�typer rFrGN)	r!�PROMPT_IFACErr	�signal�filterr8�recv_until_filteredr7)r$rl�prompt�rule�signals�	dismissedrSr+r+r,�exec_promptzs��rx�pathscCsPttt|�}|�dd|�\}}t|�dkr&t||�\}\}}|dks$J�|SdS)z�Requests unlocking objects specified in `paths`.
	Returns a boolean representing whether the operation was dismissed.

	.. versionadded:: 2.1.2�Unlock�ao�F)r!rrIr8r_rx)r$ryrP�unlocked_pathsrtrwr6�unlockedr+r+r,�unlock_objects�srcCs6tttd�}tdd|d�}d|_|�dd|���dS)z�Adds match rules for the given connection.

	Currently it matches all messages from the Prompt interface, as the
	mock service (unlike GNOME Keyring) does not specify the signal
	destination.

	.. versionadded:: 3.1
	)�senderr#z/org/freedesktop/DBuszorg.freedesktop.DBus)r"r#r$�AddMatchrFN)rr(rpr!�bus_namer8�	serialise)r$ru�dbusr+r+r,�add_match_rules�s	�r�)3rAr`�typingrrr�jeepneyrrrrr	r
r�jeepney.io.blockingr�secretstorage.definesr
rrrrrrrrr�secretstorage.dhcryptorr�secretstorage.exceptionsrr�&cryptography.hazmat.primitives.ciphersrrr�cryptography.hazmat.backendsrr(rIrpr!rUr\rBrk�boolrxrr�r+r+r+r,�<module>s6$0)
�
��
�