From 5976e3abda846075540fe37731af354f64e3e8ed Mon Sep 17 00:00:00 2001 From: finiteprods Date: Wed, 3 Feb 2021 10:56:47 +0100 Subject: [PATCH] restore FFI set_scalar --- rust/xaynet-mobile/src/ffi/settings.rs | 7 +++---- rust/xaynet-mobile/src/settings.rs | 9 ++++++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/rust/xaynet-mobile/src/ffi/settings.rs b/rust/xaynet-mobile/src/ffi/settings.rs index 34a165dfd..98ee990cb 100644 --- a/rust/xaynet-mobile/src/ffi/settings.rs +++ b/rust/xaynet-mobile/src/ffi/settings.rs @@ -1,4 +1,4 @@ -use std::os::raw::{c_int, c_uint}; +use std::os::raw::{c_double, c_int}; use ffi_support::{ByteBuffer, FfiStr}; use xaynet_core::crypto::{ByteObject, PublicSigningKey, SecretSigningKey, SigningKeyPair}; @@ -82,12 +82,11 @@ pub unsafe extern "C" fn xaynet_ffi_settings_new() -> *mut Settings { #[no_mangle] pub unsafe extern "C" fn xaynet_ffi_settings_set_scalar( settings: *mut Settings, - numer: c_uint, - denom: c_uint, + scalar: c_double, ) -> c_int { match unsafe { settings.as_mut() } { Some(settings) => { - settings.set_scalar(numer, denom); + settings.set_scalar(scalar); OK } None => ERR_NULLPTR, diff --git a/rust/xaynet-mobile/src/settings.rs b/rust/xaynet-mobile/src/settings.rs index 0fe99f880..50eab8532 100644 --- a/rust/xaynet-mobile/src/settings.rs +++ b/rust/xaynet-mobile/src/settings.rs @@ -4,7 +4,10 @@ use std::convert::TryInto; use thiserror::Error; -use xaynet_core::{crypto::SigningKeyPair, mask::Scalar}; +use xaynet_core::{ + crypto::SigningKeyPair, + mask::{FromPrimitive, Scalar}, +}; use xaynet_sdk::settings::{MaxMessageSize, PetSettings}; /// A participant settings @@ -43,8 +46,8 @@ impl Settings { } /// Set the scalar to use for masking - pub fn set_scalar(&mut self, numer: u32, denom: u32) { - self.scalar = Scalar::new(numer, denom) + pub fn set_scalar(&mut self, scalar: f64) { + self.scalar = Scalar::from_primitive(scalar).unwrap() // FIXME better to avoid f64 } /// Set the Xaynet coordinator address