doc: python bindings HOWTO

* Added instructions and code to count the number of public and secret
  keys available since it was quick and easy.
This commit is contained in:
Ben McGinnes 2018-03-09 20:45:14 +11:00
parent f2c1e8d8d5
commit 172baaf4d3

View File

@ -498,6 +498,39 @@
#+end_src
* Working with keys
:PROPERTIES:
:CUSTOM_ID: howto-keys
:END:
** Counting keys
:PROPERTIES:
:CUSTOM_ID: howto-basic-verification
:END:
Counting the number of keys in your public keybox (=pubring.kbx=),
the format shich has superceded the old keyring format
(=pubring.gpg= and =secring.gpg=) is a very simple task.
#+begin_src python
import gpg
c = gpg.Context()
seckeys = c.keylist(pattern=None, secret=True)
pubkeys = c.keylist(pattern=None, secret=False)
seclist = list(seckeys)
secnum = len(seclist)
publist = list(pubkeys)
pubnum = len(publist)
print("""
Number of secret keys: {0}
Number of public keys: {1}
""".format(secnum, pubnum)
#+end_src
* Copyright and Licensing
:PROPERTIES:
:CUSTOM_ID: copyright-and-license