summaryrefslogtreecommitdiffstats
path: root/openpgp-ffi/include/sequoia/openpgp
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2019-01-17 11:11:27 +0100
committerJustus Winter <justus@sequoia-pgp.org>2019-01-17 16:48:28 +0100
commit3f58832474a4b270e136544016a401ef773ac065 (patch)
treec617160250c3040ca964c1b72ab5957cd872b82f /openpgp-ffi/include/sequoia/openpgp
parent38b4108cc1eac851ac17932c5c33623dd535bebb (diff)
openpgp-ffi: New crate.
- This creates a new crate, 'sequoia-openpgp-ffi', and moves a handful of functions from 'sequoia-ffi' to it. - The 'sequoia-ffi' crate is a superset of the 'sequoia-openpgp-ffi' crate. This is accomplished by some include! magic. - My first attempt involved having 'sequoia-ffi' depend on 'sequoia-openpgp-ffi', so that the former just re-exports the symbols. However, that turned out to be unreliable, and might be not what we want, because it could also duplicate parts of Rust's standard library. - Fixes #144.
Diffstat (limited to 'openpgp-ffi/include/sequoia/openpgp')
-rw-r--r--openpgp-ffi/include/sequoia/openpgp/crypto.h50
-rw-r--r--openpgp-ffi/include/sequoia/openpgp/error.h147
2 files changed, 197 insertions, 0 deletions
diff --git a/openpgp-ffi/include/sequoia/openpgp/crypto.h b/openpgp-ffi/include/sequoia/openpgp/crypto.h
new file mode 100644
index 00000000..1c30fe3f
--- /dev/null
+++ b/openpgp-ffi/include/sequoia/openpgp/crypto.h
@@ -0,0 +1,50 @@
+#ifndef SEQUOIA_OPENPGP_CRYPTO_H
+#define SEQUOIA_OPENPGP_CRYPTO_H
+
+typedef struct sq_mpi *sq_mpi_t;
+
+/*/
+/// Creates a signature.
+///
+/// This is a low-level mechanism to produce an arbitrary OpenPGP
+/// signature. Using this trait allows Sequoia to perform all
+/// operations involving signing to use a variety of secret key
+/// storage mechanisms (e.g. smart cards).
+/*/
+typedef struct sq_signer *sq_signer_t;
+
+/*/
+/// Frees a signer.
+/*/
+void sq_signer_free (sq_signer_t s);
+
+/*/
+/// A cryptographic key pair.
+///
+/// A `KeyPair` is a combination of public and secret key. If both
+/// are available in memory, a `KeyPair` is a convenient
+/*/
+typedef struct sq_key_pair *sq_key_pair_t;
+
+/* Forward declaration. */
+typedef struct sq_p_key *sq_p_key_t;
+
+/*/
+/// Creates a new key pair.
+/*/
+void sq_key_pair_new (sq_p_key_t public, sq_mpi_t secret);
+
+/*/
+/// Frees a key pair.
+/*/
+void sq_key_pair_free (sq_key_pair_t kp);
+
+/*/
+/// Creates a signer from a key pair.
+///
+/// Note that the returned object merely references the key pair, and
+/// must not outlive the key pair.
+/*/
+sq_signer_t sq_key_pair_as_signer (sq_key_pair_t kp);
+
+#endif /* SEQUOIA_OPENPGP_CRYPTO_H */
diff --git a/openpgp-ffi/include/sequoia/openpgp/error.h b/openpgp-ffi/include/sequoia/openpgp/error.h
new file mode 100644
index 00000000..dd42753c
--- /dev/null
+++ b/openpgp-ffi/include/sequoia/openpgp/error.h
@@ -0,0 +1,147 @@
+#ifndef SEQUOIA_ERRORS_H
+#define SEQUOIA_ERRORS_H
+
+#include <stddef.h>
+#include <stdint.h>
+#include <limits.h>
+
+/* XXX: Reorder and name-space before release. */
+typedef enum sq_status {
+ /*/
+ /// The operation was successful.
+ /*/
+ SQ_STATUS_SUCCESS = 0,
+
+ /*/
+ /// An unknown error occurred.
+ /*/
+ SQ_STATUS_UNKNOWN_ERROR = -1,
+
+ /*/
+ /// The network policy was violated by the given action.
+ /*/
+ SQ_STATUS_NETWORK_POLICY_VIOLATION = -2,
+
+ /*/
+ /// An IO error occurred.
+ /*/
+ SQ_STATUS_IO_ERROR = -3,
+
+ /*/
+ /// A given argument is invalid.
+ /*/
+ SQ_STATUS_INVALID_ARGUMENT = -15,
+
+ /*/
+ /// The requested operation is invalid.
+ /*/
+ SQ_STATUS_INVALID_OPERATION = -4,
+
+ /*/
+ /// The packet is malformed.
+ /*/
+ SQ_STATUS_MALFORMED_PACKET = -5,
+
+ /*/
+ /// Unsupported hash algorithm.
+ /*/
+ SQ_STATUS_UNSUPPORTED_HASH_ALGORITHM = -9,
+
+ /*/
+ /// Unsupported public key algorithm.
+ /*/
+ SQ_STATUS_UNSUPPORTED_PUBLICKEY_ALGORITHM = -18,
+
+ /*/
+ /// Unsupported elliptic curve.
+ /*/
+ SQ_STATUS_UNSUPPORTED_ELLIPTIC_CURVE = -21,
+
+ /*/
+ /// Unsupported symmetric algorithm.
+ /*/
+ SQ_STATUS_UNSUPPORTED_SYMMETRIC_ALGORITHM = -10,
+
+ /*/
+ /// Unsupported AEAD algorithm.
+ /*/
+ SQ_STATUS_UNSUPPORTED_AEAD_ALGORITHM = -26,
+
+ /*/
+ /// Unsupport signature type.
+ /*/
+ SQ_STATUS_UNSUPPORTED_SIGNATURE_TYPE = -20,
+
+ /*/
+ /// Invalid password.
+ /*/
+ SQ_STATUS_INVALID_PASSWORD = -11,
+
+ /*/
+ /// Invalid session key.
+ /*/
+ SQ_STATUS_INVALID_SESSION_KEY = -12,
+
+ /*/
+ /// Missing session key.
+ /*/
+ SQ_STATUS_MISSING_SESSION_KEY = -27,
+
+ /*/
+ /// Malformed TPK.
+ /*/
+ SQ_STATUS_MALFORMED_TPK = -13,
+
+ /*/
+ /// Bad signature.
+ /*/
+ SQ_STATUS_BAD_SIGNATURE = -19,
+
+ /*/
+ /// Message has been manipulated.
+ /*/
+ SQ_STATUS_MANIPULATED_MESSAGE = -25,
+
+ /*/
+ /// Malformed message.
+ /*/
+ SQ_STATUS_MALFORMED_MESSAGE = -22,
+
+ /*/
+ /// Index out of range.
+ /*/
+ SQ_STATUS_INDEX_OUT_OF_RANGE = -23,
+
+ /*/
+ /// TPK not supported.
+ /*/
+ SQ_STATUS_UNSUPPORTED_TPK = -24,
+
+ /* Dummy value to make sure the enumeration has a defined size. Do
+ not use this value. */
+ SQ_STATUS_FORCE_WIDTH = INT_MAX,
+} sq_status_t;
+
+/*/
+/// Complex errors returned from Sequoia.
+/*/
+typedef struct sq_error *sq_error_t;
+
+/*/
+/// Frees an error.
+/*/
+void sq_error_free (sq_error_t error);
+
+/*/
+/// Returns the error message.
+///
+/// The returned value must be freed with `free(3)`.
+/*/
+char *sq_error_string (const sq_error_t err);
+
+/*/
+/// Returns the error status code.
+/*/
+sq_status_t sq_error_status (const sq_error_t err);
+
+#endif