Skip to content

Commit

Permalink
ffi: Drop dependency on num_traits::ToPrimitive
Browse files Browse the repository at this point in the history
We were only using it on enums, and unconditionally at that, so Rust's
built-in numeric casts will have the same effect.
  • Loading branch information
jrose-signal committed Oct 22, 2020
1 parent 7759a7d commit b6caa7a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 10 deletions.
2 changes: 0 additions & 2 deletions rust/bridge/ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ crate-type = ["staticlib"]
libsignal-protocol-rust = { path = "../../protocol" }
rand = "0.7.3"
libc = "0.2"
num-traits = "0.2"
num-derive = "0.3"
static_assertions = "1.1"

[build-dependencies]
Expand Down
10 changes: 4 additions & 6 deletions rust/bridge/ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

use libc::{c_char, c_int, c_uchar, c_uint, c_ulonglong, size_t};
use libsignal_protocol_rust::*;
use num_derive::ToPrimitive;
use static_assertions::const_assert_eq;
use std::convert::TryFrom;
use std::ffi::{c_void, CString};
Expand Down Expand Up @@ -64,7 +63,7 @@ pub unsafe extern "C" fn signal_error_get_type(err: *const SignalFfiError) -> u3
match err.as_ref() {
Some(err) => {
let code: SignalErrorCode = err.into();
num_traits::ToPrimitive::to_u32(&code).expect("Error enum can be converted to u32")
code as u32
}
None => 0,
}
Expand Down Expand Up @@ -807,7 +806,7 @@ type IsTrustedIdentity = extern "C" fn(
ctx: *mut c_void,
) -> c_int;

#[derive(Debug, ToPrimitive)]
#[derive(Debug)]
#[repr(C)]
pub enum FfiDirection {
Sending = 0,
Expand Down Expand Up @@ -910,12 +909,11 @@ impl IdentityKeyStore for FfiIdentityKeyStore {
Direction::Sending => FfiDirection::Sending,
Direction::Receiving => FfiDirection::Receiving,
};
let primitive_direction = num_traits::ToPrimitive::to_u32(&direction).unwrap();
let result = (self.store.is_trusted_identity)(
self.store.ctx,
&*address,
&*identity.public_key(),
primitive_direction,
direction as u32,
ctx,
);

Expand Down Expand Up @@ -1285,7 +1283,7 @@ pub unsafe extern "C" fn signal_encrypt_message(

ffi_fn_destroy!(signal_ciphertext_message_destroy destroys CiphertextMessage);

#[derive(Debug, ToPrimitive)]
#[derive(Debug)]
#[repr(C)]
pub enum FfiCiphertextMessageType {
Whisper = 2,
Expand Down
3 changes: 1 addition & 2 deletions rust/bridge/ffi/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

use libc::{c_char, c_uchar, c_uint, c_ulonglong, size_t};
use libsignal_protocol_rust::*;
use num_derive::ToPrimitive;
use std::ffi::{CStr, CString};
use std::fmt;

Expand All @@ -22,7 +21,7 @@ pub enum SignalFfiError {
InvalidType,
}

#[derive(Debug, ToPrimitive)]
#[derive(Debug)]
#[repr(C)]
pub enum SignalErrorCode {
UnknownError = 1,
Expand Down

0 comments on commit b6caa7a

Please sign in to comment.