Ë
    ëSûep  ã                   ó’   — d 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 ddl	m
Z
 dZdZ G d	„ d
e
j                  «      Z G d„ d«      Zy)aÅ  
Copyright (c) 2022, Ian Santopietro
All rights reserved.

This file is part of RepoLib.

RepoLib is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

RepoLib is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with RepoLib.  If not, see <https://www.gnu.org/licenses/>.
é    N)ÚPath)Úrequesté   )Úutilzhttps://keyserver.ubuntu.com/z/pks/lookup?op=get&options=mr&exact=on&search=0xc                   ó(   ‡ — e Zd ZdZddœˆ fd„
Zˆ xZS )ÚKeyFileErrorz% Exceptions related to apt key files.r   )Úcodec                ó2   •— t        ‰| �  |i |¤Ž || _        y)z‡Exceptions related to apt key files.

        Arguments:
            code (:obj:`int`, optional, default=1): Exception error code.
    N)ÚsuperÚ__init__r	   )Úselfr	   ÚargsÚkwargsÚ	__class__s       €ú-/usr/lib/python3/dist-packages/repolib/key.pyr   zKeyFileError.__init__'   s   ø€ ô 	‰Ñ˜$Ð) &Ò)Øˆ�	ó    )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ú__classcell__)r   s   @r   r   r   $   s   ø„ Ù/à#$÷ ò r   r   c            	       ó\   — e Zd ZdZddeddfd„Zddedededdfd„Zdd	„Zdd
„Zdd„Z	dd„Z
y)Ú	SourceKeyz A signing key for an apt source.ÚnameÚreturnNc                 ó  — t        j                  t        «      | _        t	        «       | _        t	        «       | _        t        j                  «       | _	        d| _
        |r#| j                  |¬«       | j                  «        y y )Nr   )r   )ÚloggingÚ	getLoggerr   Úlogr   Útmp_pathÚpathÚgnupgÚGPGÚgpgÚdataÚ
reset_pathÚ	setup_gpg)r   r   s     r   r   zSourceKey.__init__3   sZ   € Ü×$Ñ$¤XÓ.ˆŒÜ›ˆŒÜ“FˆŒ	Ü—9‘9“;ˆŒØˆŒ	áØ�O‰O ˆOÔ&Ø�N‰NÕð r   r!   Úsuffixc                 ó  — | j                   j                  d«       |s|st        d«      ‚|r9|› d|› d�}t        j                  |z  | _        t        j                  |z  | _        n>|r<t        |«      | _        t        j                  | j                  j                  z  | _        | j                  «        | j                   j                  d| j                  «       | j                   j                  d| j
                  «       y)a%  Set the path for this key
        
        Arguments:
            suffix(str): The suffix to append to the end of the name to get the
                file name (default: 'archive-keyring')
            name(str): The name of the source
            path(str): The entire path to the key
        zSetting pathz/A name is required to set the path for this keyú-z.gpgzKey Path: %szTemp Path: %sN)r   Úinfor   r   ÚTEMP_DIRr    ÚKEYS_DIRr!   r   r   r'   Údebug)r   r   r!   r(   Ú	file_names        r   r&   zSourceKey.reset_path>   s¶   € ð 	�‰�‰�nÔ%Ù™DÜÐPÓQÐQáØ˜&  & ¨Ð.ˆIÜ ŸM™M¨IÑ5ˆDŒMÜŸ™¨	Ñ1ˆD�IÙÜ˜T›
