summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2018-02-14 12:41:19 +0100
committerJustus Winter <justus@sequoia-pgp.org>2018-02-14 14:16:44 +0100
commit7815e95f6936533b07e9b8e849b29f8958c65b79 (patch)
tree142755e6798fa0faf93fcf4afcd83e79c5547b1e
parent15b9e52a868adf9762a8e1e838120f1a208a5ce3 (diff)
ffi: Bind rest of the KeyID functions.
- Also fix the error handling.
-rw-r--r--ffi/src/lib.rs26
-rw-r--r--ffi/src/sequoia.h12
2 files changed, 34 insertions, 4 deletions
diff --git a/ffi/src/lib.rs b/ffi/src/lib.rs
index 32b5cdc1..fd7ed64c 100644
--- a/ffi/src/lib.rs
+++ b/ffi/src/lib.rs
@@ -317,12 +317,12 @@ pub extern "system" fn sq_config_ephemeral(cfg: Option<&mut Config>) {
}
-/* openpgp::KeyID. */
+/* sequoia::openpgp::KeyID. */
/// Reads a binary key ID.
#[no_mangle]
pub extern "system" fn sq_keyid_from_bytes(id: *const uint8_t) -> *mut KeyID {
- if id.is_null() { return ptr::null_mut() }
+ assert!(!id.is_null());
let id = unsafe { slice::from_raw_parts(id, 8) };
Box::into_raw(Box::new(KeyID::from_bytes(id)))
}
@@ -330,7 +330,7 @@ pub extern "system" fn sq_keyid_from_bytes(id: *const uint8_t) -> *mut KeyID {
/// Reads a hex-encoded Key ID.
#[no_mangle]
pub extern "system" fn sq_keyid_from_hex(id: *const c_char) -> *mut KeyID {
- if id.is_null() { return ptr::null_mut() }
+ assert!(!id.is_null());
let id = unsafe { CStr::from_ptr(id).to_string_lossy() };
KeyID::from_hex(&id)
.map(|id| Box::into_raw(Box::new(id)))
@@ -346,6 +346,26 @@ pub extern "system" fn sq_keyid_free(keyid: *mut KeyID) {
}
}
+/// Converts the KeyID to its standard representation.
+#[no_mangle]
+pub extern "system" fn sq_keyid_to_string(id: Option<&KeyID>)
+ -> *mut c_char {
+ let id = id.expect("KeyID is NULL");
+ CString::new(id.to_string())
+ .unwrap() // Errors only on internal nul bytes.
+ .into_raw()
+}
+
+/// Converts the KeyID to a hexadecimal number.
+#[no_mangle]
+pub extern "system" fn sq_keyid_to_hex(id: Option<&KeyID>)
+ -> *mut c_char {
+ let id = id.expect("KeyID is NULL");
+ CString::new(id.to_hex())
+ .unwrap() // Errors only on internal nul bytes.
+ .into_raw()
+}
+
/* sequoia::openpgp::Fingerprint. */
diff --git a/ffi/src/sequoia.h b/ffi/src/sequoia.h
index f308d389..292b1141 100644
--- a/ffi/src/sequoia.h
+++ b/ffi/src/sequoia.h
@@ -219,10 +219,20 @@ sq_keyid_t sq_keyid_from_bytes (const uint8_t *id);
sq_keyid_t sq_keyid_from_hex (const char *id);
/*/
-/// Frees a keyid object.
+/// Frees a sq_keyid_t.
/*/
void sq_keyid_free (sq_keyid_t keyid);
+/*/
+/// Converts the KeyID to its standard representation.
+/*/
+char *sq_keyid_to_string (const sq_keyid_t fp);
+
+/*/
+/// Converts the KeyID to a hexadecimal number.
+/*/
+char *sq_keyid_to_hex (const sq_keyid_t fp);
+
/* sequoia::openpgp::Fingerprint. */