Skip to content

Commit 0c9933e

Browse files
authored
Merge pull request #29 from G-Core/feat/proxywasm_secret
proxywasm secret methods
2 parents 92feb17 + 4bdd8d1 commit 0c9933e

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ use crate::gcore::fastedge::http::{Error as HttpError, Method, Request, Response
1616

1717
/// Implementation of Outbound HTTP component
1818
mod http_client;
19+
/// FastEdge ProxyWasm module extension
20+
pub mod proxywasm;
1921

2022
pub mod wasi_nn {
2123
#![allow(missing_docs)]

src/proxywasm.rs

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
extern "C" {
2+
fn proxy_get_secret(
3+
key_data: *const u8,
4+
key_size: usize,
5+
return_value_data: *mut *mut u8,
6+
return_value_size: *mut usize,
7+
) -> u32;
8+
}
9+
10+
/// ProxyWasm secret interface
11+
pub mod secret {
12+
use crate::proxywasm::proxy_get_secret;
13+
use std::ptr::null_mut;
14+
15+
/// Get secret method.
16+
/// return None if secret not found for given key
17+
pub fn get(key: &str) -> Result<Option<Vec<u8>>, u32> {
18+
let mut return_data: *mut u8 = null_mut();
19+
let mut return_size: usize = 0;
20+
unsafe {
21+
match proxy_get_secret(
22+
key.as_ptr(),
23+
key.len(),
24+
&mut return_data,
25+
&mut return_size,
26+
) {
27+
0 => {
28+
if !return_data.is_null() {
29+
Ok(Some(Vec::from_raw_parts(
30+
return_data,
31+
return_size,
32+
return_size,
33+
)))
34+
} else {
35+
Ok(None)
36+
}
37+
}
38+
1 => Ok(None),
39+
status => panic!("unexpected status: {}", status),
40+
}
41+
}
42+
}
43+
}

0 commit comments

Comments
 (0)