|
1 |
| -= Using RNP’s C APIs |
| 1 | += Using the RNP C API |
2 | 2 |
|
3 |
| -If you’re a developer and wish to use the RNP library in your projects, |
4 |
| -you can use the examples below to see how it may be done. |
| 3 | +This document is for developers who wish to use RNP as a library in C. |
5 | 4 |
|
6 |
| -== Samples |
| 5 | +Examples are given below to demonstrate such usage. |
| 6 | + |
| 7 | +== Examples |
7 | 8 |
|
8 | 9 | [TIP]
|
9 |
| -.Where to find the examples |
| 10 | +.Location of examples |
10 | 11 | ====
|
11 |
| -Find the source code for these examples |
12 |
| -under `https://github.com/rnpgp/rnp/blob/master/src/examples/[src/examples]`. |
| 12 | +The source code of these examples can be found under |
| 13 | +`https://github.com/rnpgp/rnp/blob/master/src/examples/[src/examples]`. |
13 | 14 |
|
14 |
| -If you’re building from source, the examples are built together with the RNP library |
15 |
| -and are available in `src/examples` directory of your build folder. |
| 15 | +If you are planning to build from source, these examples are built |
| 16 | +together with the RNP library and will be available under `src/examples` |
| 17 | +within your build folder. |
16 | 18 | ====
|
17 | 19 |
|
18 | 20 | [TIP]
|
19 | 21 | ====
|
20 |
| -All samples below use APIs exposed via header file |
21 |
| -`https://github.com/rnpgp/rnp/blob/master/include/rnp/rnp.h[include/rnp/rnp.h]`, |
22 |
| -check it out for more documentation. |
| 22 | +All samples below use APIs exposed via the header file |
| 23 | +`https://github.com/rnpgp/rnp/blob/master/include/rnp/rnp.h[include/rnp/rnp.h]`. |
| 24 | +For further details please refer to the file directly. |
23 | 25 | ====
|
24 | 26 |
|
25 |
| -Following sample applications are available: |
| 27 | +The following example applications are available: |
| 28 | + |
| 29 | +`generate`:: Demonstrates generating keys, save/load of keyrings, exporting keys. |
26 | 30 |
|
27 |
| -`generate`:: Includes code which shows how to generate keys, save/load keyrings, export keys. |
| 31 | +`encrypt`:: Demonstrates how to encrypt a file using a password and/or key. |
28 | 32 |
|
29 |
| -`encrypt`:: Includes code which shows how to encrypt file, using the password and/or key. |
| 33 | +`decrypt`:: Demonstrates how to decrypt OpenPGP data using a key and/or password. |
30 | 34 |
|
31 |
| -`decrypt`:: This one shows how to decrypt OpenPGP data, using the key or password. |
| 35 | +`sign`:: Demonstrates how to sign messages, using one or more keys from a loaded keyring. |
32 | 36 |
|
33 |
| -`sign`:: Shows how to sign messages, using the key(s) from loaded keyring. |
| 37 | +`verify`:: Demonstrates how to verify signed messages using dynamic keys fetching |
| 38 | + (using a sample key provider implementation). |
34 | 39 |
|
35 |
| -`verify`:: Shows how to verify signed messages using dynamic keys fetching (sample key provider implementation). |
| 40 | +`dump`:: Demonstrates how to dump OpenPGP packet information. |
36 | 41 |
|
37 |
| -`dump`:: Shows how to dump OpenPGP packet information. |
38 | 42 |
|
39 |
| -=== https://github.com/rnpgp/rnp/blob/master/src/examples/generate.c[generate.c] |
| 43 | +=== generate.c |
| 44 | + |
| 45 | +Location: https://github.com/rnpgp/rnp/blob/master/src/examples/generate.c |
40 | 46 |
|
41 | 47 | This example is composed from 2 functions:
|
42 | 48 |
|
43 |
| - * `ffi_generate_keys()`: this shows how to generate and save different key types |
44 |
| - (RSA and EDDSA/Curve25519) using the JSON key description. |
45 |
| - This also demonstrates the usage of password provider. |
| 49 | +* `ffi_generate_keys()`: Demonstrates how to generate and save different key types |
| 50 | + (RSA and EDDSA/Curve25519) using JSON key description. |
| 51 | + Also demonstrates usage of the password provider. |
46 | 52 | +
|
47 | 53 | Keyrings will be saved to files `pubring.pgp` and `secring.pgp` in the current directory.
|
48 | 54 | You can use `rnp --list-packets pubring.pgp` to check the properties of the generated key(s).
|
49 | 55 |
|
50 |
| - * `ffi_output_keys()`: This shows how to load keyrings, |
51 |
| - search for the keys (in helper functions `ffi_print_key()`/`ffi_export_key()`), |
52 |
| - and export them to memory or file in armored format. |
| 56 | +* `ffi_output_keys()`: Demonstrates how to load keyrings, |
| 57 | + search for keys (in helper functions `ffi_print_key()`/`ffi_export_key()`), |
| 58 | + and how to export them to memory or file in armored format. |
| 59 | + |
| 60 | +=== encrypt.c |
| 61 | + |
| 62 | +Location: https://github.com/rnpgp/rnp/blob/master/src/examples/encrypt.c |
| 63 | + |
| 64 | +This code example does the following: |
| 65 | + |
| 66 | +* first loads a public keyring (`pubring.pgp`) (created by the `generate.c` example) |
| 67 | +* then creates an encryption operation structure and |
| 68 | +* configures it with various options (including the setup of password encryption and public-key encryption). |
53 | 69 |
|
54 |
| -=== https://github.com/rnpgp/rnp/blob/master/src/examples/encrypt.c[encrypt.c] |
| 70 | +The result is the encrypted and armored (for easier reading) message |
| 71 | +`RNP encryption sample message`. |
55 | 72 |
|
56 |
| -This code sample first loads public keyring (`pubring.pgp`) (created by the “generate.c” example), |
57 |
| -then creates encryption operation structure and configures it with various options |
58 |
| -(including the setup of password encryption and public-key encryption). |
| 73 | +This message is saved to the file `encrypted.asc` in current directory. |
59 | 74 |
|
60 |
| -The result is the encrypted and armored (for easier reading) message `RNP encryption sample message`. |
61 |
| -It is saved to the file `encrypted.asc` in current directory. |
| 75 | +What you can do after: |
62 | 76 |
|
63 |
| -You can investigate it via the `rnp --list-packets encrypted.asc` command. |
64 |
| -Also, you may want to decrypt saved file via `rnp --keyfile secring.pgp -d encrypted.asc`. |
| 77 | +* Inspect the message with `rnp --list-packets encrypted.asc`. |
| 78 | +* Decrypt the saved file via `rnp --keyfile secring.pgp -d encrypted.asc`. |
65 | 79 |
|
66 |
| -=== https://github.com/rnpgp/rnp/blob/master/src/examples/decrypt.c[decrypt.c] |
| 80 | +=== decrypt.c |
67 | 81 |
|
68 |
| -This example uses keyrings generated in the “generate.c” sample to decrypt messages |
69 |
| -encrypted by the “encrypt.c” sample. |
| 82 | +Location: https://github.com/rnpgp/rnp/blob/master/src/examples/decrypt.c |
70 | 83 |
|
71 |
| -It shows how to decrypt message with password or with a key |
72 |
| -and implements custom password provider for decryption or key password. |
| 84 | +This example uses keyrings generated from the `generate.c` example |
| 85 | +to decrypt messages encrypted by the `encrypt.c` example. |
73 | 86 |
|
74 |
| -Decrypted message is saved to the memory and then printed to the stdout. |
| 87 | +This example demonstrates how to decrypt message with a password or with a key, |
| 88 | +and implements a custom password provider for decryption via key or key password. |
75 | 89 |
|
76 |
| -=== https://github.com/rnpgp/rnp/blob/master/src/examples/sign.c[sign.c] |
| 90 | +The decrypted message is saved to memory and then printed to the `stdout`. |
77 | 91 |
|
78 |
| -This sample uses keyrings generated in the preceding “generate.c” sample. |
| 92 | +=== sign.c |
79 | 93 |
|
80 |
| -This sample configures signing context and signs the message, saving it to the `signed.asc` file. |
81 |
| -Attached signature is used, i.e. the data is encapsulated into the resulting message. |
| 94 | +Location: https://github.com/rnpgp/rnp/blob/master/src/examples/sign.c |
82 | 95 |
|
83 |
| -You can investigate the signed message by issuing `rnp --list-packets signed.asc` command. |
84 |
| -To verify message, use `rnp --keyfile pubring.pgp -v signed.asc`. |
| 96 | +This example uses keyrings generated in the preceding `generate.c` example. |
85 | 97 |
|
86 |
| -=== https://github.com/rnpgp/rnp/blob/master/src/examples/verify.c[verify.c] |
| 98 | +It demonstrates configuration of a signing context, signing of the message, |
| 99 | +and the saving of the detached signature to the `signed.asc` file. |
87 | 100 |
|
88 |
| -This example uses keyrings generated in the “generate.c” sample. |
| 101 | +Then the attached signature is used: i.e. the data is encapsulated into |
| 102 | +the resulting message. |
| 103 | + |
| 104 | +What you can do after: |
| 105 | + |
| 106 | +* Inspect the signed message with `rnp --list-packets signed.asc`. |
| 107 | +* Verify the message with `rnp --keyfile pubring.pgp -v signed.asc`. |
| 108 | + |
| 109 | +=== verify.c |
| 110 | + |
| 111 | +Location: https://github.com/rnpgp/rnp/blob/master/src/examples/verify.c[ |
| 112 | + |
| 113 | +This example uses keyrings generated in the `generate.c` example. |
89 | 114 |
|
90 | 115 | However, instead of loading the whole keyring, it implements dynamic key fetching
|
91 | 116 | via custom key provider (see function `example_key_provider`).
|
92 | 117 |
|
93 |
| -After verification this sample outputs the verified embedded message |
94 |
| -and all signatures with signing key ids and statuses. |
| 118 | +After verification, it outputs the verified embedded message |
| 119 | +and all signatures to `stdout` (with signing key IDs and statuses). |
| 120 | + |
| 121 | +=== dump.c |
95 | 122 |
|
96 |
| -=== https://github.com/rnpgp/rnp/blob/master/src/examples/dump.c[dump.c] |
| 123 | +Location: https://github.com/rnpgp/rnp/blob/master/src/examples/dump.c[ |
97 | 124 |
|
98 |
| -This example dumps OpenPGP packet information from the input stream (stdin or filename), |
99 |
| -tuned with flags passed via command line interface. |
| 125 | +This example dumps OpenPGP packet information from the input stream |
| 126 | +(via `stdin` or filename), tuned with flags passed via the |
| 127 | +command-line interface. |
100 | 128 |
|
101 |
| -Resulting human-readable text or JSON is dumped to stdout. |
| 129 | +The resulting human-readable text or JSON is printed to `stdout`. |
0 commit comments