doc: python bindings howto

* Added example for verifying both detached and "in-line" signatures.
This commit is contained in:
Ben McGinnes 2018-03-09 15:22:24 +11:00
parent f685cda281
commit ab81c2d868

View File

@ -401,15 +401,14 @@ Python bindings to programmatically leverage the GPGME library.
afile.close()
#+end_src
Detached binary signing (maybe change text to be reading a file's
content):
Detached binary signing of a file.
#+begin_src python
import gpg
text = """Declaration of ... something.
"""
tfile = open("/path/to/statement.txt", "r")
text = tfile.read()
tfile.close()
c = gpg.Context()
c.armor = True
@ -426,7 +425,31 @@ afile.close()
:CUSTOM_ID: howto-basic-verification
:END:
x
Verify a signed file, both detached and not:
#+begin_src python
import gpg
import sys
import time
c = gpg.Context()
data, result = c.verify(open(filename),
open(detached_sig_filename)
if detached_sig_filename else None)
for index, sign in enumerate(result.signatures):
print("signature", index, ":")
print(" summary: %#0x" % (sign.summary))
print(" status: %#0x" % (sign.status))
print(" timestamp: ", sign.timestamp)
print(" timestamp: ", time.ctime(sign.timestamp))
print(" fingerprint:", sign.fpr)
print(" uid: ", c.get_key(sign.fpr).uids[0].uid)
if data:
sys.stdout.buffer.write(data)
#+end_src
* Copyright and Licensing