diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2019-01-15 17:57:35 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2019-01-15 18:02:37 +0100 |
commit | 977fae00f57ca87fa08568a3ce0f55a5382af13a (patch) | |
tree | 64afb0bfe2768efee998964a640fd3e24ec75505 /ffi/src/openpgp/keyid.rs | |
parent | 1f504ddf2d09f62ea3a68aab6deeac24aa813b54 (diff) |
ffi: Allocate returned strings using libc.
- Allocate all returned strings using libc's allocator. This has
the advantage that the user can easily use strings and free them
using free(3).
- Fixes #157.
Diffstat (limited to 'ffi/src/openpgp/keyid.rs')
-rw-r--r-- | ffi/src/openpgp/keyid.rs | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/ffi/src/openpgp/keyid.rs b/ffi/src/openpgp/keyid.rs index 045e5133..bdb93b2d 100644 --- a/ffi/src/openpgp/keyid.rs +++ b/ffi/src/openpgp/keyid.rs @@ -4,7 +4,6 @@ //! //! [`sequoia-openpgp::KeyID`]: ../../../sequoia_openpgp/enum.KeyID.html -use std::ffi::CString; use std::hash::{Hash, Hasher}; use std::ptr; use std::slice; @@ -21,6 +20,7 @@ use build_hasher; /// /// ```c /// #include <assert.h> +/// #include <stdlib.h> /// #include <string.h> /// #include <sequoia.h> /// @@ -30,7 +30,7 @@ use build_hasher; /// assert (strcmp (mr_b_as_string, "BBBB BBBB BBBB BBBB") == 0); /// /// sq_keyid_free (mr_b); -/// sq_string_free (mr_b_as_string); +/// free (mr_b_as_string); /// ``` #[no_mangle] pub extern "system" fn sq_keyid_from_bytes(id: *const uint8_t) -> *mut KeyID { @@ -77,9 +77,7 @@ pub extern "system" fn sq_keyid_hash(id: *const KeyID) pub extern "system" fn sq_keyid_to_string(id: *const KeyID) -> *mut c_char { let id = ffi_param_ref!(id); - CString::new(id.to_string()) - .unwrap() // Errors only on internal nul bytes. - .into_raw() + ffi_return_string!(id.to_string()) } /// Converts the KeyID to a hexadecimal number. @@ -87,9 +85,7 @@ pub extern "system" fn sq_keyid_to_string(id: *const KeyID) pub extern "system" fn sq_keyid_to_hex(id: *const KeyID) -> *mut c_char { let id = ffi_param_ref!(id); - CString::new(id.to_hex()) - .unwrap() // Errors only on internal nul bytes. - .into_raw() + ffi_return_string!(id.to_hex()) } /// Compares KeyIDs. |