ˆDŒIÜ ŸM™M¨D¯I©I¯N©NÑ:ˆDŒMà�‰Ôà�‰�‰�~ t§y¡yÔ1Ø�‰�‰�¨¯©Õ6r   c                 óÌ  — | j                   j                  d«       | j                   j                  d| j                  | j                  «       	 t        j                  | j                  | j                  «       t        j                  t        | j                  «      ¬«      | _        | j                   j                  d| j                  j                  «       y# t        $ r Y Œjw xY w)z#Set up the GPG object for this key.zSetting up GPGzCopying %s to %s)ÚkeyringzGPG Setup: %sN)r   r+   r.   r!   r    ÚshutilÚcopy2ÚFileNotFoundErrorr"   r#   Ústrr$   r1   )r   s    r   r'   zSourceKey.setup_gpgX   s–   € à�‰�‰Ð&Ô'Ø�‰�‰Ð)¨4¯9©9°d·m±mÔDð	Ü�L‰L˜Ÿ™ D§M¡MÔ2ô
 —9‘9¤S¨¯©Ó%7Ô8ˆŒØ�‰�‰�¨¯©×(8Ñ(8Õ9øô	 !ò 	Ùð	ús   Á*C Ã	C#Ã"C#c                 óÎ  — | j                   j                  d| j                  | j                  «       | j                   j	                  d| j
                  j                  «       «       | j                   j	                  d| j                  j                  «       «       t        j                  j                  «       s!	 t        j                  j                  d¬«       	 t        j                  | j                  | j                  «       y# t        $ r | j                   j                  d«       Y ŒRw xY w# t        $ r¬ t        j                   «       }	 |j#                  dd«      }|j%                  t'        | j                  «      t'        | j                  «      «       Y y# t        j(                  j*                  $ r* | j                   j-                  d	«       t/        d
«       Y Y yw xY ww xY w)zSaves the key to disk.zSaving key file %s from %szKey contents: %szTemp key exists? %sT)ÚparentszPKey destination path does not exist and cannot be created Failures expected now.úorg.pop_os.repolibú/RepoúDBus service not found!ú%Permission denied. Please use `sudo`.N)r   r+   r!   r    r.   r$   Ú	list_keysÚexistsr   r-   ÚmkdirÚPermissionErrorÚerrorr2   ÚcopyÚdbusÚ	SystemBusÚ
get_objectÚinstall_signing_keyr5   Ú
exceptionsÚDBusExceptionÚcriticalÚprint©r   ÚbusÚprivileged_objects      r   Úsave_gpgzSourceKey.save_gpge   s\  € à�‰�‰Ð2°D·I±I¸t¿}¹}ÔMØ�‰�‰Ð)¨4¯8©8×+=Ñ+=Ó+?Ô@Ø�‰�‰Ð,¨d¯m©m×.BÑ.BÓ.DÔEÜ�}‰}×#Ñ#Ô%ðÜ—‘×#Ñ#¨DÐ#Ô1ð	Ü�K‰K˜Ÿ™ t§y¡yÕ1øô #ò Ø—‘—‘ð-öðûô ò 	Ü—.‘.Ó"ˆCð	Ø$'§N¡NÐ3GÈÓ$QÐ!Ø!×5Ñ5Ü˜Ÿ™Ó&Ü˜Ÿ	™	“Nöøô —?‘?×0Ñ0ò Ø—‘×!Ñ!Ð";Ô<ÜÐ=Ô>Úðúð	ús>   Â9 D Ã*D/ Ä$D,Ä+D,Ä/G$ÅA
FÆAG ÇG$ÇG Ç G$c                 óÊ  — 	 | j                   j                  «        | j                  j                  «        y# t        $ r˜ t	        j
                  «       }	 |j                  dd«      }|j                  t        | j                  «      «       Y y# t        j                  j                  $ r* | j                  j                  d«       t        d«       Y Y yw xY wt        $ r Y yw xY w)zDeletes the key file from disk.r8   r9   r:   r;   N)r    Úunlinkr!   r?   rB   rC   rD   Údelete_signing_keyr5   rF   rG   r   rH   rI   r4   rJ   s      r   Ú
delete_keyzSourceKey.delete_key‚   s´   € ð	Ø�M‰M× Ñ Ô"Ø�I‰I×ÑÕøäò 	Ü—.‘.Ó"ˆCðØ$'§N¡NÐ3GÈÓ$QÐ!Ø!×4Ñ4´S¸¿¹³^ÖDøÜ—?‘?×0Ñ0ò Ø—‘×!Ñ!Ð";Ô<ÜÐ=Ô>Úðúô
 !ò 	Ùð	ús.   ‚47 ·C"Á6BÂACÃC"ÃCÃC"Ã!C"c                 ó  — | j                   j                  «       r6t        | j                   d¬«      5 }|j                  «       | _        ddd«       y| j
                  j                  «        d|v r0|d   | _        | j                  j                  | j                  «       yd|v ro| j                  j                  |d   «       | j
                  j                  «       r6t        | j
                  d¬«      5 }|j                  «       | _        ddd«       yyd|v r€t        j                  |d   «      }t        j                  |«      5 }|j                  «       j                  d«      | _        | j                  j                  | j                  «       ddd«       yd|v r¨d	|vr	t        |d	<   d
