gpgme/lang/python/docs/dita/howto/part04/default-signing.dita
Ben McGinnes f0063afa71 docs: python bindings HOWTO - DITA XML version
* Due to the org-babel bug which breaks Python source code examples
  beyond the most simple snippets, ported the HOWTO to a source format
  which I *know* for sure won't break it.
* Details of the org-mode bug is in https://dev.gnupg.org/T3977
* DITA project uses DITA-OT 2.x (2.4 or 2.5, IIRC) with support for DITA 1.3.
* source files were written with oXygenXML Editor 20.0, hence the
  oXygenXML project file in the directory; however only the .ditamap
  and .dita files are required to generate any output with the
  DITA-OT.

Signed-off-by: Ben McGinnes <ben@adversary.org>
2018-05-15 13:13:16 +10:00

52 lines
2.1 KiB
XML

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dita PUBLIC "-//OASIS//DTD DITA Composite//EN" "ditabase.dtd">
<dita>
<topic id="topic_ntx_sqz_5db">
<title>Default Signatures</title>
<body>
<p>The normal or default signing process is essentially the same as is most often
invoked when also encrypting a message or file. So when the encryption component is not
utilised, the result is to produce an encoded and signed output which may or may not be
ASCII armoured and which may or may not also be compressed.</p>
<p>By default compression will be used unless GnuPG detects that the plaintext is already
compressed. ASCII armouring will be determined according to the value of
<codeph>gpg.Context().armor</codeph>.</p>
<p>The compression algorithm is selected in much the same way as the symmetric encryption
algorithm or the hash digest algorithm is when multiple keys are involved; from the
preferences saved into the key itself or by comparison with the preferences with all other
keys involved.</p>
<p>
<codeblock id="defsig-1" outputclass="language-python">import gpg
text0 = """Declaration of ... something.
"""
text = text0.encode()
c = gpg.Context(armor=True, signers=sig_src)
signed_data, result = c.sign(text, mode=gpg.constants.sig.mode.NORMAL)
with open("/path/to/statement.txt.asc", "w") as afile:
afile.write(signed_data.decode())
</codeblock>
</p>
<p>Though everything in this example is accurate, it is more likely that reading the input
data from another file and writing the result to a new file will be performed more like the
way it is done in the next example. Even if the output format is ASCII armoured.</p>
<p>
<codeblock id="defsig-2" outputclass="language-python">import gpg
with open("/path/to/statement.txt", "rb") as tfile:
text = tfile.read()
c = gpg.Context()
signed_data, result = c.sign(text, mode=gpg.constants.sig.mode.NORMAL)
with open("/path/to/statement.txt.sig", "wb") as afile:
afile.write(signed_data)
</codeblock>
</p>
</body>
</topic>
</dita>