
    W̩g                        S SK JrJrJr  S SKrS SKrS SKrS SKrSSKJ	r	  SSK
JrJr  SSKJr  SSKJ
r
  SSKJr  CCC  " S	 S
\5      r " S S\5      r " S S\5      rS rS rS rS rS rSS jr\" 5         S rS rSS jrS rS rg)    )absolute_importprint_functionunicode_literalsN   )gpgme)
errorcheck
GPGMEError)	constants)errors)utilc                      ^  \ rS rSrSrS rU 4S jrS rS rS r	\
S 5       r\
S	 5       rS
 r \" 5       rSS jr\R$                  " S5      rS rU 4S jrSrU =r$ )GpgmeWrapper,   z6Base wrapper class

Not to be instantiated directly.

c                     S U l         Xl        g N_callback_excinfowrapped)selfr   s     */usr/lib/python3/dist-packages/gpg/core.py__init__GpgmeWrapper.__init__3   s    !%    c                 \   > SR                  [        [        U ]  5       U R                  5      $ )Nz	<{}/{!r}>)formatsuperr   __repr__r   )r   	__class__s    r   r   GpgmeWrapper.__repr__7   s+    !!,.0$,,@ 	@r   c                 j   SR                  [        U R                  R                  5      /nU R                   Vs/ s H  n[	        X5      (       d  M  UPM     nnU(       a/  UR                  SR                  SR                  U5      5      5        SR                  SR                  U5      5      $ s  snf )Nz{}.{}z({}) z<{}>)r   __name__r   _boolean_propertiesgetattrappendjoin)r   accfflagss       r   __str__GpgmeWrapper.__str__;   s    ~~h(?(?@A 44I4q8H4IJJv}}SXXe_56}}SXXc]++	 Js   B0B0c                 >    [        [        U R                  5      5      $ r   )hashreprr   r   s    r   __hash__GpgmeWrapper.__hash__C   s    D&''r   c                 `    Uc  g[        U R                  5      [        UR                  5      :H  $ NF)r.   r   )r   others     r   __eq__GpgmeWrapper.__eq__F   s'    =%emm)<<<r   c                     [        5       e)zMThe name of the c type wrapped by this class

Must be set by child classes.

NotImplementedErrorr/   s    r   _ctypeGpgmeWrapper._ctypeL        "##r   c                     [        5       e)zWThe common prefix of c functions wrapped by this class

Must be set by child classes.

r8   r/   s    r   _cprefixGpgmeWrapper._cprefixU   r<   r   c                     [        5       e)z}Must be implemented by child classes.

This function must return a trueish value for all c functions
returning gpgme_error_t.r8   r   names     r   _errorcheckGpgmeWrapper._errorcheck^   s    
 "##r   c                 h  ^^ [        [        SR                  U R                  U5      5      m[        [        SR                  U R                  U5      5      mU4S jnU4S jn[	        XESR                  U5      S9n[        U R                  X5        U(       a  U" U [        U5      5        g U" U 5      $ )Nz{}get_{}z{}set_{}c                 ^   > U R                   (       d  g[        T" U R                   5      5      $ r3   r   bool)slfget_funcs    r   get1GpgmeWrapper.__wrap_boolean_property.<locals>.getl   s!    ;;-..r   c                 b   > U R                   (       d  g T" U R                   [        U5      5        g r   rG   )rI   valueset_funcs     r   set_2GpgmeWrapper.__wrap_boolean_property.<locals>.set_q   s    ;;S[[$u+.r   z{} flag)doc)r$   r   r   r>   propertysetattrr   rH   )	r   keydo_setrN   rK   rP   prJ   rO   s	          @@r   __wrap_boolean_property$GpgmeWrapper.__wrap_boolean_propertyh   s    5*"3"3DMM3"GH5*"3"3DMM3"GH	/
	/
 SI$4$4S$9:'tE{#t9r   z$gpgme_([^(]*)\(([^,]*), (.*\) -> .*)c                   ^ ^^^ US   S:X  d  T R                   c  gUT R                  ;   a  T R                  U5      $ T R                   U-   m[        [        T5      mT R                  T5      (       a  UU4S jmOU4S jm[        TS5      nU(       a  T R                  R                  SU5      nOSnUTl        [        T R                  UT5        UU 4S jnX4l        U$ )	z7On-the-fly generation of wrapper methods and propertiesr   _Nc                    > U R                   (       d  g T" U R                   /UQ76 nU R                  (       a  [        R                  " U 5        [	        UT5      $ r   )r   r   r   gpg_raise_callback_exceptionr   )rI   argsresultfuncrB   s      r   	_funcwrap+GpgmeWrapper.__getattr__.<locals>._funcwrap   sD    {{ckk1D1((66s;!&$//r   c                    > U R                   (       d  g T" U R                   /UQ76 nU R                  (       a  [        R                  " U 5        U$ r   )r   r   r   r]   )rI   r^   r_   r`   s      r   ra   rb      s<    {{ckk1D1((66s;r   __doc__z\2.\1(\3c                     > T" T/U Q76 $ r    )r^   ra   r   s    r   wrapper)GpgmeWrapper.__getattr__.<locals>.wrapper   s    T)D))r   )r>   r#   $_GpgmeWrapper__wrap_boolean_propertyr$   r   rC   _munge_docstringsubrd   rT   r   )r   rU   doc_origrR   rg   ra   r`   rB   s   `    @@@r   __getattr__GpgmeWrapper.__getattr__   s    q6S=DMM1$***//44}}s"ud#D!!0 4+''++KBCC	 	Y/	* r   c                 r   > XR                   ;   a  U R                  USU5        g[        [        U ]  X5        g)z#On-the-fly generation of propertiesTN)r#   ri   r   r   __setattr__)r   rU   rN   r   s      r   rp   GpgmeWrapper.__setattr__   s0    ***((dE:,1#=r   r   )FN)r"   
__module____qualname____firstlineno__rd   r   r   r*   r0   r5   rS   r:   r>   rC   setr#   ri   recompilerj   rm   rp   __static_attributes____classcell__r   s   @r   r   r   ,   s    @,(= $ $ $ $$ ,%, zz"IJ/b> >r   r   c            	         ^  \ rS rSrSrSSS/ \R                  \R                  SS4U 4S jjrS r	S r
/ SSSSSSSS4	S	 jrS:S
 jrS\R                  4S jrSS/ 4S jrS rS;S jrS;S jrS;S jrSS\R(                  R*                  R,                  S4S jr         S<S jr       S=S jrS rS rS>S jrS r   S?S jrS@S jr\S 5       r \ RB                  S 5       r \S 5       r"\"RB                  S 5       r"\S 5       r#\#RB                  S 5       r#\S  5       r$\$RB                  S! 5       r$S"r%S#r&S$ r'1 S%kr(S& r)S' r*S( r+S) r,S* r-SAS+ jr.S, r/S- r0S;S. jr1S/ r2S;S0 jr3S1 r4S;S2 jr5S3 r6\S4 5       r7S5 r8SBS6 jr9S7 r:S8 r;S9r<U =r=$ )CContext   ac  Context for cryptographic operations

All cryptographic operations in GPGME are performed within a
context, which contains the internal state of the operation as
well as configuration parameters.  By using several contexts you
can run several cryptographic operations in parallel, with
different configuration.

Access to a context must be synchronized.

FNc	                 l  > U(       a  SU l         Og[        R                  " 5       n	[        [        R                  " U	5      5        [        R
                  " U	5      n[        R                  " U	5        SU l         [        [        U ]'  U5        Xl
        X l        X0l        X@l        XPl        X`l        Xl        g)a  Construct a context object

Keyword arguments:
armor           -- enable ASCII armoring (default False)
textmode        -- enable canonical text mode (default False)
offline         -- do not contact external key sources (default False)
signers         -- list of keys used for signing (default [])
pinentry_mode   -- pinentry mode (default PINENTRY_MODE_DEFAULT)
protocol        -- protocol to use (default PROTOCOL_OpenPGP)
home_dir        -- state directory (default is the engine default)

FTN)ownr   new_gpgme_ctx_t_pr   	gpgme_newgpgme_ctx_t_p_valuedelete_gpgme_ctx_t_pr   r|   r   armortextmodeofflinesignerspinentry_modeprotocolhome_dir)r   r   r   r   r   r   r   r   r   tmpr   s             r   r   Context.__init__   s    * DH))+Cus+,//4G&&s+DHgt%g.
 *  r   c                 x    U(       d  Uc  gUR                  S[        R                  5        UR                  5       $ )z`Read helper

Helper function to retrieve the results of an operation, or
None if SINK is given.
Nr   )seekosSEEK_SETread)r   sinkdatas      r   __read__Context.__read__   s,     4<		!R[[!yy{r   c                 $    SR                  U 5      $ )NzContext(armor={0.armor}, textmode={0.textmode}, offline={0.offline}, signers={0.signers}, pinentry_mode={0.pinentry_mode}, protocol={0.protocol}, home_dir={0.home_dir}))r   r/   s    r   r   Context.__repr__   s     VD\		"r   Tc                   ^ U(       a  UO	[        5       nSnX[        R                  -  -  nX(       + [        R                  -  -  nX[        R                  -  -  nX[        R
                  -  -  nX(       + [        R                  -  -  nTbG  U R                  n[        U SS5      n[        R                  U l        SU4S jjnU R                  U5         U(       a  U R                  X,X5        OU R                  X,X5         Tb  WU l        [6        R8                  " U W5        U R                  5       nUR(                  (       a   eU(       a  U R!                  5       OSnU(       a  UR0                  (       a   eU R#                  XK5      UU4$ ! [        R                   Ga  nU R                  5       nU(       a  U R!                  5       OSnU R#                  XK5      UU4nUR%                  5       [        R&                  :X  a;  UR(                  (       a*  [        R*                  " UR(                  UR,                  US9eUR%                  5       [        R.                  :X  aK  U R!                  5       nUR0                  (       a*  [        R2                  " UR0                  UR,                  US9eUUl        UeSnAff = f! Tb  WU l        [6        R8                  " U W5        f f = f)a  Encrypt data

Encrypt the given plaintext for the given recipients.  If the
list of recipients is empty, the data is encrypted
symmetrically with a passphrase.

The passphrase can be given as parameter, using a callback
registered at the context, or out-of-band via pinentry.

Keyword arguments:
recipients      -- list of keys to encrypt to
sign            -- sign plaintext (default True)
sink            -- write result to sink instead of returning it
passphrase      -- for symmetric encryption
always_trust    -- always trust the keys (default False)
add_encrypt_to  -- encrypt to configured additional keys (default False)
prepare         -- (ui) prepare for encryption (default False)
expect_sign     -- (ui) prepare for signing (default False)
compress        -- compress plaintext (default True)

Returns:
ciphertext      -- the encrypted data (or None if sink is given)
result          -- additional information about the encryption
sign_result     -- additional information about the signature(s)

Raises:
InvalidRecipients -- if encryption using a particular key failed
InvalidSigners  -- if signing using a particular key failed
GPGMEError      -- as signaled by the underlying library

r   N_passphrase_cbc                    > T$ r   rf   hintdescprev_badhook
passphrases       r   passphrase_cb&Context.encrypt.<locals>.passphrase_cb5  	    !!r   errorresultsr   )Datar
   ENCRYPT_ALWAYS_TRUSTENCRYPT_NO_ENCRYPT_TOENCRYPT_PREPAREENCRYPT_EXPECT_SIGNENCRYPT_NO_COMPRESSr   r$   PINENTRY_MODE_LOOPBACKset_passphrase_cbop_encrypt_sign
op_encryptr   r	   op_encrypt_resultop_sign_resultr   getcodeUNUSABLE_PUBKEYinvalid_recipientsInvalidRecipientsr   UNUSABLE_SECKEYinvalid_signersInvalidSignersr   r   gpg_set_passphrase_cb)r   	plaintext
recipientssignr   r   always_trustadd_encrypt_toprepareexpect_signcompress
ciphertextr)   old_pinentry_modeold_passphrase_cbr   er_   
sig_resultr   s        `              r   encryptContext.encrypt   su   T "Ttv
	 > >>>$	(G(GGG94444y<<<<,)"?"???! $ 2 2 '.> E!*!A!AD" ""=1	E$$Z	N
9I. %%6"++D2CD''),,,,.2T((*
Z%?%???}}T.
BB?    	++-F26,,.DJ}}T6
KGyy{f444,, 2211gg ') ) yy{f444!002
-- //"22gg ') )  AIG)	, %%6"++D2CD &s7   F .J: /F J: J7"DJ22J77J: :$Kc                   ^ SnSnU(       a  UO	[        5       nTbG  U R                  n	[        U SS5      n
[        R                  U l        SU4S jjnU R                  U5         [        U[        5      (       a  UnO#Uc  [        R                  " S[        S9  SnOUnSnU(       a  U R                  X5        OU R                  X5         Tb  W	U l        [&        R(                  " U W
5        U R                  5       nU(       a  U R!                  5       nOSnU R#                  X(5      X4nUR*                  (       a  [        R,                  " UR*                  US9eU(       a  U(       a%  [/        [1        S	 UR2                  5      5      Ul        Ub  / nU H  nSnUR4                   Ho  nUR2                   HS  nUR6                  [        R8                  -  S
:X  a  M&  UR:                  (       a  UR<                  UR<                  :X  a  Sn  O   U(       d  Mo    O   U(       a  M  UR?                  U5        M     U(       a  [        R@                  " UUUS9eU$ ! [        R                   aI  nU R                  5       nU(       a  U R!                  5       nOSnU R#                  X(5      X4Ul        UeSnAff = f! Tb  W	U l        [&        R(                  " U W
5        f f = f)a=  Decrypt data

Decrypt the given ciphertext and verify any signatures.  If
VERIFY is an iterable of keys, the ciphertext must be signed
by all those keys, otherwise a MissingSignatures error is
raised.  Note: if VERIFY is an empty iterable, that is treated
the same as passing verify=True (that is, verify signatures
and return data about any valid signatures found, but no
signatures are required and no MissingSignatures error will be
raised).

The filter_signatures argument can be used to force this
function to return signatures that are not fully trusted - for
example because they were made by unknown keys.

If the ciphertext is symmetrically encrypted using a
passphrase, that passphrase can be given as parameter, using a
callback registered at the context, or out-of-band via
pinentry.

Keyword arguments:
sink            -- write result to sink instead of returning it
passphrase      -- for symmetric decryption
verify          -- check signatures (boolean or iterable of keys,
                   see above) (default True)
filter_signatures  -- if this function should filter out signatures
                   that are not completely OK (default True)

Returns:
plaintext       -- the decrypted data (or None if sink is given)
result          -- additional information about the decryption
verify_result   -- additional information about the valid
                   signature(s) found

Raises:
UnsupportedAlgorithm -- if an unsupported algorithm was used
MissingSignatures    -- if expected signatures are missing or bad
GPGMEError           -- as signaled by the underlying library

FNr   c                    > T$ r   rf   r   s       r   r   &Context.decrypt.<locals>.passphrase_cb  r   r   zTctx.decrypt called with verify=None, should be bool or iterable (treating as False).categoryTr   c                 <    U R                   [        R                  :H  $ r   statusr   NO_ERROR)ss    r   <lambda>!Context.decrypt.<locals>.<lambda>  s    V__A\r   r   r   )!r   r   r$   r
   r   r   
isinstancerH   warningswarnDeprecationWarningop_decrypt_verify
op_decryptr   r	   op_decrypt_resultop_verify_resultr   r   r   r   unsupported_algorithmUnsupportedAlgorithmlistfilter
signaturessubkeyssummarySIGSUM_VALIDcan_signfprr%   MissingSignatures)r   r   r   r   verifyfilter_signaturesdo_sig_verificationrequired_keysr   r   r   r   r   r_   verify_resultr   missingrU   oksubkeysigs      `                 r   decryptContext.decrypt`  s   R $ Ddf	! $ 2 2 '.> E!*!A!AD" ""=1	E&$''&,#j/1 ',# !'&*#"&&z=
6 %%6"++D2CD'') 113M M==16I''--f.J.J6=? ?  +/7\^k^v^v0w+x(((CB"%++#0#;#;C"{{Y-C-CCqH (%6::3H%)! $< 2! #. 2s+ )  22=';BD D c    	++-F" $ 5 5 7 $t7OAIG	 %%6"++D2CD &s8   $AI 7J3 8I 	J3 J0'AJ++J00J3 3$Kc                 
   U(       a  UO	[        5       n U R                  XU5        U R                  5       nUR                  (       a   eU R	                  X$5      U4$ ! [        R                   a  nU R	                  X$5      U R                  5       4nUR                  5       [        R                  :X  aA  US   R                  (       a-  [        R                  " US   R                  UR                  US9eXel        UeSnAff = f)a  Sign data

Sign the given data with either the configured default local
key, or the 'signers' keys of this context.

Keyword arguments:
mode            -- signature mode (default: normal, see below)
sink            -- write result to sink instead of returning it

Returns:
either
  signed_data   -- encoded data and signature (normal mode)
  signature     -- only the signature data (detached mode)
  cleartext     -- data and signature as text (cleartext mode)
    (or None if sink is given)
result          -- additional information about the signature(s)

Raises:
InvalidSigners  -- if signing using a particular key failed
GPGMEError      -- as signaled by the underlying library

r   r   N)r   op_signr   r	   r   r   r   r   r   r   r   r   )r   r   r   mode
signeddatar   r   r_   s           r   r   Context.sign  s    . "Ttv
	LL40 $$&))))}}T.66    		}}T68K8K8MNGyy{f4441:-- //
22gg ') )  IG		s   A D1BC==Dc                    U(       a  SnOU(       a  UO	[        5       n U(       a  U R                  X!S5        OU R                  USU5         U R	                  X55      U R                  5       4n[        S US   R                   5       5      (       a  [        R                  " US   US9e[        5       nU H  n	Sn
U	R                   Hv  nUS   R                   HW  nUR                  [        R                  -  S:X  a  M&  UR                  (       d  M9  UR                   UR                   :X  d  MU  Sn
  O   U
(       d  Mv    O   U
(       a  M  UR#                  U	5        M     U(       a  [        R$                  " US   XS9eU$ ! [        R                   a-  nU R	                  X55      U R                  5       4Ul        UeSnAff = f)a  Verify signatures

Verify signatures over data.  If VERIFY is an iterable of
keys, the ciphertext must be signed by all those keys,
otherwise an error is raised.

Keyword arguments:
signature       -- detached signature data
sink            -- write result to sink instead of returning it

Returns:
data            -- the plain data
    (or None if sink is given, or we verified a detached signature)
result          -- additional information about the signature(s)

Raises:
BadSignatures   -- if a bad signature is encountered
MissingSignatures -- if expected signatures are missing or bad
GPGMEError      -- as signaled by the underlying library

Nc              3   Z   #    U  H!  oR                   [        R                  :g  v   M#     g 7fr   r   ).0r   s     r   	<genexpr>!Context.verify.<locals>.<genexpr>-  s     J4Iqxx6??*4Is   )+r   r   Fr   T)r   	op_verifyr   r	   r   r   r   anyr   BadSignaturesr   r   r   r
   r   r   r   r%   r   )r   signed_data	signaturer   r   r   r   r   r   rU   r   r   r   s                r   r   Context.verify  s   , D4TVD	yt<{D$7 ==,d.C.C.EFJGAJ4I4IJJJ&&wqz7CC&CB++"1:00C{{Y%;%;;q@ 6::+@! 1 2 & 2s#  **
G6 6 7    	t2D4I4I4KLAIG	s   F  F   G(F<<Gc                     U R                  U5        U R                  5       nUR                  S:X  a  [        R                  nO[        R
                  n U[        R
                  :X  a  WnU$ UnU$ ! [         a  nU[        R                  :X  a:  UR                  S:X  a  [        R                  n SnAN_[        R                  n SnANtU[        :X  a$  [        US5      SL a  [        R                  n SnANU[        :X  a$  [        US5      SL a  [        R                  n SnAN[        R                  n SnANSnAff = f)aK  Import data

Imports the given data into the Context.

Returns:
        -- an object describing the results of imported or updated
           keys

Raises:
TypeError      -- Very rarely.
GPGMEError     -- as signaled by the underlying library:

                  Import status errors, when they occur, will usually
                  be of NODATA.  NO_PUBKEY indicates something
                  managed to run the function without any
                  arguments, while an argument of None triggers
                  the first NODATA of errors.GPGME in the
                  exception.
r   zNo datadecodeTencodeN)	op_importop_import_result
consideredr
   STATUS_IMPORT_PROBLEMSTATUS_KEY_CONSIDERED	Exceptionr   r	   code_strSTATUS_NODATASTATUS_FILE_ERROR	TypeErrorhasattrSTATUS_NO_PUBKEYSTATUS_ERROR)r   r   r_   r   r   import_results         r   
key_importContext.key_importD  s    (	0NN4 **,F  A%"88"88 Y444"M  #M%  	0F%%%::*&44F&88FiGD($;t$C"33iGD($;t$C"44"//	0s6   AA1 A1 1
D?;4D:4D:	)D:7)D:%D::D?c                     [        5       nSn U R                  XU5        UR                  S[        R                  5        UR                  5       n[        U5      S:  a  UnU$ SnU$ ! [         a  nUeSnAff = f)a  Export keys.

Exports public keys matching the pattern specified.  If no
pattern is specified then exports all available keys.

Keyword arguments:
pattern -- return keys matching pattern (default: all keys)

Returns:
        -- A key block containing one or more OpenPGP keys in
           either ASCII armoured or binary format as determined
           by the Context().  If there are no matching keys it
           returns None.

Raises:
GPGMEError     -- as signaled by the underlying library.
r   N)r   	op_exportr   r   r   r   r	   lenr   patternr   r   	pk_resultr   r_   s          r   
key_exportContext.key_exports  s}    $ v	NN7$/IIa%		I y>AF  F  	G	s   AA' '
A81A33A8c                    [        5       n[        R                  n U R                  XU5        UR	                  S[
        R                  5        UR                  5       n[        U5      S:  a  UnU$ SnU$ ! [         a  nUeSnAff = f)a  Export keys.

Exports public keys matching the pattern specified in a
minimised format.  If no pattern is specified then exports all
available keys.

Keyword arguments:
pattern -- return keys matching pattern (default: all keys)

Returns:
        -- A key block containing one or more minimised OpenPGP
           keys in either ASCII armoured or binary format as
           determined by the Context().  If there are no matching
           keys it returns None.

Raises:
GPGMEError     -- as signaled by the underlying library.
r   N)
r   r   GPGME_EXPORT_MODE_MINIMALr  r   r   r   r   r	   r  r  s          r   key_export_minimalContext.key_export_minimal  s    & v..	NN7$/IIa%		I y>AF  F  	G	   AA5 5
B?BBc                    [        5       n[        R                  n U R                  XU5        UR	                  S[
        R                  5        UR                  5       n[        U5      S:  a  UnU$ SnU$ ! [         a  nUeSnAff = f)a[  Export secret keys.

Exports secret keys matching the pattern specified.  If no
pattern is specified then exports or attempts to export all
available secret keys.

IMPORTANT: Each secret key to be exported will prompt for its
passphrase via an invocation of pinentry and gpg-agent.  If the
passphrase is not entered or does not match then no data will be
exported.  This is the same result as when specifying a pattern
that is not matched by the available keys.

Keyword arguments:
pattern -- return keys matching pattern (default: all keys)

Returns:
        -- On success a key block containing one or more OpenPGP
           secret keys in either ASCII armoured or binary format
           as determined by the Context().
        -- On failure while not raising an exception, returns None.

Raises:
GPGMEError     -- as signaled by the underlying library.
r   N)
r   r   GPGME_EXPORT_MODE_SECRETr  r   r   r   r   r	   r  )r   r  r   r   	sk_resultr   r_   s          r   key_export_secretContext.key_export_secret  s    2 v--	NN7$/IIa%		I y>AF  F  	G	r$  c              #   H  #    U(       d#  U R                  U5        U R                  X5        O0[        U[        5      (       d	  [        US9nU R	                  US5        U R                  5       nU(       a  Uv   U R                  5       nU(       a  M  U R                  5         g7f)a  List keys

Keyword arguments:
pattern -- return keys matching pattern (default: all keys)
secret  -- return only secret keys (default: False)
mode    -- keylist mode (default: list local keys)
source  -- read keys from source instead from the keyring
               (all other options are ignored in this case)

Returns:
        -- an iterator returning key objects

Raises:
GPGMEError      -- as signaled by the underlying library
)filer   N)set_keylist_modeop_keylist_startr   r   op_keylist_from_data_startop_keylist_nextop_keylist_end)r   r  secretr   sourcerU   s         r   keylistContext.keylist  s     ( !!$'!!'2
 fd++6*++FA6""$I&&(C c 	s   BB"B"c           	        ^	 [         R                  " T	5      (       aG  U R                  n[        U SS5      n[        R
                  U l        SU	4S jjnU R                  U5         U R                  UUSUSU(       a  [        R                  R                  OSU(       a  [        R                  R                  OS-  U(       a  [        R                  R                  OS-  U(       a  [        R                  R                  OS-  T	c  [        R                  R                  OS-  U(       a  SO[        R                  R                  -  U
(       a  [        R                  R                  OS-  5        [         R                  " T	5      (       a  WU l        [         R"                  " U W5        U R%                  5       $ ! [         R                  " T	5      (       a  WU l        [         R"                  " U W5        f f = f)a  Create a primary key

Create a primary key for the user id USERID.

ALGORITHM may be used to specify the public key encryption
algorithm for the new key.  By default, a reasonable default
is chosen.  You may use "future-default" to select an
algorithm that will be the default in a future implementation
of the engine.  ALGORITHM may be a string like "rsa", or
"rsa2048" to explicitly request an algorithm and a key size.

EXPIRES_IN specifies the expiration time of the key in number
of seconds since the keys creation.  By default, a reasonable
expiration time is chosen.  If you want to create a key that
does not expire, use the keyword argument EXPIRES.

SIGN, ENCRYPT, CERTIFY, and AUTHENTICATE can be used to
request the capabilities of the new key.  If you don't request
any, a reasonable set of capabilities is selected, and in case
of OpenPGP, a subkey with a reasonable set of capabilities is
created.

If PASSPHRASE is None (the default), then the key will not be
protected with a passphrase.  If PASSPHRASE is a string, it
will be used to protect the key.  If PASSPHRASE is True, the
passphrase must be supplied using a passphrase callback or
out-of-band with a pinentry.

Keyword arguments:
algorithm    -- public key algorithm, see above (default: reasonable)
expires_in   -- expiration time in seconds (default: reasonable)
expires      -- whether the key should expire (default: True)
sign         -- request the signing capability (see above)
encrypt      -- request the encryption capability (see above)
certify      -- request the certification capability (see above)
authenticate -- request the authentication capability (see above)
passphrase   -- protect the key with a passphrase (default: no
                passphrase)
force        -- force key creation even if a key with the same userid
                exists (default: False)

Returns:
             -- an object describing the result of the key creation

Raises:
GPGMEError   -- as signaled by the underlying library

r   Nc                    > T$ r   rf   r   s       r   r   )Context.create_key.<locals>.passphrase_cbF  r   r   r   r   )r   is_a_stringr   r$   r
   r   r   op_createkeycreateSIGNENCRCERTAUTHNOPASSWDNOEXPIREFORCEr   r   op_genkey_result)r   userid	algorithm
expires_inexpiresr   r   certifyauthenticater   forcer   r   r   s            `    r   
create_keyContext.create_key  s   v J'' $ 2 2 '.> E!*!A!AD" ""=1	E+/)""''Q+2)""'';+2)""''; ,8)""''Q@ 0:/A)""++q	J
 !I$4$4$=$=? -2)""((q:< 
++%6"++D2CD$$&&	 
++%6"++D2CD ,s   %DF9 9<G5c	                 ^  ^ [         R                  " T5      (       aG  U R                  n	[        U SS5      n
[        R
                  U l        SU4S jjnU R                  U5         U R                  UUSUU(       a  [        R                  R                  OSU(       a  [        R                  R                  OS-  U(       a  [        R                  R                  OS-  Tc  [        R                  R                  OS-  U(       a  SO[        R                  R                  -  5        [         R                  " T5      (       a  W	U l        [        R                  " U W
5        U R!                  5       $ ! [         R                  " T5      (       a  W	U l        [        R                  " U W
5        f f = f)a!  Create a subkey

Create a subkey for the given KEY.  As subkeys are a concept
of OpenPGP, calling this is only valid for the OpenPGP
protocol.

ALGORITHM may be used to specify the public key encryption
algorithm for the new subkey.  By default, a reasonable
default is chosen.  You may use "future-default" to select an
algorithm that will be the default in a future implementation
of the engine.  ALGORITHM may be a string like "rsa", or
"rsa2048" to explicitly request an algorithm and a key size.

EXPIRES_IN specifies the expiration time of the subkey in
number of seconds since the subkeys creation.  By default, a
reasonable expiration time is chosen.  If you want to create a
subkey that does not expire, use the keyword argument EXPIRES.

SIGN, ENCRYPT, and AUTHENTICATE can be used to request the
capabilities of the new subkey.  If you don't request any, an
encryption subkey is generated.

If PASSPHRASE is None (the default), then the subkey will not
be protected with a passphrase.  If PASSPHRASE is a string, it
will be used to protect the subkey.  If PASSPHRASE is True,
the passphrase must be supplied using a passphrase callback or
out-of-band with a pinentry.

Keyword arguments:
algorithm    -- public key algorithm, see above (default: reasonable)
expires_in   -- expiration time in seconds (default: reasonable)
expires      -- whether the subkey should expire (default: True)
sign         -- request the signing capability (see above)
encrypt      -- request the encryption capability (see above)
authenticate -- request the authentication capability (see above)
passphrase   -- protect the subkey with a passphrase (default: no
                passphrase)

Returns:
             -- an object describing the result of the subkey creation

Raises:
GPGMEError   -- as signaled by the underlying library

r   Nc                    > T$ r   rf   r   s       r   r   ,Context.create_subkey.<locals>.passphrase_cb  r   r   r   r   )r   r8  r   r$   r
   r   r   op_createsubkeyr:  r;  r<  r>  r?  r@  r   r   rB  )r   rU   rD  rE  rF  r   r   rH  r   r   r   r   s           `   r   create_subkeyContext.create_subkey`  sa   l J'' $ 2 2 '.> E!*!A!AD" ""=1	E  +/)""''Q+2)""'';+7)""''Q@ 0:/A)""++qJ !I$4$4$=$=	?	A 
++%6"++D2CD$$&&	 
++%6"++D2CD ,s   %CE0 0<F,c                 (    U R                  XS5        g)zAdd a UID

Add the uid UID to the given KEY.  Calling this function is
only valid for the OpenPGP protocol.

Raises:
GPGMEError   -- as signaled by the underlying library

r   N)	op_adduidr   rU   uids      r   key_add_uidContext.key_add_uid       	s#r   c                 (    U R                  XS5        g)zRevoke a UID

Revoke the uid UID from the given KEY.  Calling this function
is only valid for the OpenPGP protocol.

Raises:
GPGMEError   -- as signaled by the underlying library

r   N)	op_revuidrT  s      r   key_revoke_uidContext.key_revoke_uid  rX  r   c                 V   SnUb  [         R                  " U5      (       a  O.U[        R                  R                  -  nSR                  U5      nU(       d  U[        R                  R                  -  nU(       a  U[        R                  R                  -  nU R                  XX55        g)am  Sign a key

Sign a key with the current set of signing keys.  Calling this
function is only valid for the OpenPGP protocol.

If UIDS is None (the default), then all UIDs are signed.  If
it is a string, then only the matching UID is signed.  If it
is a list of strings, then all matching UIDs are signed.  Note
that a case-sensitive exact string comparison is done.

EXPIRES_IN specifies the expiration time of the signature in
seconds.  If EXPIRES_IN is False, the signature does not
expire.

Keyword arguments:
uids         -- user ids to sign, see above (default: sign all)
expires_in   -- validity period of the signature in seconds
                                       (default: do not expire)
local        -- create a local, non-exportable signature
                                       (default: False)

Raises:
GPGMEError   -- as signaled by the underlying library

r   N
)	r   r8  r
   keysignLFSEPr&   r@  LOCAL
op_keysign)r   rU   uidsrE  localr)   s         r   key_signContext.key_sign  s    4 <4++D11Y&&,,,E99T?DY&&///EY&&,,,E:5r   c                 &    U R                  X5        g)zSet a keys' TOFU policy

Set the TOFU policy associated with KEY to POLICY.  Calling
this function is only valid for the OpenPGP protocol.

Raises:
GPGMEError   -- as signaled by the underlying library

N)op_tofu_policy)r   rU   policys      r   key_tofu_policyContext.key_tofu_policy  s     	C(r   c           	         [         R                  " U5      (       d  [        U[        5      (       a  UnOSR	                  S U 5       5      n[
        R                  " 5       n[
        R                  " U R                  UU(       a  [        R                  " U 5      U4OSU(       a  [        R                  " U 5      U4OSU(       a  [        R                  " U 5      U4OSU5      nU R                  (       a  [
        R                  " U 5        [        U5        [
        R                  " U5      n[
        R                  " U5        US:w  a  [!        U5      $ S$ )aA  Issue a raw assuan command

This function can be used to issue a raw assuan command to the
engine.

If command is a string or bytes, it will be used as-is.  If it
is an iterable of strings, it will be properly escaped and
joined into a well-formed assuan command.

Keyword arguments:
data_cb         -- a callback receiving data lines
inquire_cb      -- a callback providing more information
status_cb       -- a callback receiving status lines

Returns:
result          -- the result of command as GPGMEError

Raises:
GPGMEError      -- as signaled by the underlying library

r!   c              3   N   #    U  H  n[         R                  " U5      v   M     g 7fr   )r   percent_escape)r   r(   s     r   r   *Context.assuan_transact.<locals>.<genexpr>  s     C7a4..q117s   #%Nr   )r   r8  r   bytesr&   r   new_gpgme_error_t_pgpgme_op_assuan_transact_extr   weakrefrefr   r]   r   gpgme_error_t_p_valuedelete_gpgme_error_t_pr	   )	r   commanddata_cb
inquire_cb	status_cbcmderrptrerrr   s	            r   assuan_transactContext.assuan_transact  s   6 G$$
7E(B(BC((C7CCC**,00LL# !(D 17;  $+;;t#4j"A# '.kk$&7%C"F	, !!..t43,,V4$$V,%+q[z&!:d:r   c                 T   Uc  [        S5      eUc
  [        5       nU(       a  [        R                  " U 5      X%4nO[        R                  " U 5      U4n[        R
                  " U R                  XUU5      nU R                  (       a  [        R                  " U 5        [        U5        g)a  Interact with the engine

This method can be used to edit keys and cards interactively.
KEY is the key to edit, FUNC is called repeatedly with two
unicode arguments, 'keyword' and 'args'.  See the GPGME manual
for details.

Keyword arguments:
sink            -- if given, additional output is written here
flags           -- use constants.INTERACT_CARD to edit a card

Raises:
GPGMEError      -- as signaled by the underlying library

NzFirst argument cannot be None)

ValueErrorr   rs  rt  r   gpgme_op_interactr   r   r]   r   )r   rU   r`   r   r)   	fnc_value
opaquedatar_   s           r   interactContext.interact1  s      ;<==<6D!++d+T=J!++d+T2J((s:)-/!!..t46r   c                     U R                   (       d  g[        U R                  5       5       Vs/ s H  oR                  U5      PM     sn$ s  snf )zKeys used for signingN)r   rangesigners_countsigners_enum)r   is     r   r   Context.signersR  s?     ||.3D4F4F4H.IJ.I!!!$.IJJJs   Ac                     U R                   nU R                  5          U H  nU R                  U5        M     g !   X l         e = fr   )r   signers_clearsigners_add)r   r   oldrU   s       r   r   r  Y  sC    ll	  % 	Ls	   9 	Ac                 "    U R                  5       $ )zPinentry mode)get_pinentry_moder/   s    r   r   Context.pinentry_moded  s     %%''r   c                 &    U R                  U5        g r   )set_pinentry_moder   rN   s     r   r   r  i  s    u%r   c                 "    U R                  5       $ )zProtocol to use)get_protocolr/   s    r   r   Context.protocolm  s       ""r   c                 d    [        [        R                  " U5      5        U R                  U5        g r   )r   r   gpgme_engine_check_versionset_protocolr  s     r   r   r  r  s#    533E:;% r   c                 R    U R                   (       d  gU R                  R                  $ )zEngine's home directoryN)r   engine_infor   r/   s    r   r   Context.home_dirw  s      ||(((r   c                 8    U R                  U R                  US9  g )N)r   )set_engine_infor   r  s     r   r   r  ~  s    T]]U;r   gpgme_ctx_tgpgme_c                 v    UR                  S5      =(       a    UR                  S5      (       + =(       d    US;   $ )?This function should list all functions returning gpgme_error_t	gpgme_op__result>   r   gpgme_cancelgpgme_get_keygpgme_set_localegpgme_set_sendergpgme_get_sig_keygpgme_signers_addgpgme_cancel_asyncgpgme_set_ctx_flaggpgme_set_protocolgpgme_set_keylist_modegpgme_set_sub_protocolgpgme_sig_notation_addgpgme_set_pinentry_modegpgme_ctx_set_engine_info)
startswithendswithrA   s     r   rC   Context._errorcheck  s=     - *y)3* 	.2 7 /		r   >   r   r   r   c                 >   [         (       d  g U R                  5         U R                  5         U R                  5         U R                  (       aP  U R
                  (       a>  [         R                  (       a(  [         R                  " U R
                  5        S U l        g g g g r   )r   _free_passcb_free_progresscb_free_statuscbr   r   gpgme_releaser/   s    r   __del__Context.__del__  se    u88)<)<-DL *=8r   c                     U $ r   rf   r/   s    r   	__enter__Context.__enter__      r   c                     gr3   rf   r   typerN   tbs       r   __exit__Context.__exit__      r   c              /      #    U R                   " U0 UD6  U R                  5       nU(       a  Uv   U R                  5       nU(       a  M  U R                  5         g 7fr   )r-  r/  r0  )r   r^   kwargsrU   s       r   op_keylist_allContext.op_keylist_all  sQ     t.v.""$I&&(C c 	   AA	Ac                    [         R                  " 5       n [        [         R                  " U R                  U5      5        [         R
                  " U5      n[         R                  " U5        U(       a
  S Ul        U$ g! [        R                   a0  nSnUR                  5       [        R                  :w  a  Ue SnANgSnAff = f)znReturns the next key in the list created
by a call to op_keylist_start().  The object returned
is of type Key.Nc                 .    [         R                  " U 5      $ r   r   gpgme_key_unrefr/   s    r   r   )Context.op_keylist_next.<locals>.<lambda>  s    u'<'<T'Br   )r   new_gpgme_key_t_pr   gpgme_op_keylist_nextr   gpgme_key_t_p_valuer   r	   r   EOFdelete_gpgme_key_t_pr  )r   ptrrU   excps       r   r/  Context.op_keylist_next  s     %%'	u224<<EF++C0C
 	""3'BCKJ     	C||~+
 ,	s   A A? ?C&B>>Cc                    [         R                  " 5       n [        [         R                  " U R                  XU5      5        [         R                  " U5      n[         R                  " U5        U(       d   eS Ul        U$ ! [
        R                   a?  nUR                  5       [
        R                  :X  a  [
        R                  " U5      eUeSnAff = f)zGet a key given a fingerprint

Keyword arguments:
secret          -- to request a secret key

Returns:
                -- the matching key

Raises:
KeyError        -- if the key was not found
GPGMEError      -- as signaled by the underlying library

Nc                 .    [         R                  " U 5      $ r   r  r/   s    r   r   !Context.get_key.<locals>.<lambda>  s    5#8#8#>r   )r   r  r   r  r   r   r	   r   r  KeyNotFoundr  r  r  )r   r   r1  r  r   rU   s         r   get_keyContext.get_key  s     %%'	u**4<<6JK '',""3'
s>
    	yy{fjj(((--G	s   +B C:CCc              /      #    U R                   " U0 UD6  U R                  5       nU(       a  Uv   U R                  5       nU(       a  M  U R                  5         g 7fr   )op_trustlist_startop_trustlist_nextop_trustlist_end)r   r^   r  trusts       r   op_trustlist_allContext.op_trustlist_all  sQ     00&&(K**,E e 	r  c                 j   [         R                  " 5       n [        [         R                  " U R                  U5      5        [         R
                  " U5      n[         R                  " U5        U$ ! [        R                   a/  nSnUR                  5       [        R                  :w  a  e  SnANVSnAff = f)z}Returns the next trust item in the list created
by a call to op_trustlist_start().  The object returned
is of type TrustItem.N)r   new_gpgme_trust_item_t_pr   gpgme_op_trustlist_nextr   gpgme_trust_item_t_p_valuer   r	   r   r  delete_gpgme_trust_item_t_p)r   r  r  r  s       r   r  Context.op_trustlist_next  s     ,,.	u44T\\3GH44S9E
 	))#.    	E||~+ ,	s   A A/ /B2%B--B2c                     Uc  SnO4Uc  [         R                  " U 5      U4nO[         R                  " U 5      X4n[        R                  " X5        g)a  Sets the passphrase callback to the function specified by func.

When the system needs a passphrase, it will call func with three args:
hint, a string describing the key it needs the passphrase for;
desc, a string describing the passphrase it needs;
prev_bad, a boolean equal True if this is a call made after
unsuccessful previous attempt.

If hook has a value other than None it will be passed into the func
as a forth argument.

Please see the GPGME manual for more information.
N)rs  rt  r   r   r   r`   r   hookdatas       r   r   Context.set_passphrase_cb  sG     <H|#KK-t4#KK-t:##D3r   c                 R    [         R                  (       a  U R                  S 5        g g r   )r   r   r   r/   s    r   r  Context._free_passcb  s    &&""4( 'r   c                     Uc  SnO4Uc  [         R                  " U 5      U4nO[         R                  " U 5      X4n[        R                  " X5        g)a  Sets the progress meter callback to the function specified by FUNC.
If FUNC is None, the callback will be cleared.

This function will be called to provide an interactive update
of the system's progress.  The function will be called with
three arguments, type, total, and current.  If HOOK is not
None, it will be supplied as fourth argument.

Please see the GPGME manual for more information.

N)rs  rt  r   gpg_set_progress_cbr  s       r   set_progress_cbContext.set_progress_cb  sG     <H|#KK-t4#KK-t:!!$1r   c                 R    [         R                  (       a  U R                  S 5        g g r   )r   r  r  r/   s    r   r  Context._free_progresscb(  s    $$  & %r   c                     Uc  SnO4Uc  [         R                  " U 5      U4nO[         R                  " U 5      X4n[        R                  " X5        g)a   Sets the status callback to the function specified by FUNC.  If
FUNC is None, the callback will be cleared.

The function will be called with two arguments, keyword and
args.  If HOOK is not None, it will be supplied as third
argument.

Please see the GPGME manual for more information.

N)rs  rt  r   gpg_set_status_cbr  s       r   set_status_cbContext.set_status_cb,  sG     <H|#KK-t4#KK-t:/r   c                 R    [         R                  (       a  U R                  S 5        g g r   )r   r  r  r/   s    r   r  Context._free_statuscb@  s    ""t$ #r   c                     U R                   nU R                  5        Vs/ s H  o"R                   U:X  d  M  UPM     nn[        U5      S:X  d   eUS   $ s  snf )z,Configuration of the engine currently in user   r   )r   get_engine_infor  )r   rW   r  infoss       r   r  Context.engine_infoD  sS     MM 002F2qjjAo2F5zQQx Gs
   AAc                 B    [         R                  " U R                  5      $ )zGet engine configuration

Returns information about all configured and installed
engines.

Returns:
infos           -- a list of engine infos

)r   gpgme_ctx_get_engine_infor   r/   s    r   r  Context.get_engine_infoL  s     ..t||<<r   c                 (    U R                  XU5        g)a  Change engine configuration

Changes the configuration of the crypto engine implementing
the protocol 'proto' for the context.

Keyword arguments:
file_name       -- engine program file name (unchanged if None)
home_dir        -- configuration directory (unchanged if None)

N)ctx_set_engine_info)r   proto	file_namer   s       r   r  Context.set_engine_infoX  s     	  8<r   c                     [         R                  " 5       n[         R                  " U R                  X!5        [         R                  " U5      n[         R
                  " U5        [        U5        g)zWait for asynchronous call to finish. Wait forever if hang is True.
Raises an exception on errors.

Please read the GPGME manual for more information.

N)r   rq  
gpgme_waitr   ru  rv  r   )r   hangr  r   s       r   waitContext.waite  sL     '')s1,,S1$$S)6r   c                 T    [         R                  " S[        S9  U R                  XXCS9$ )a  Start key editing using supplied callback function

Note: This interface is deprecated and will be removed with
GPGME 1.8.  Please use .interact instead.  Furthermore, we
implement this using gpgme_op_interact, so callbacks will get
called with string keywords instead of numeric status
messages.  Code that is using constants.STATUS_X or
constants.status.X will continue to work, whereas code using
magic numbers will break as a result.

z"Call to deprecated method op_edit.r   )r   r  )r   r   r   r  )r   rU   r`   r  outs        r   op_editContext.op_editr  s*     	0;M	O}}SS}FFr   )	r   r   r   r   r   r   r   r   r   )NNTTr   )	Nr   TFFFFNF)Nr   TFFFN)NFF)NNN)Nr   N)F)NN)>r"   rr   rs   rt   rd   r
   PINENTRY_MODE_DEFAULTPROTOCOL_OpenPGPr   r   r   r   r   SIG_MODE_NORMALr   r   r  r  r"  r(  r3  r   ra  rJ  rP  rV  r[  re  rj  r~  r  rS   r   setterr   r   r   r:   r>   rC   r#   r  r  r  r  r/  r  r  r  r   r  r  r  r  r  r  r  r  r  r  rx   ry   rz   s   @r   r|   r|      sz   
 (>>#44$!L	" "$!`CDyv #)B)B )7V -1tB <|-^ D!F'T &&++11	#N "   %"X'x !%!"" ##(!%P'd
$
$'6R
) !%#'"&	0;dB K K ^^  ( ( & & # # __! ! ) ) __< < FH" ;
 ": 4.)2*'0(%  
==G Gr   r|   c                      ^  \ rS rSrSrSrSrS r      SU 4S jjrS r	S r
S	 rS
 rS rSS jrSS jrSS jrS rS rS rS rS rSS jrSrU =r$ )r   i  a"  Data buffer

A lot of data has to be exchanged between the user and the crypto
engine, like plaintext messages, ciphertext, signatures and
information about the keys.  The technical details about
exchanging the data information are completely abstracted by
GPGME.  The user provides and receives the data via `gpgme_data_t'
objects, regardless of the communication protocol between GPGME
and the crypto engine in use.

This Data class is the implementation of the GpgmeData objects.

Please see the information about __init__ for instantiation.

gpgme_data_tgpgme_data_c                     US;  $ )r  >	   gpgme_data_readgpgme_data_seekgpgme_data_writegpgme_data_releasegpgme_data_identifygpgme_data_set_flaggpgme_data_get_encodinggpgme_data_get_file_namegpgme_data_release_and_get_memrf   rA   s     r   rC   Data._errorcheck  s      

 

 
	
r   c                 f  > [         [        U ]  S5        SU l        Ub  U R                  " U6   gUb  U R                  X5        gUb  Ub  Ub  U R                  X#U5        gUb?  [        R                  " U5      (       a  U R                  X&5        gU R                  U5        gU R                  5         g)a  Initialize a new gpgme_data_t object.

If no args are specified, make it an empty object.

If string alone is specified, initialize it with the data
contained there.

If file, offset, and length are all specified, file must
be either a filename or a file-like object, and the object
will be initialized by reading the specified chunk from the file.

If cbs is specified, it MUST be a tuple of the form:

(read_cb, write_cb, seek_cb, release_cb[, hook])

where the first four items are functions implementing reading,
writing, seeking the data, and releasing any resources once
the data object is deallocated.  The functions must match the
following prototypes:

    def read(amount, hook=None):
        return <a b"bytes" object>

    def write(data, hook=None):
        return <the number of bytes written>

    def seek(offset, whence, hook=None):
        return <the new file position>

    def release(hook=None):
        <return value and exceptions are ignored>

The functions may be bound methods.  In that case, you can
simply use the 'self' reference instead of using a hook.

If file is specified without any other arguments, then
it must be a filename, and the object will be initialized from
that file.

N)r   r   r   data_cbsnew_from_cbsnew_from_memnew_from_filepartr   r8  new_from_filenew_from_fdnew)r   stringr+  offsetlengthcbscopyr   s          r   r   Data.__init__  s    ^ 	dD"4(?s#f+&"49K""48%%""4.  &HHJr   c                    [         (       d  g U R                  bc  [         R                  (       aN  [         R                  " U R                  5        U R                  (       a  [         R                  " U 5        S U l        U R                  5         g r   )r   r   r"  r   r]   _free_datacbsr/   s    r   r  Data.__del__  sX    u<<#(@(@$$T\\2%%2248DLr   c                     U $ r   rf   r/   s    r   r  Data.__enter__  r  r   c                     gr3   rf   r  s       r   r  Data.__exit__  r  r   c                     S U l         g r   )	_data_cbsr/   s    r   r8  Data._free_datacbs  s	    r   c                     [         R                  " 5       n[        [         R                  " U5      5        [         R                  " U5      U l        [         R                  " U5        g r   )r   new_gpgme_data_t_pr   gpgme_data_newgpgme_data_t_p_valuer   delete_gpgme_data_t_p)r   r   s     r   r0  Data.new   sC    &&(5'',-11#6##C(r   c           	          [         R                  " 5       n[        [         R                  " X1[	        U5      U5      5        [         R
                  " U5      U l        [         R                  " U5        g r   )r   rB  r   gpgme_data_new_from_memr  rD  r   rE  )r   r1  r5  r   s       r   r,  Data.new_from_mem  sO    &&())#s6{DI	K11#6##C(r   c                 v   [         R                  " 5       n [        [         R                  " X1U5      5        [         R                  " U5      U l
        [         R                  " U5        g ! [        R
                   a;  nUR                  5       [        R                  :X  a  U(       d  [        S5      eUeS nAff = f)Nz#delayed reads are not yet supported)r   rB  r   gpgme_data_new_from_filer   r	   r   	INV_VALUEr  rD  r   rE  )r   filenamer5  r   r   s        r   r.  Data.new_from_file  s    &&(	u55cTJK 11#6##C(    	yy{f...t !FGG		s    A) )B8=6B33B8c                 .   [         R                  " 5       nUb  [        R                  " U 5      XUXE4nO[        R                  " U 5      XUU4n[         R                  " XU5        [         R
                  " U5      U l        [         R                  " U5        g r   )r   rB  rs  rt  gpg_data_new_from_cbsrD  r   rE  )r   read_cbwrite_cbseek_cb
release_cbr   r   r  s           r   r+  Data.new_from_cbs  s|    &&(D)7g"*H  D)7g"$H##DC811#6##C(r   c           	         [         R                  " 5       nSnSn[        R                  " U5      (       a  UnO`[         R                  " UR                  5       UR                  5      nUc.  [        S[        [        U5      5      < S[        U5      < 35      e[        [         R                  " XEXbU5      5        [         R                  " U5      U l        [         R                  " U5        g)zThis wraps the GPGME gpgme_data_new_from_filepart() function.
The argument "file" may be:

* a string specifying a file name, or
* a file-like object supporting the fileno() and the mode attribute.

NzFailed to open file from z arg )r   rB  r   r8  fdopenfilenor   r  strr  r   gpgme_data_new_from_filepartrD  r   rE  )r   r+  r2  r3  r   rM  fps          r   r-  Data.new_from_filepart%  s     &&(D!!HdkkmTYY7Bz JJ !$T", - - 	..sb/57	8 11#6##C(r   c                     [         R                  " 5       n[        [         R                  " X!R	                  5       5      5        [         R
                  " U5      U l        [         R                  " U5        g)zThis wraps the GPGME gpgme_data_new_from_fd() function.  The
argument "file" must be a file-like object, supporting the
fileno() method.

N)r   rB  r   gpgme_data_new_from_fdrX  rD  r   rE  )r   r+  r   s      r   r/  Data.new_from_fd@  sK     &&(5//[[]CD11#6##C(r   c                 &    U R                  U5        g)zThis wrap around gpgme_data_new_from_stream is an alias for
new_from_fd() method since in python there's no difference
between file stream and file descriptor.N)r/  r   r+  s     r   new_from_streamData.new_from_streamK  s     	r   c                 &    U R                  U5        g)zThis wrap around gpgme_data_new_from_estream is an alias for
new_from_fd() method since in python there's no difference
between file stream and file descriptor, but using fd broke.N)rb  ra  s     r   new_from_estreamData.new_from_estreamQ  s     	T"r   c                     [         R                  " U R                  U5      nUS:  a>  U R                  (       a  [         R                  " U 5        U$ [
        R                  " 5       eU$ )zcWrite buffer given as string or bytes.

If a string is given, it is implicitly encoded using UTF-8.r   )r   r!  r   r   r]   r	   fromSyserror)r   bufferwrittens      r   write
Data.writeW  sU     ((v>Q;%%2248  !--//r   c                    US:X  a  gUS:  a$   [         R                  " U R                  U5      nU$ / n  [         R                  " U R                  S5      n[        W5      S:X  a  OUR                  U5        ME  SR                  U5      $ !   U R                  (       a  [         R                  " U 5         W$ e = f!   U R                  (       a  [         R                  " U 5         Ne = f)zRead at most size bytes, returned as bytes.

If the size argument is negative or omitted, read until EOF is reached.

Returns the data read, or the empty string if there was no data
to read before EOF was reached.r    i   r   )r   r  r   r   r]   r  r%   r&   )r   sizer_   chunkss       r   r   	Data.readc  s     19!8..t||TB MF"224<<FF v;!#f%  88F##'))66t< M --::4@s"   !B !B; )B87B8;)C'&C')r?  r*  r   )NNNNNT)Tr   ))r"   rr   rs   rt   rd   r:   r>   rC   r   r  r  r  r8  r0  r,  r.  r+  r-  r/  rb  re  rk  r   rx   ry   rz   s   @r   r   r     s~      FH
( >@
))
)
))6	)#
!$ !$r   r   c                 .    [         R                  " U 5      $ )zReturn short algorithm string

Return a public key algorithm string (e.g. "rsa2048") for a given
SUBKEY.

Returns:
algo      - a string

)r   gpgme_pubkey_algo_string)r   s    r   pubkey_algo_stringru    s     ))&11r   c                 .    [         R                  " U 5      $ )zReturn name of public key algorithm

Return the name of the public key algorithm for a given numeric
algorithm id ALGO (cf. RFC4880).

Returns:
algo      - a string

)r   gpgme_pubkey_algo_namealgos    r   pubkey_algo_namerz    s     ''--r   c                 .    [         R                  " U 5      $ )zReturn name of hash algorithm

Return the name of the hash algorithm for a given numeric
algorithm id ALGO (cf. RFC4880).

Returns:
algo      - a string

)r   gpgme_hash_algo_namerx  s    r   hash_algo_namer}    s     %%d++r   c                 .    [         R                  " U 5      $ )zdGet protocol description

Get the string describing protocol PROTO.

Returns:
proto     - a string

)r   gpgme_get_protocol_namer  s    r   get_protocol_namer    s     ((//r   c                 .    [         R                  " U 5      $ )z|Return the address spec

Return the addr-spec (cf. RFC2822 section 4.3) from a user id UID.

Returns:
addr_spec - a string

)r   gpgme_addrspec_from_uid)rU  s    r   addrspec_from_uidr    s     ((--r   c                 .    [         R                  " U 5      $ r   )r   gpgme_check_version)versions    r   check_versionr    s    $$W--r   c                 x     [        [        R                  " U 5      5        g! [        R                   a     gf = f)NTF)r   r   r  r   r	   r  s    r   engine_check_versionr    s5    533E:; s   " 99c                      [         R                  " 5       n  [        [         R                  " U 5      5        [         R                  " U 5      n[         R                  " U 5        U$ ! [
        R                   a    S n N0f = fr   )r   new_gpgme_engine_info_t_pr   gpgme_get_engine_infogpgme_engine_info_t_p_valuer   r	   delete_gpgme_engine_info_t_p)r  infos     r   r  r    si    

)
)
+C5..s34005 
&&s+K  s   5A$ $A=<A=c                 D    [        [        R                  " XU5      5        g)a  Changes the default configuration of the crypto engine implementing
the protocol 'proto'. 'file_name' is the file name of
the executable program implementing this protocol. 'home_dir' is the
directory name of the configuration directory (engine's default is
used if omitted).N)r   r   gpgme_set_engine_info)r  r  r   s      r   r  r    s     u**5XFGr   c                 D    [        [        R                  " SX5      5        g)z(Sets the default locale used by contextsN)r   r   r  )r   rN   s     r   
set_localer    s    u%%dH<=r   c                     [         R                  " 5       n[         R                  " SX5      n[         R                  " U5      n[         R                  " U5        Uc  [        U5        X24$ [        U5      nX24$ )a2  Wait for asynchronous call on any Context  to finish.
Wait forever if hang is True.

For finished anynch calls it returns a tuple (status, context):
    status  - status return by asnynchronous call.
    context - context which caused this call to return.

Please read the GPGME manual of more information.N)r   rq  r  ru  rv  r   r|   )r  r  contextr   s       r   r  r    so     
#
#
%CtS/G((-F	  %6  '"r   r   )
__future__r   r   r   rv   r   r   rs  rn  r   r   r   r	   r
   r   objectr   r|   r   ru  rz  r}  r  r  r  r  r  r  r  r  rf   r   r   <module>r     s    I H 	 	    *   ^%5&J>6 J>ZGGl GGT&A$< A$H
2
.
,	0	.. H>
r   