|vr	t        |d
<   |d	   |d
   z   |d   z   }t        j                  |«      }t        j                  |«      5 }|j                  «       j                  d«      | _        | j                  j                  | j                  «       ddd«       yt        d|j!                  «       › �d«      ‚# 1 sw Y   yxY w# 1 sw Y   yxY w# 1 sw Y   yxY w# 1 sw Y   yxY w)a@  Loads the key data from disk into the object for processing.

        Each of the keyword options specifies one place to look to import key 
        data. Once one is successfully imported, the method returns, so passing 
        multiple won't import multiple keys. 
        
        Keyword Arguments:
            raw(bytes): Raw data to import to the keyring
            ascii(str): ASCII-armored key data to import directly
            url(str): A URL to download key data from
            fingerprint(str): A key fingerprint to download from `keyserver`
                keyserver(str): A keyserver to download from.
                keypath(str): The path on the keyserver from which to download.
        
        NOTE: The keyserver and keypath args only affect the operation of the 
            `fingerprint` keyword.
        Úrb)ÚmodeNÚrawÚasciiÚurlzUTF-8ÚfingerprintÚ	keyserverÚkeypathz4load_key_data() got an unexpected keyword argument "z? Expected keyword arguments are: [raw, ascii, url, fingerprint])r!   r=   ÚopenÚreadr%   r    Útouchr$   Úimport_keysr   ÚRequestÚurlopenÚdecodeÚSKS_KEYSERVERÚSKS_KEYLOOKUP_PATHÚ	TypeErrorÚkeys)r   r   ÚkeyfileÚreqÚresponseÚkey_urls         r   Úload_key_datazSourceKey.load_key_data•   s!  € ð& �9‰9×ÑÔÜ�d—i‘i dÔ+ð +¨wØ#ŸL™L›N�”	÷+àà�‰×ÑÔà�F‰?Ø˜u™ˆDŒIØ�H‰H× Ñ  §¡Ô+Øà�fÑØ�H‰H× Ñ  ¨¡Ô1Ø�}‰}×#Ñ#Ô%Ü˜$Ÿ-™-¨dÔ3ð /°wØ '§¡£�D”I÷/áà�F‰?Ü—/‘/ &¨¡-Ó0ˆCÜ—‘ Ó%ð 0¨Ø$ŸM™M›O×2Ñ2°7Ó;�”	Ø—‘×$Ñ$ T§Y¡YÔ/÷0ð à˜FÑ"Ø &Ñ(Ü&3��{Ñ#à Ñ&Ü$6��yÑ!à˜[Ñ)¨F°9Ñ,=Ñ=ÀÀ}Ñ@UÑUˆGÜ—/‘/ 'Ó*ˆCÜ—‘ Ó%ð 0¨Ø$ŸM™M›O×2Ñ2°7Ó;�”	Ø—‘×$Ñ$ T§Y¡YÔ/÷0ð äØBÀ6Ç;Á;Ã=À/ÐRØMó
ð 	
÷O+àú÷/àú÷0ð ú÷0ð ús1   ²IÃ2I+ÅA
I7Ç/A
JÉI(É+I4É7J ÊJ)Ú )rk   rk   zarchive-keyring)r   N)r   r   r   r   r5   r   r&   r'   rM   rQ   rj   © r   r   r   r   0   sN   „ Ù*ñ	˜Cð 	¨ó 	ñ7˜sð 7¨cð 7Àð 7Ð\`ó 7ó4:óó:ô&>
r   r   )r   r   r2   rB   r"   Úpathlibr   Úurllibr   rk   r   rb   rc   Ú	RepoErrorr   r   rl   r   r   ú<module>rp      sH   ðñó( Û ã Û Ý Ý å à/€ØFÐ ô
�4—>‘>ô 
÷c
ò c
r   