diff --git a/matcher-rs/Cargo.lock b/matcher-rs/Cargo.lock index 649e297..dbbf038 100644 --- a/matcher-rs/Cargo.lock +++ b/matcher-rs/Cargo.lock @@ -2,149 +2,13 @@ # It is not intended for manual editing. version = 4 -[[package]] -name = "aho-corasick" -version = "1.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301" -dependencies = [ - "memchr", -] - -[[package]] -name = "bindgen" -version = "0.72.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "993776b509cfb49c750f11b8f07a46fa23e0a1386ffc01fb1e7d343efc387895" -dependencies = [ - "bitflags", - "cexpr", - "clang-sys", - "itertools", - "log", - "prettyplease", - "proc-macro2", - "quote", - "regex", - "rustc-hash", - "shlex", - "syn", -] - -[[package]] -name = "bitflags" -version = "2.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3" - -[[package]] -name = "cexpr" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" -dependencies = [ - "nom", -] - -[[package]] -name = "cfg-if" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" - -[[package]] -name = "clang-sys" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4" -dependencies = [ - "glob", - "libc", - "libloading", -] - -[[package]] -name = "either" -version = "1.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" - -[[package]] -name = "glob" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0cc23270f6e1808e30a928bdc84dea0b9b4136a8bc82338574f23baf47bbd280" - -[[package]] -name = "itertools" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" -dependencies = [ - "either", -] - -[[package]] -name = "libc" -version = "0.2.177" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2874a2af47a2325c2001a6e6fad9b16a53b802102b528163885171cf92b15976" - -[[package]] -name = "libloading" -version = "0.8.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7c4b02199fee7c5d21a5ae7d8cfa79a6ef5bb2fc834d6e9058e89c825efdc55" -dependencies = [ - "cfg-if", - "windows-link", -] - -[[package]] -name = "lock_api" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965" -dependencies = [ - "scopeguard", -] - -[[package]] -name = "log" -version = "0.4.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34080505efa8e45a4b816c349525ebe327ceaa8559756f0356cba97ef3bf7432" - -[[package]] -name = "lol_alloc" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83e5106554cabc97552dcadf54f57560ae6af3276652f82ca2be06120dc4c5dc" -dependencies = [ - "spin", -] - [[package]] name = "matcher-rs" version = "0.1.0" dependencies = [ - "bindgen", - "lol_alloc", "nanoserde", ] -[[package]] -name = "memchr" -version = "2.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273" - -[[package]] -name = "minimal-lexical" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" - [[package]] name = "nanoserde" version = "0.1.37" @@ -159,120 +23,3 @@ name = "nanoserde-derive" version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e943b2c21337b7e3ec6678500687cdc741b7639ad457f234693352075c082204" - -[[package]] -name = "nom" -version = "7.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" -dependencies = [ - "memchr", - "minimal-lexical", -] - -[[package]] -name = "prettyplease" -version = "0.2.37" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b" -dependencies = [ - "proc-macro2", - "syn", -] - -[[package]] -name = "proc-macro2" -version = "1.0.103" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ee95bc4ef87b8d5ba32e8b7714ccc834865276eab0aed5c9958d00ec45f49e8" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.42" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a338cc41d27e6cc6dce6cefc13a0729dfbb81c262b1f519331575dd80ef3067f" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "regex" -version = "1.12.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "843bc0191f75f3e22651ae5f1e72939ab2f72a4bc30fa80a066bd66edefc24d4" -dependencies = [ - "aho-corasick", - "memchr", - "regex-automata", - "regex-syntax", -] - -[[package]] -name = "regex-automata" -version = "0.4.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5276caf25ac86c8d810222b3dbb938e512c55c6831a10f3e6ed1c93b84041f1c" -dependencies = [ - "aho-corasick", - "memchr", - "regex-syntax", -] - -[[package]] -name = "regex-syntax" -version = "0.8.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a2d987857b319362043e95f5353c0535c1f58eec5336fdfcf626430af7def58" - -[[package]] -name = "rustc-hash" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d" - -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - -[[package]] -name = "shlex" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" - -[[package]] -name = "spin" -version = "0.9.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" -dependencies = [ - "lock_api", -] - -[[package]] -name = "syn" -version = "2.0.111" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "390cc9a294ab71bdb1aa2e99d13be9c753cd2d7bd6560c77118597410c4d2e87" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "unicode-ident" -version = "1.0.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" - -[[package]] -name = "windows-link" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" diff --git a/matcher-rs/Cargo.toml b/matcher-rs/Cargo.toml index 22d395e..5b38f50 100644 --- a/matcher-rs/Cargo.toml +++ b/matcher-rs/Cargo.toml @@ -3,19 +3,16 @@ name = "matcher-rs" version = "0.1.0" authors = ["rensiyuan"] edition = "2024" -build = "build.rs" [lib] crate-type = ["cdylib", "rlib"] [dependencies] -lol_alloc = "0.4.1" nanoserde = "0.1" [dev-dependencies] [build-dependencies] -bindgen = "0.72.1" [profile.release] # Tell `rustc` to optimize for small code size. diff --git a/matcher-rs/build.rs b/matcher-rs/build.rs deleted file mode 100644 index f822d9b..0000000 --- a/matcher-rs/build.rs +++ /dev/null @@ -1,20 +0,0 @@ -use std::env; -use std::path::PathBuf; - -fn main() { - println!("cargo:rerun-if-changed=../matcher/credentialmanager.h"); - println!("cargo:rerun-if-env-changed=TARGET"); - - let builder = bindgen::Builder::default() - .header("../matcher/credentialmanager.h") - .clang_arg("-I/usr/include") - .clang_arg("-fvisibility=default") - .parse_callbacks(Box::new(bindgen::CargoCallbacks::new())); - - let bindings = builder.generate().expect("Unable to generate bindings"); - - let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); - bindings - .write_to_file(out_path.join("bindings.rs")) - .expect("Couldn't write bindings!"); -} diff --git a/matcher-rs/build.sh b/matcher-rs/build.sh index 2e0e5e1..d862a82 100644 --- a/matcher-rs/build.sh +++ b/matcher-rs/build.sh @@ -12,6 +12,6 @@ cargo +nightly build \ # 2. Further shrink using wasm-opt (if available) for wasm in target/wasm32-unknown-unknown/release/*.wasm; do - wasm-opt -Oz --strip-debug --enable-bulk-memory "$wasm" -o "$wasm" + wasm-opt -Oz --strip-debug --enable-bulk-memory --enable-sign-ext "$wasm" -o "$wasm" done diff --git a/matcher-rs/src/bindings.rs b/matcher-rs/src/bindings.rs index 04d76a4..c000d59 100644 --- a/matcher-rs/src/bindings.rs +++ b/matcher-rs/src/bindings.rs @@ -1,6 +1,142 @@ -#![allow(non_upper_case_globals)] -#![allow(non_camel_case_types)] -#![allow(non_snake_case)] -#![allow(unused)] +use std::os::raw::{c_char, c_void}; -include!(concat!(env!("OUT_DIR"), "/bindings.rs")); +#[repr(C)] +pub struct CallingAppInfo { + pub package_name: [u8; 256], + pub origin: [u8; 512], +} + +unsafe extern "C" { + pub fn AddEntry( + cred_id: i64, + icon: *const c_char, + icon_len: usize, + title: *const c_char, + subtitle: *const c_char, + disclaimer: *const c_char, + warning: *const c_char, + ); + pub fn AddField( + cred_id: i64, + field_display_name: *const c_char, + field_display_value: *const c_char, + ); + pub fn AddEntrySet(set_id: *const c_char, set_length: i32); + pub fn AddEntryToSet( + cred_id: *const c_char, + icon: *const c_char, + icon_len: usize, + title: *const c_char, + subtitle: *const c_char, + disclaimer: *const c_char, + warning: *const c_char, + metadata: *const c_char, + set_id: *const c_char, + set_index: i32, + ); + pub fn AddFieldToEntrySet( + cred_id: *const c_char, + field_display_name: *const c_char, + field_display_value: *const c_char, + set_id: *const c_char, + set_index: i32, + ); + pub fn AddPaymentEntryToSet( + cred_id: *const c_char, + merchant_name: *const c_char, + payment_method_name: *const c_char, + payment_method_subtitle: *const c_char, + payment_method_icon: *const c_char, + payment_method_icon_len: usize, + transaction_amount: *const c_char, + bank_icon: *const c_char, + bank_icon_len: usize, + payment_provider_icon: *const c_char, + payment_provider_icon_len: usize, + metadata: *const c_char, + set_id: *const c_char, + set_index: i32, + ); + pub fn AddPaymentEntryToSetV2( + cred_id: *const c_char, + merchant_name: *const c_char, + payment_method_name: *const c_char, + payment_method_subtitle: *const c_char, + payment_method_icon: *const c_char, + payment_method_icon_len: usize, + transaction_amount: *const c_char, + bank_icon: *const c_char, + bank_icon_len: usize, + payment_provider_icon: *const c_char, + payment_provider_icon_len: usize, + additional_info: *const c_char, + metadata: *const c_char, + set_id: *const c_char, + set_index: i32, + ); + pub fn AddStringIdEntry( + cred_id: *const c_char, + icon: *const c_char, + icon_len: usize, + title: *const c_char, + subtitle: *const c_char, + disclaimer: *const c_char, + warning: *const c_char, + ); + pub fn AddFieldForStringIdEntry( + cred_id: *const c_char, + field_display_name: *const c_char, + field_display_value: *const c_char, + ); + pub fn GetRequestBuffer(buffer: *mut c_void); + pub fn GetRequestSize(size: *mut u32); + pub fn ReadCredentialsBuffer(buffer: *mut c_void, offset: usize, len: usize) -> usize; + pub fn GetCredentialsSize(size: *mut u32); + pub fn GetWasmVersion(version: *mut u32); + pub fn AddPaymentEntry( + cred_id: *const c_char, + merchant_name: *const c_char, + payment_method_name: *const c_char, + payment_method_subtitle: *const c_char, + payment_method_icon: *const c_char, + payment_method_icon_len: usize, + transaction_amount: *const c_char, + bank_icon: *const c_char, + bank_icon_len: usize, + payment_provider_icon: *const c_char, + payment_provider_icon_len: usize, + ); + pub fn AddInlineIssuanceEntry( + cred_id: *const c_char, + icon: *const c_char, + icon_len: usize, + title: *const c_char, + subtitle: *const c_char, + ); + pub fn SetAdditionalDisclaimerAndUrlForVerificationEntry( + cred_id: *const c_char, + secondary_disclaimer: *const c_char, + url_display_text: *const c_char, + url_value: *const c_char, + ); + pub fn SetAdditionalDisclaimerAndUrlForVerificationEntryInCredentialSet( + cred_id: *const c_char, + secondary_disclaimer: *const c_char, + url_display_text: *const c_char, + url_value: *const c_char, + set_id: *const c_char, + set_index: i32, + ); + pub fn GetCallingAppInfo(info: *mut CallingAppInfo); + pub fn SelfDeclarePackageInfo( + package_display_name: *const c_char, + package_icon: *const c_char, + package_icon_len: usize, + ); + pub fn AddMetadataDisplayTextToEntrySet( + cred_id: *const c_char, + metadata_display_text: *const c_char, + set_id: *const c_char, + set_index: i32, + ); +} diff --git a/matcher-rs/src/credman.rs b/matcher-rs/src/credman.rs index 2c53c9d..aff5239 100644 --- a/matcher-rs/src/credman.rs +++ b/matcher-rs/src/credman.rs @@ -52,7 +52,8 @@ impl CredmanApi for CredmanApiImpl { disclaimer: Option<&CStr>, warning: Option<&CStr>, ) { - let icon_bytes = icon.map_or(std::ptr::null(), |x| x.as_ptr()) as *const i8; + let icon_bytes = + icon.map_or(std::ptr::null(), |x| x.as_ptr()) as *const std::os::raw::c_char; let icon_length = icon.map_or(0, |x| x.len()); unsafe { AddStringIdEntry( diff --git a/matcher-rs/src/issuance.rs b/matcher-rs/src/issuance.rs index d7c55d1..3e5fd82 100644 --- a/matcher-rs/src/issuance.rs +++ b/matcher-rs/src/issuance.rs @@ -31,14 +31,8 @@ pub fn issuance_main(credman: &mut impl CredmanApi) -> Result<(), Box filters.iter().all(|f| f.matches(request)), Self::Or { filters } => filters.iter().any(|f| f.matches(request)), Self::Not { filter } => !filter.matches(request), - Self::AllowsIssuers { issuers } => { - issuers.contains(request.credential_issuer) - } + Self::AllowsIssuers { issuers } => issuers.contains(request.credential_issuer), Self::AllowsConfigurationIds { configuration_ids } => request .credential_configuration_ids .iter() .any(|id| configuration_ids.contains(id)), - Self::SupportsAuthCodeFlow {} => request - .grants - .contains_key("authorization_code"), + Self::SupportsAuthCodeFlow {} => request.grants.contains_key("authorization_code"), Self::SupportsPreAuthFlow {} => request .grants .contains_key("urn:ietf:params:oauth:grant-type:pre-authorized_code"), diff --git a/matcher-rs/src/lib.rs b/matcher-rs/src/lib.rs index fb23de0..a172c8a 100644 --- a/matcher-rs/src/lib.rs +++ b/matcher-rs/src/lib.rs @@ -1,8 +1,3 @@ -#[cfg(target_arch = "wasm32")] -#[global_allocator] -static ALLOCATOR: lol_alloc::AssumeSingleThreaded = - unsafe { lol_alloc::AssumeSingleThreaded::new(lol_alloc::LeakingAllocator::new()) }; - pub mod bindings; pub mod credman; pub mod issuance;