diff options
-rw-r--r-- | ffi/examples/configure.c | 4 | ||||
-rw-r--r-- | ffi/examples/keyserver.c | 6 | ||||
-rw-r--r-- | ffi/lang/python/sequoia/error.py | 2 | ||||
-rw-r--r-- | ffi/src/lib.rs | 2 | ||||
-rw-r--r-- | openpgp-ffi/examples/armor.c | 4 | ||||
-rw-r--r-- | openpgp-ffi/examples/encrypt-for.c | 10 | ||||
-rw-r--r-- | openpgp-ffi/examples/example.c | 2 | ||||
-rw-r--r-- | openpgp-ffi/examples/parser.c | 4 | ||||
-rw-r--r-- | openpgp-ffi/examples/reader.c | 2 | ||||
-rw-r--r-- | openpgp-ffi/include/sequoia/openpgp/error.h | 2 | ||||
-rw-r--r-- | openpgp-ffi/src/armor.rs | 12 | ||||
-rw-r--r-- | openpgp-ffi/src/error.rs | 10 | ||||
-rw-r--r-- | openpgp-ffi/src/lib.rs | 8 |
13 files changed, 29 insertions, 39 deletions
diff --git a/ffi/examples/configure.c b/ffi/examples/configure.c index 9e986613..38b15c05 100644 --- a/ffi/examples/configure.c +++ b/ffi/examples/configure.c @@ -20,14 +20,14 @@ main (int argc, char **argv) ctx = sq_config_build (cfg, &err); if (ctx == NULL) error (1, 0, "Initializing sequoia failed: %s", - pgp_error_string (err)); + pgp_error_to_string (err)); ks = sq_keyserver_sks_pool (ctx); if (ks == NULL) { pgp_error_t err = sq_context_last_error (ctx); assert (pgp_error_status (err) == PGP_STATUS_NETWORK_POLICY_VIOLATION); - char *msg = pgp_error_string (err); + char *msg = pgp_error_to_string (err); error (0, 0, "Initializing KeyServer failed as expected: %s", msg); free (msg); diff --git a/ffi/examples/keyserver.c b/ffi/examples/keyserver.c index 204e52ae..f7437472 100644 --- a/ffi/examples/keyserver.c +++ b/ffi/examples/keyserver.c @@ -18,13 +18,13 @@ main (int argc, char **argv) ctx = sq_context_new ("org.sequoia-pgp.example", &err); if (ctx == NULL) error (1, 0, "Initializing sequoia failed: %s", - pgp_error_string (err)); + pgp_error_to_string (err)); ks = sq_keyserver_sks_pool (ctx); if (ks == NULL) { pgp_error_t err = sq_context_last_error (ctx); - error (1, 0, "Initializing Keyserver failed: %s", pgp_error_string (err)); + error (1, 0, "Initializing Keyserver failed: %s", pgp_error_to_string (err)); } id = pgp_keyid_from_bytes ((uint8_t *) "\x24\x7F\x6D\xAB\xC8\x49\x14\xFE"); @@ -32,7 +32,7 @@ main (int argc, char **argv) if (tpk == NULL) { pgp_error_t err = sq_context_last_error (ctx); - error (1, 0, "Failed to retrieve key: %s", pgp_error_string (err)); + error (1, 0, "Failed to retrieve key: %s", pgp_error_to_string (err)); } char *debug = pgp_tpk_debug (tpk); diff --git a/ffi/lang/python/sequoia/error.py b/ffi/lang/python/sequoia/error.py index 192b7d18..0b434801 100644 --- a/ffi/lang/python/sequoia/error.py +++ b/ffi/lang/python/sequoia/error.py @@ -23,7 +23,7 @@ class MalformedValue(Error, ValueError): class SQError(Error): def __init__(self, o): self.__o = ffi.gc(o, lib.pgp_error_free) - super(SQError, self).__init__(sq_str(lib.pgp_error_string(self.__o))) + super(SQError, self).__init__(sq_str(lib.pgp_error_to_string(self.__o))) class Success(SQError): pass diff --git a/ffi/src/lib.rs b/ffi/src/lib.rs index 8c88b836..2a75e89d 100644 --- a/ffi/src/lib.rs +++ b/ffi/src/lib.rs @@ -100,7 +100,7 @@ //! //! tpk = pgp_tpk_from_file (&err, "../openpgp/tests/data/keys/testy.pgp"); //! if (tpk == NULL) -//! error (1, 0, "pgp_tpk_from_bytes: %s", pgp_error_string (err)); +//! error (1, 0, "pgp_tpk_from_bytes: %s", pgp_error_to_string (err)); //! //! pgp_tpk_free (tpk); //! ``` diff --git a/openpgp-ffi/examples/armor.c b/openpgp-ffi/examples/armor.c index 4c47be6c..00873761 100644 --- a/openpgp-ffi/examples/armor.c +++ b/openpgp-ffi/examples/armor.c @@ -32,7 +32,7 @@ main (int argc, char **argv) header = pgp_armor_reader_headers (&err, armor, &header_len); if (header == NULL) - error (1, 0, "Getting headers failed: %s", pgp_error_string (err)); + error (1, 0, "Getting headers failed: %s", pgp_error_to_string (err)); assert (header_len == 2); assert (strcmp (header[0].key, "Key0") == 0 @@ -50,7 +50,7 @@ main (int argc, char **argv) assert (kind == PGP_ARMOR_KIND_FILE); if (pgp_reader_read (&err, armor, (uint8_t *) message, 12) < 0) - error (1, 0, "Reading failed: %s", pgp_error_string (err)); + error (1, 0, "Reading failed: %s", pgp_error_to_string (err)); assert (memcmp (message, "Hello world!", 12) == 0); diff --git a/openpgp-ffi/examples/encrypt-for.c b/openpgp-ffi/examples/encrypt-for.c index b34d3a9f..16295678 100644 --- a/openpgp-ffi/examples/encrypt-for.c +++ b/openpgp-ffi/examples/encrypt-for.c @@ -46,7 +46,7 @@ main (int argc, char **argv) tpk = pgp_tpk_from_bytes (&err, b, st.st_size); if (tpk == NULL) - error (1, 0, "pgp_packet_parser_from_bytes: %s", pgp_error_string (err)); + error (1, 0, "pgp_packet_parser_from_bytes: %s", pgp_error_to_string (err)); sink = pgp_writer_alloc (&cipher, &cipher_bytes); @@ -61,11 +61,11 @@ main (int argc, char **argv) &tpk, 1, PGP_ENCRYPTION_MODE_FOR_TRANSPORT); if (writer == NULL) - error (1, 0, "pgp_encryptor_new: %s", pgp_error_string (err)); + error (1, 0, "pgp_encryptor_new: %s", pgp_error_to_string (err)); writer = pgp_literal_writer_new (&err, writer); if (writer == NULL) - error (1, 0, "pgp_literal_writer_new: %s", pgp_error_string (err)); + error (1, 0, "pgp_literal_writer_new: %s", pgp_error_to_string (err)); size_t nread; uint8_t buf[4096]; @@ -77,7 +77,7 @@ main (int argc, char **argv) ssize_t written; written = pgp_writer_stack_write (&err, writer, b, nread); if (written < 0) - error (1, 0, "pgp_writer_stack_write: %s", pgp_error_string (err)); + error (1, 0, "pgp_writer_stack_write: %s", pgp_error_to_string (err)); b += written; nread -= written; @@ -87,7 +87,7 @@ main (int argc, char **argv) rc = pgp_writer_stack_finalize (&err, writer); writer = NULL; if (rc) - error (1, 0, "pgp_writer_stack_write: %s", pgp_error_string (err)); + error (1, 0, "pgp_writer_stack_write: %s", pgp_error_to_string (err)); fwrite (cipher, 1, cipher_bytes, stdout); diff --git a/openpgp-ffi/examples/example.c b/openpgp-ffi/examples/example.c index c23b4381..5b114d8f 100644 --- a/openpgp-ffi/examples/example.c +++ b/openpgp-ffi/examples/example.c @@ -36,7 +36,7 @@ main (int argc, char **argv) tpk = pgp_tpk_from_bytes (&err, b, st.st_size); if (tpk == NULL) - error (1, 0, "pgp_tpk_from_bytes: %s", pgp_error_string (err)); + error (1, 0, "pgp_tpk_from_bytes: %s", pgp_error_to_string (err)); char *debug = pgp_tpk_debug (tpk); printf ("%s", debug); diff --git a/openpgp-ffi/examples/parser.c b/openpgp-ffi/examples/parser.c index 3f9d90ab..db6a95d7 100644 --- a/openpgp-ffi/examples/parser.c +++ b/openpgp-ffi/examples/parser.c @@ -61,7 +61,7 @@ main (int argc, char **argv) rc = pgp_packet_parser_next (&err, pp, &p, &ppr); if (rc) error (1, 0, "pgp_packet_parser_from_bytes: %s", - pgp_error_string (err)); + pgp_error_to_string (err)); // We now own p. If we want, we can save it in some structure. // This would be useful when collecting PKESK packets. Either @@ -82,7 +82,7 @@ main (int argc, char **argv) } } if (ppr == NULL) - error (1, 0, "pgp_packet_parser_from_bytes: %s", pgp_error_string (err)); + error (1, 0, "pgp_packet_parser_from_bytes: %s", pgp_error_to_string (err)); fprintf (stderr, "Parsed %ld packets in %ld seconds, %.2f packets/s.\n", n, elapsed, (double) n / (double) elapsed); diff --git a/openpgp-ffi/examples/reader.c b/openpgp-ffi/examples/reader.c index 125b0e37..a293bd80 100644 --- a/openpgp-ffi/examples/reader.c +++ b/openpgp-ffi/examples/reader.c @@ -38,7 +38,7 @@ main (int argc, char **argv) reader = pgp_reader_from_bytes (b, st.st_size); tpk = pgp_tpk_from_reader (&err, reader); if (tpk == NULL) - error (1, 0, "pgp_tpk_from_reader: %s", pgp_error_string (err)); + error (1, 0, "pgp_tpk_from_reader: %s", pgp_error_to_string (err)); char *debug = pgp_tpk_debug (tpk); printf ("%s", debug); diff --git a/openpgp-ffi/include/sequoia/openpgp/error.h b/openpgp-ffi/include/sequoia/openpgp/error.h index d6fa2c5f..157eb44d 100644 --- a/openpgp-ffi/include/sequoia/openpgp/error.h +++ b/openpgp-ffi/include/sequoia/openpgp/error.h @@ -137,7 +137,7 @@ void pgp_error_free (pgp_error_t error); /// /// The returned value must be freed with `free(3)`. /*/ -char *pgp_error_string (const pgp_error_t err); +char *pgp_error_to_string (const pgp_error_t err); /*/ /// Returns the error status code. diff --git a/openpgp-ffi/src/armor.rs b/openpgp-ffi/src/armor.rs index 76836dee..b45cb09a 100644 --- a/openpgp-ffi/src/armor.rs +++ b/openpgp-ffi/src/armor.rs @@ -77,7 +77,7 @@ fn kind_to_int(kind: Option<armor::Kind>) -> c_int { /// size_t header_len; /// header = pgp_armor_reader_headers (&err, armor, &header_len); /// if (header == NULL) -/// error (1, 0, "Getting headers failed: %s", pgp_error_string (err)); +/// error (1, 0, "Getting headers failed: %s", pgp_error_to_string (err)); /// /// assert (header_len == 2); /// assert (strcmp (header[0].key, "Key0") == 0 @@ -93,7 +93,7 @@ fn kind_to_int(kind: Option<armor::Kind>) -> c_int { /// /// char message[12]; /// if (pgp_reader_read (&err, armor, (uint8_t *) message, 12) < 0) -/// error (1, 0, "Reading failed: %s", pgp_error_string (err)); +/// error (1, 0, "Reading failed: %s", pgp_error_to_string (err)); /// /// assert (pgp_armor_reader_kind (armor) == PGP_ARMOR_KIND_FILE); /// assert (memcmp (message, "Hello world!", 12) == 0); @@ -157,7 +157,7 @@ pub extern "system" fn pgp_armor_reader_from_file(errp: Option<&mut *mut ::error /// size_t header_len; /// header = pgp_armor_reader_headers (&err, armor, &header_len); /// if (header == NULL) -/// error (1, 0, "Getting headers failed: %s", pgp_error_string (err)); +/// error (1, 0, "Getting headers failed: %s", pgp_error_to_string (err)); /// /// assert (header_len == 2); /// assert (strcmp (header[0].key, "Key0") == 0 @@ -173,7 +173,7 @@ pub extern "system" fn pgp_armor_reader_from_file(errp: Option<&mut *mut ::error /// /// char message[12]; /// if (pgp_reader_read (&err, armor, (uint8_t *) message, 12) < 0) -/// error (1, 0, "Reading failed: %s", pgp_error_string (err)); +/// error (1, 0, "Reading failed: %s", pgp_error_to_string (err)); /// /// assert (pgp_armor_reader_kind (armor) == PGP_ARMOR_KIND_FILE); /// assert (memcmp (message, "Hello world!", 12) == 0); @@ -317,10 +317,10 @@ pub extern "system" fn pgp_armor_reader_headers(errp: Option<&mut *mut ::error:: /// alloc = pgp_writer_alloc (&buf, &len); /// armor = pgp_armor_writer_new (&err, alloc, PGP_ARMOR_KIND_FILE, header, 2); /// if (armor == NULL) -/// error (1, 0, "Creating armor writer failed: %s", pgp_error_string (err)); +/// error (1, 0, "Creating armor writer failed: %s", pgp_error_to_string (err)); /// /// if (pgp_writer_write (&err, armor, (uint8_t *) message, strlen (message)) < 0) -/// error (1, 0, "Writing failed: %s", pgp_error_string (err)); +/// error (1, 0, "Writing failed: %s", pgp_error_to_string (err)); // /// pgp_writer_free (armor); /// pgp_writer_free (alloc); diff --git a/openpgp-ffi/src/error.rs b/openpgp-ffi/src/error.rs index 3d4dd3ca..6eb63000 100644 --- a/openpgp-ffi/src/error.rs +++ b/openpgp-ffi/src/error.rs @@ -2,7 +2,6 @@ use failure; use std::io; -use libc::c_char; extern crate sequoia_openpgp as openpgp; @@ -14,15 +13,6 @@ extern crate sequoia_openpgp as openpgp; #[::ffi_wrapper_type(prefix = "pgp_", derive = "Display")] pub struct Error(failure::Error); -/// Returns the error message. -/// -/// The returned value must be freed with `free(3)`. -#[::ffi_catch_abort] #[no_mangle] -pub extern "system" fn pgp_error_string(error: *const Error) - -> *mut c_char { - ffi_return_string!(&format!("{}", error.ref_raw())) -} - /// Returns the error status code. #[::ffi_catch_abort] #[no_mangle] pub extern "system" fn pgp_error_status(error: *const Error) diff --git a/openpgp-ffi/src/lib.rs b/openpgp-ffi/src/lib.rs index ca0c4158..54f37eb5 100644 --- a/openpgp-ffi/src/lib.rs +++ b/openpgp-ffi/src/lib.rs @@ -86,7 +86,7 @@ //! pgp_error_t err; //! pgp_tpk_t tpk = pgp_tpk_from_file (&err, "../openpgp/tests/data/keys/testy.pgp"); //! if (tpk == NULL) -//! error (1, 0, "pgp_tpk_from_file: %s", pgp_error_string (err)); +//! error (1, 0, "pgp_tpk_from_file: %s", pgp_error_to_string (err)); //! //! /* XXX: Do something interesting. */ //! @@ -149,11 +149,11 @@ //! [`pgp_packet_parser_from_bytes`]: parse/fn.pgp_packet_parser_from_bytes.html //! //! Errors may be inspected using [`pgp_error_status`], and formatted -//! as an error message using [`pgp_error_string`]. Errors must be freed +//! as an error message using [`pgp_error_to_string`]. Errors must be freed //! using [`pgp_error_free`]. //! //! [`pgp_error_status`]: error/fn.pgp_error_status.html -//! [`pgp_error_string`]: error/fn.pgp_error_string.html +//! [`pgp_error_to_string`]: error/fn.pgp_error_to_string.html //! [`pgp_error_free`]: error/fn.pgp_error_free.html //! //! ## Types @@ -304,7 +304,7 @@ //! pgp_error_t err; //! char message[12]; //! if (pgp_reader_read (&err, armor, (uint8_t *) message, 12) != 12) -//! error (1, 0, "Reading failed: %s", pgp_error_string (err)); +//! error (1, 0, "Reading failed: %s", pgp_error_to_string (err)); //! //! assert (pgp_armor_reader_kind (armor) == PGP_ARMOR_KIND_FILE); //! assert (memcmp (message, "Hello world!", 12) == 0); |