remove extern c and no_mangle

This commit is contained in:
dignifiedquire
2019-04-27 01:42:58 +03:00
parent 9a1fcc745e
commit 1faf248e09
54 changed files with 789 additions and 1579 deletions

View File

@@ -47,8 +47,7 @@ impl Into<Vec<u8>> for cvec {
}
/// Get the length of the data of the given [cvec].
#[no_mangle]
pub unsafe extern "C" fn rpgp_cvec_len(cvec_ptr: *mut cvec) -> libc::size_t {
pub unsafe fn rpgp_cvec_len(cvec_ptr: *mut cvec) -> libc::size_t {
assert!(!cvec_ptr.is_null());
let cvec = &*cvec_ptr;
@@ -56,8 +55,7 @@ pub unsafe extern "C" fn rpgp_cvec_len(cvec_ptr: *mut cvec) -> libc::size_t {
}
/// Get a pointer to the data of the given [cvec].
#[no_mangle]
pub unsafe extern "C" fn rpgp_cvec_data(cvec_ptr: *mut cvec) -> *const u8 {
pub unsafe fn rpgp_cvec_data(cvec_ptr: *mut cvec) -> *const u8 {
assert!(!cvec_ptr.is_null());
let cvec = &*cvec_ptr;
@@ -65,8 +63,7 @@ pub unsafe extern "C" fn rpgp_cvec_data(cvec_ptr: *mut cvec) -> *const u8 {
}
/// Free the given [cvec].
#[no_mangle]
pub unsafe extern "C" fn rpgp_cvec_drop(cvec_ptr: *mut cvec) {
pub unsafe fn rpgp_cvec_drop(cvec_ptr: *mut cvec) {
assert!(!cvec_ptr.is_null());
let v = &*cvec_ptr;

View File

@@ -32,7 +32,6 @@ pub fn take_last_error() -> Option<Box<Error>> {
/// Calculate the number of bytes in the last error's error message **not**
/// including any trailing `null` characters.
#[no_mangle]
pub extern "C" fn rpgp_last_error_length() -> c_int {
LAST_ERROR.with(|prev| match *prev.borrow() {
Some(ref err) => err.to_string().len() as c_int + 1,
@@ -51,8 +50,7 @@ pub extern "C" fn rpgp_last_error_length() -> c_int {
/// If there are no recent errors then this returns `0` (because we wrote 0
/// bytes). `-1` is returned if there are any errors, for example when passed a
/// null pointer or a buffer of insufficient size.
#[no_mangle]
pub unsafe extern "C" fn rpgp_last_error_message() -> *mut c_char {
pub unsafe fn rpgp_last_error_message() -> *mut c_char {
let last_error = match take_last_error() {
Some(err) => err,
None => return ptr::null_mut(),

View File

@@ -4,11 +4,7 @@ use std::slice;
use crate::pgp::cvec;
/// Calculate the SHA256 hash of the given bytes.
#[no_mangle]
pub unsafe extern "C" fn rpgp_hash_sha256(
bytes_ptr: *const u8,
bytes_len: libc::size_t,
) -> *mut cvec {
pub unsafe fn rpgp_hash_sha256(bytes_ptr: *const u8, bytes_len: libc::size_t) -> *mut cvec {
assert!(!bytes_ptr.is_null());
assert!(bytes_len > 0);

View File

@@ -13,11 +13,7 @@ pub type public_or_secret_key = PublicOrSecret;
/// Creates an in-memory representation of a PGP key, based on the armor file given.
/// The returned pointer should be stored, and reused when calling methods "on" this key.
/// When done with it [rpgp_key_drop] should be called, to free the memory.
#[no_mangle]
pub unsafe extern "C" fn rpgp_key_from_armor(
raw: *const u8,
len: libc::size_t,
) -> *mut public_or_secret_key {
pub unsafe fn rpgp_key_from_armor(raw: *const u8, len: libc::size_t) -> *mut public_or_secret_key {
assert!(!raw.is_null());
assert!(len > 0);
@@ -38,7 +34,6 @@ pub unsafe extern "C" fn rpgp_key_from_armor(
}
/// Creates an in-memory representation of a PGP key, based on the serialized bytes given.
#[no_mangle]
pub unsafe extern "C" fn rpgp_key_from_bytes(
raw: *const u8,
len: libc::size_t,
@@ -63,8 +58,7 @@ pub unsafe extern "C" fn rpgp_key_from_bytes(
}
/// Returns the KeyID for the passed in key. The caller is responsible to call [rpgp_string_drop] with the returned memory, to free it.
#[no_mangle]
pub unsafe extern "C" fn rpgp_key_id(key_ptr: *mut public_or_secret_key) -> *mut c_char {
pub unsafe fn rpgp_key_id(key_ptr: *mut public_or_secret_key) -> *mut c_char {
assert!(!key_ptr.is_null());
let key = &*key_ptr;
@@ -77,8 +71,7 @@ pub unsafe extern "C" fn rpgp_key_id(key_ptr: *mut public_or_secret_key) -> *mut
}
/// Returns the Fingerprint for the passed in key. The caller is responsible to call [rpgp_cvec_drop] with the returned memory, to free it.
#[no_mangle]
pub unsafe extern "C" fn rpgp_key_fingerprint(key_ptr: *mut public_or_secret_key) -> *mut cvec {
pub unsafe fn rpgp_key_fingerprint(key_ptr: *mut public_or_secret_key) -> *mut cvec {
assert!(!key_ptr.is_null());
let key = &*key_ptr;
@@ -88,24 +81,21 @@ pub unsafe extern "C" fn rpgp_key_fingerprint(key_ptr: *mut public_or_secret_key
}
/// Returns `true` if this key is a public key, false otherwise.
#[no_mangle]
pub unsafe extern "C" fn rpgp_key_is_public(key_ptr: *mut public_or_secret_key) -> bool {
pub unsafe fn rpgp_key_is_public(key_ptr: *mut public_or_secret_key) -> bool {
assert!(!key_ptr.is_null());
(&*key_ptr).is_public()
}
/// Returns `true` if this key is a secret key, false otherwise.
#[no_mangle]
pub unsafe extern "C" fn rpgp_key_is_secret(key_ptr: *mut public_or_secret_key) -> bool {
pub unsafe fn rpgp_key_is_secret(key_ptr: *mut public_or_secret_key) -> bool {
assert!(!key_ptr.is_null());
(&*key_ptr).is_secret()
}
/// Frees the memory of the passed in key, making the pointer invalid after this method was called.
#[no_mangle]
pub unsafe extern "C" fn rpgp_key_drop(key_ptr: *mut public_or_secret_key) {
pub unsafe fn rpgp_key_drop(key_ptr: *mut public_or_secret_key) {
assert!(!key_ptr.is_null());
let _key = &*key_ptr;

View File

@@ -12,11 +12,7 @@ pub use pgp::composed::Message;
pub type message = Message;
/// Parse an armored message.
#[no_mangle]
pub unsafe extern "C" fn rpgp_msg_from_armor(
msg_ptr: *const u8,
msg_len: libc::size_t,
) -> *mut message {
pub unsafe fn rpgp_msg_from_armor(msg_ptr: *const u8, msg_len: libc::size_t) -> *mut message {
assert!(!msg_ptr.is_null());
assert!(msg_len > 0);
@@ -31,7 +27,6 @@ pub unsafe extern "C" fn rpgp_msg_from_armor(
}
/// Parse a message in bytes format.
#[no_mangle]
pub unsafe extern "C" fn rpgp_msg_from_bytes(
msg_ptr: *const u8,
msg_len: libc::size_t,
@@ -47,8 +42,7 @@ pub unsafe extern "C" fn rpgp_msg_from_bytes(
}
/// Decrypt the passed in message, using a password.
#[no_mangle]
pub unsafe extern "C" fn rpgp_msg_decrypt_with_password(
pub unsafe fn rpgp_msg_decrypt_with_password(
msg_ptr: *const message,
password_ptr: *const c_char,
) -> *mut message {
@@ -74,8 +68,7 @@ pub unsafe extern "C" fn rpgp_msg_decrypt_with_password(
}
/// Decrypt the passed in message, without attempting to use a password.
#[no_mangle]
pub unsafe extern "C" fn rpgp_msg_decrypt_no_pw(
pub unsafe fn rpgp_msg_decrypt_no_pw(
msg_ptr: *const message,
skeys_ptr: *const *const signed_secret_key,
skeys_len: libc::size_t,
@@ -155,8 +148,7 @@ pub struct message_decrypt_result {
}
/// Free a [message_decrypt_result].
#[no_mangle]
pub unsafe extern "C" fn rpgp_message_decrypt_result_drop(res_ptr: *mut message_decrypt_result) {
pub unsafe fn rpgp_message_decrypt_result_drop(res_ptr: *mut message_decrypt_result) {
assert!(!res_ptr.is_null());
let res = &*res_ptr;
@@ -167,8 +159,7 @@ pub unsafe extern "C" fn rpgp_message_decrypt_result_drop(res_ptr: *mut message_
/// Returns the underlying data of the given message.
/// Fails when the message is encrypted. Decompresses compressed messages.
#[no_mangle]
pub unsafe extern "C" fn rpgp_msg_to_bytes(msg_ptr: *const message) -> *mut cvec {
pub unsafe fn rpgp_msg_to_bytes(msg_ptr: *const message) -> *mut cvec {
assert!(!msg_ptr.is_null());
let msg = &*msg_ptr;
@@ -184,8 +175,7 @@ pub unsafe extern "C" fn rpgp_msg_to_bytes(msg_ptr: *const message) -> *mut cvec
}
/// Encodes the message into its ascii armored representation.
#[no_mangle]
pub unsafe extern "C" fn rpgp_msg_to_armored(msg_ptr: *const message) -> *mut cvec {
pub unsafe fn rpgp_msg_to_armored(msg_ptr: *const message) -> *mut cvec {
assert!(!msg_ptr.is_null());
let msg = &*msg_ptr;
@@ -199,8 +189,7 @@ pub unsafe extern "C" fn rpgp_msg_to_armored(msg_ptr: *const message) -> *mut cv
}
/// Encodes the message into its ascii armored representation, returning a string.
#[no_mangle]
pub unsafe extern "C" fn rpgp_msg_to_armored_str(msg_ptr: *const message) -> *mut c_char {
pub unsafe fn rpgp_msg_to_armored_str(msg_ptr: *const message) -> *mut c_char {
assert!(!msg_ptr.is_null());
let msg = &*msg_ptr;
@@ -214,8 +203,7 @@ pub unsafe extern "C" fn rpgp_msg_to_armored_str(msg_ptr: *const message) -> *mu
}
/// Free a [message], that was created by rpgp.
#[no_mangle]
pub unsafe extern "C" fn rpgp_msg_drop(msg_ptr: *mut message) {
pub unsafe fn rpgp_msg_drop(msg_ptr: *mut message) {
assert!(!msg_ptr.is_null());
let _ = &*msg_ptr;
@@ -223,8 +211,7 @@ pub unsafe extern "C" fn rpgp_msg_drop(msg_ptr: *mut message) {
}
/// Get the number of fingerprints of a given encrypted message.
#[no_mangle]
pub unsafe extern "C" fn rpgp_msg_recipients_len(msg_ptr: *mut message) -> u32 {
pub unsafe fn rpgp_msg_recipients_len(msg_ptr: *mut message) -> u32 {
assert!(!msg_ptr.is_null());
let msg = &*msg_ptr;
@@ -235,8 +222,7 @@ pub unsafe extern "C" fn rpgp_msg_recipients_len(msg_ptr: *mut message) -> u32 {
}
/// Get the fingerprint of a given encrypted message, by index, in hexformat.
#[no_mangle]
pub unsafe extern "C" fn rpgp_msg_recipients_get(msg_ptr: *mut message, i: u32) -> *mut c_char {
pub unsafe fn rpgp_msg_recipients_get(msg_ptr: *mut message, i: u32) -> *mut c_char {
assert!(!msg_ptr.is_null());
let msg = &*msg_ptr;
@@ -251,8 +237,7 @@ pub unsafe extern "C" fn rpgp_msg_recipients_get(msg_ptr: *mut message, i: u32)
}
}
#[no_mangle]
pub unsafe extern "C" fn rpgp_encrypt_bytes_to_keys(
pub unsafe fn rpgp_encrypt_bytes_to_keys(
bytes_ptr: *const u8,
bytes_len: libc::size_t,
pkeys_ptr: *const *const signed_public_key,
@@ -285,8 +270,7 @@ pub unsafe extern "C" fn rpgp_encrypt_bytes_to_keys(
Box::into_raw(Box::new(msg))
}
#[no_mangle]
pub unsafe extern "C" fn rpgp_sign_encrypt_bytes_to_keys(
pub unsafe fn rpgp_sign_encrypt_bytes_to_keys(
bytes_ptr: *const u8,
bytes_len: libc::size_t,
pkeys_ptr: *const *const signed_public_key,
@@ -333,8 +317,7 @@ pub unsafe extern "C" fn rpgp_sign_encrypt_bytes_to_keys(
Box::into_raw(Box::new(encrypted_msg))
}
#[no_mangle]
pub unsafe extern "C" fn rpgp_encrypt_bytes_with_password(
pub unsafe fn rpgp_encrypt_bytes_with_password(
bytes_ptr: *const u8,
bytes_len: libc::size_t,
password_ptr: *const c_char,

View File

@@ -18,8 +18,7 @@ pub use self::public_key::*;
pub use self::secret_key::*;
/// Free string, that was created by rpgp.
#[no_mangle]
pub unsafe extern "C" fn rpgp_string_drop(p: *mut libc::c_char) {
pub unsafe fn rpgp_string_drop(p: *mut libc::c_char) {
let _ = std::ffi::CString::from_raw(p);
// Drop
}

View File

@@ -12,11 +12,7 @@ use crate::pgp::cvec;
pub type signed_public_key = SignedPublicKey;
/// Parse a serialized public key, into the native rPGP memory representation.
#[no_mangle]
pub unsafe extern "C" fn rpgp_pkey_from_bytes(
raw: *const u8,
len: libc::size_t,
) -> *mut signed_public_key {
pub unsafe fn rpgp_pkey_from_bytes(raw: *const u8, len: libc::size_t) -> *mut signed_public_key {
assert!(!raw.is_null());
assert!(len > 0);
@@ -32,7 +28,6 @@ pub unsafe extern "C" fn rpgp_pkey_from_bytes(
}
/// Serialize the [signed_public_key] to bytes.
#[no_mangle]
pub unsafe extern "C" fn rpgp_pkey_to_bytes(pkey_ptr: *mut signed_public_key) -> *mut cvec {
assert!(!pkey_ptr.is_null());
@@ -45,8 +40,7 @@ pub unsafe extern "C" fn rpgp_pkey_to_bytes(pkey_ptr: *mut signed_public_key) ->
}
/// Get the key id of the given [signed_public_key].
#[no_mangle]
pub unsafe extern "C" fn rpgp_pkey_key_id(pkey_ptr: *mut signed_public_key) -> *mut c_char {
pub unsafe fn rpgp_pkey_key_id(pkey_ptr: *mut signed_public_key) -> *mut c_char {
assert!(!pkey_ptr.is_null());
let pkey = &*pkey_ptr;
@@ -59,8 +53,7 @@ pub unsafe extern "C" fn rpgp_pkey_key_id(pkey_ptr: *mut signed_public_key) -> *
}
/// Free the given [signed_public_key].
#[no_mangle]
pub unsafe extern "C" fn rpgp_pkey_drop(pkey_ptr: *mut signed_public_key) {
pub unsafe fn rpgp_pkey_drop(pkey_ptr: *mut signed_public_key) {
assert!(!pkey_ptr.is_null());
let _pkey = &*pkey_ptr;

View File

@@ -18,11 +18,7 @@ use crate::pgp::signed_public_key;
pub type signed_secret_key = SignedSecretKey;
/// Generates a new RSA key.
#[no_mangle]
pub unsafe extern "C" fn rpgp_create_rsa_skey(
bits: u32,
user_id: *const c_char,
) -> *mut signed_secret_key {
pub unsafe fn rpgp_create_rsa_skey(bits: u32, user_id: *const c_char) -> *mut signed_secret_key {
assert!(!user_id.is_null());
let user_id = CStr::from_ptr(user_id);
@@ -37,7 +33,6 @@ pub unsafe extern "C" fn rpgp_create_rsa_skey(
}
/// Generates a new x25519 key.
#[no_mangle]
pub unsafe extern "C" fn rpgp_create_x25519_skey(user_id: *const c_char) -> *mut signed_secret_key {
assert!(!user_id.is_null());
@@ -52,8 +47,7 @@ pub unsafe extern "C" fn rpgp_create_x25519_skey(user_id: *const c_char) -> *mut
}
/// Serialize a secret key into its byte representation.
#[no_mangle]
pub unsafe extern "C" fn rpgp_skey_to_bytes(skey_ptr: *mut signed_secret_key) -> *mut cvec {
pub unsafe fn rpgp_skey_to_bytes(skey_ptr: *mut signed_secret_key) -> *mut cvec {
assert!(!skey_ptr.is_null());
let skey = &*skey_ptr;
@@ -65,10 +59,7 @@ pub unsafe extern "C" fn rpgp_skey_to_bytes(skey_ptr: *mut signed_secret_key) ->
}
/// Get the signed public key matching the given private key. Only works for non password protected keys.
#[no_mangle]
pub unsafe extern "C" fn rpgp_skey_public_key(
skey_ptr: *mut signed_secret_key,
) -> *mut signed_public_key {
pub unsafe fn rpgp_skey_public_key(skey_ptr: *mut signed_secret_key) -> *mut signed_public_key {
assert!(!skey_ptr.is_null());
let skey = &*skey_ptr;
@@ -80,8 +71,7 @@ pub unsafe extern "C" fn rpgp_skey_public_key(
}
/// Returns the KeyID for the passed in key.
#[no_mangle]
pub unsafe extern "C" fn rpgp_skey_key_id(skey_ptr: *mut signed_secret_key) -> *mut c_char {
pub unsafe fn rpgp_skey_key_id(skey_ptr: *mut signed_secret_key) -> *mut c_char {
assert!(!skey_ptr.is_null());
let key = &*skey_ptr;
@@ -94,8 +84,7 @@ pub unsafe extern "C" fn rpgp_skey_key_id(skey_ptr: *mut signed_secret_key) -> *
}
/// Free the memory of a secret key.
#[no_mangle]
pub unsafe extern "C" fn rpgp_skey_drop(skey_ptr: *mut signed_secret_key) {
pub unsafe fn rpgp_skey_drop(skey_ptr: *mut signed_secret_key) {
assert!(!skey_ptr.is_null());
let _skey = &*skey_ptr;
@@ -103,11 +92,7 @@ pub unsafe extern "C" fn rpgp_skey_drop(skey_ptr: *mut signed_secret_key) {
}
/// Creates an in-memory representation of a Secret PGP key, based on the serialized bytes given.
#[no_mangle]
pub unsafe extern "C" fn rpgp_skey_from_bytes(
raw: *const u8,
len: libc::size_t,
) -> *mut signed_secret_key {
pub unsafe fn rpgp_skey_from_bytes(raw: *const u8, len: libc::size_t) -> *mut signed_secret_key {
assert!(!raw.is_null());
assert!(len > 0);