-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ipa-multipoint : Error handling and init no-copy in JNI (#158)
Signed-off-by: Thomas Zamojski <[email protected]>
- Loading branch information
1 parent
e4c77f4
commit 007c808
Showing
7 changed files
with
2,918 additions
and
2,680 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use jni::JNIEnv; | ||
use jni::objects::ReleaseMode; | ||
use jni::sys::jbyteArray; | ||
|
||
use std::convert::TryFrom; | ||
|
||
use ffi_interface::CommitmentBytes; | ||
|
||
|
||
pub fn parse_scalars<'a>(env: &'a JNIEnv<'a>, values: jbyteArray) -> Result<&'a [u8], String> { | ||
let input_len = env.get_array_length(values).map_err(|_| "Cannot get array lenght".to_string())? as usize; | ||
if input_len % 32 != 0 { | ||
return Err("Wrong input size: should be a mulitple of 32 bytes".to_string()) | ||
}; | ||
let input_elements = env.get_primitive_array_critical(values, ReleaseMode::NoCopyBack).map_err(|_| "Cannot get array elements".to_string())?; | ||
let input_slice = unsafe { std::slice::from_raw_parts(input_elements.as_ptr() as *const u8, input_len) }; | ||
Ok(input_slice) | ||
} | ||
|
||
pub fn parse_indices(env: &JNIEnv, values: jbyteArray) -> Result<Vec<usize>, String> { | ||
let input_len = env.get_array_length(values).map_err(|_| "Cannot get array lenght".to_string())? as usize; | ||
let input_elements = env.get_primitive_array_critical(values, ReleaseMode::NoCopyBack).map_err(|_| "Cannot get array elements".to_string())?; | ||
let input_slice = unsafe { std::slice::from_raw_parts(input_elements.as_ptr() as *const u8, input_len) }; | ||
let result: Vec<usize> = input_slice.iter().map(|&x| x as usize).collect(); | ||
Ok(result) | ||
} | ||
|
||
pub fn parse_commitment(env: &JNIEnv, commitment: jbyteArray) -> Result<CommitmentBytes, String> { | ||
let input_len = env.get_array_length(commitment).map_err(|_| "Cannot get commitment lenght".to_string())? as usize; | ||
let input_elements = env.get_primitive_array_critical(commitment, ReleaseMode::NoCopyBack).map_err(|_| "Cannot get array elements".to_string())?; | ||
let input_slice = unsafe { std::slice::from_raw_parts(input_elements.as_ptr() as *const u8, input_len) }; | ||
let result: CommitmentBytes = CommitmentBytes::try_from(input_slice).map_err(|_| "Wrong commitment size: should be 64 bytes".to_string())?; | ||
Ok(result) | ||
} | ||
|
||
pub fn parse_commitments<'a>(env: &'a JNIEnv<'a>, commitment: jbyteArray) -> Result<&'a [u8], String> { | ||
let input_len = env.get_array_length(commitment).map_err(|_| "Cannot get commitment lenght".to_string())? as usize; | ||
if input_len % 64 != 0 { | ||
return Err("Wrong input size: should be a mulitple of 64 bytes".to_string()) | ||
}; | ||
let input_elements = env.get_primitive_array_critical(commitment, ReleaseMode::NoCopyBack).map_err(|_| "Cannot get array elements".to_string())?; | ||
let input_slice = unsafe { std::slice::from_raw_parts(input_elements.as_ptr() as *const u8, input_len) }; | ||
Ok(input_slice) | ||
} |
Oops, something went wrong.