mirror of
https://github.com/vacp2p/stealth-address-kit.git
synced 2026-01-09 13:38:01 -05:00
chore: ffi prelude to avoid dupe types, makefile entries for bindings
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1 +1,4 @@
|
||||
/target
|
||||
expanded.rs
|
||||
stealth_address_kit.h
|
||||
stealth_address_kit.nim
|
||||
|
||||
9
Makefile
9
Makefile
@@ -1,6 +1,7 @@
|
||||
.PHONY: deps clean example
|
||||
deps:
|
||||
@cargo install cross --git https://github.com/cross-rs/cross.git --rev 1511a28
|
||||
@cargo install cbindgen
|
||||
|
||||
clean:
|
||||
@cargo clean
|
||||
@@ -11,3 +12,11 @@ example:
|
||||
bench:
|
||||
@cargo bench --all-features
|
||||
cp -r target/criterion/** benchmarks/
|
||||
|
||||
generate_c_bindings:
|
||||
@cargo expand --all-features -p stealth_address_kit > expanded.rs
|
||||
@cbindgen --output stealth_address_kit.h --lang c expanded.rs
|
||||
|
||||
generate_nim_bindings:
|
||||
@cargo expand --all-features -p stealth_address_kit > expanded.rs
|
||||
@nbindgen --output stealth_address_kit.nim expanded.rs
|
||||
|
||||
@@ -5,35 +5,8 @@ macro_rules! define_curve_ffi {
|
||||
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize, SerializationError};
|
||||
use num_traits::Zero;
|
||||
use std::ops::Add;
|
||||
use crate::ffi_prelude::{CReturn, CErrorCode};
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, PartialOrd, PartialEq)]
|
||||
pub enum CErrorCode {
|
||||
NoError = 0,
|
||||
SerializationErrorNotEnoughSpace = 1,
|
||||
SerializationErrorInvalidData = 2,
|
||||
SerializationErrorUnexpectedFlags = 3,
|
||||
SerializationErrorIoError = 4,
|
||||
InvalidKeys = 5,
|
||||
}
|
||||
|
||||
impl From<SerializationError> for CErrorCode {
|
||||
fn from(value: SerializationError) -> Self {
|
||||
match value {
|
||||
SerializationError::NotEnoughSpace => CErrorCode::SerializationErrorNotEnoughSpace,
|
||||
SerializationError::InvalidData => CErrorCode::SerializationErrorInvalidData,
|
||||
SerializationError::UnexpectedFlags => CErrorCode::SerializationErrorUnexpectedFlags,
|
||||
SerializationError::IoError(_) => CErrorCode::SerializationErrorIoError,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug)]
|
||||
pub struct CReturn<T> {
|
||||
value: T,
|
||||
err_code: CErrorCode,
|
||||
}
|
||||
paste! {
|
||||
#[repr(C)]
|
||||
#[derive(Debug)]
|
||||
|
||||
30
sdk/src/ffi_prelude.rs
Normal file
30
sdk/src/ffi_prelude.rs
Normal file
@@ -0,0 +1,30 @@
|
||||
use ark_serialize::SerializationError;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, PartialOrd, PartialEq)]
|
||||
pub enum CErrorCode {
|
||||
NoError = 0,
|
||||
SerializationErrorNotEnoughSpace = 1,
|
||||
SerializationErrorInvalidData = 2,
|
||||
SerializationErrorUnexpectedFlags = 3,
|
||||
SerializationErrorIoError = 4,
|
||||
InvalidKeys = 5,
|
||||
}
|
||||
|
||||
impl From<SerializationError> for CErrorCode {
|
||||
fn from(value: SerializationError) -> Self {
|
||||
match value {
|
||||
SerializationError::NotEnoughSpace => CErrorCode::SerializationErrorNotEnoughSpace,
|
||||
SerializationError::InvalidData => CErrorCode::SerializationErrorInvalidData,
|
||||
SerializationError::UnexpectedFlags => CErrorCode::SerializationErrorUnexpectedFlags,
|
||||
SerializationError::IoError(_) => CErrorCode::SerializationErrorIoError,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug)]
|
||||
pub struct CReturn<T> {
|
||||
pub(crate) value: T,
|
||||
pub(crate) err_code: CErrorCode,
|
||||
}
|
||||
@@ -34,6 +34,9 @@ mod vesta_impl;
|
||||
#[cfg(feature = "ffi")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "ffi")))]
|
||||
mod ffi;
|
||||
#[cfg(feature = "ffi")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "ffi")))]
|
||||
mod ffi_prelude;
|
||||
|
||||
#[cfg(feature = "baby_jub_jub")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "baby_jub_jub")))]
|
||||
|
||||
Reference in New Issue
Block a user