-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathohttp.rs
More file actions
74 lines (63 loc) · 2.07 KB
/
Copy pathohttp.rs
File metadata and controls
74 lines (63 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#[cfg(not(feature = "wasm"))]
use crate::error::PayjoinError;
#[cfg(feature = "wasm")]
use {
crate::utils::result::JsResult,
wasm_bindgen::prelude::*,
};
use std::str::FromStr;
impl From<payjoin::OhttpKeys> for OhttpKeys {
fn from(value: payjoin::OhttpKeys) -> Self {
Self(value)
}
}
impl From<OhttpKeys> for payjoin::OhttpKeys {
fn from(value: OhttpKeys) -> Self {
value.0
}
}
#[cfg_attr(feature = "uniffi", derive(uniffi::Object))]
#[cfg_attr(feature = "wasm", wasm_bindgen)]
#[derive(Debug, Clone)]
pub struct OhttpKeys(
#[wasm_bindgen(skip)]
pub payjoin::OhttpKeys
);
#[cfg_attr(feature = "uniffi", uniffi::export)]
#[cfg_attr(feature = "wasm", wasm_bindgen)]
impl OhttpKeys {
/// Decode an OHTTP KeyConfig
#[cfg(not(feature = "wasm"))]
#[cfg_attr(feature = "uniffi", uniffi::constructor)]
pub fn decode(bytes: Vec<u8>) -> Result<Self, PayjoinError> {
payjoin::OhttpKeys::decode(bytes.as_slice()).map(|e| e.into()).map_err(|e| e.into())
}
#[cfg(feature = "wasm")]
#[wasm_bindgen(constructor)]
pub fn decode(bytes: Vec<u8>) -> JsResult<OhttpKeys> {
payjoin::OhttpKeys::decode(bytes.as_slice())
.map(|e| e.into())
.map_err(|e| wasm_bindgen::JsError::new(&e.to_string()))
}
#[cfg(feature = "wasm")]
pub fn parse(s: &str) -> JsResult<OhttpKeys> {
payjoin::OhttpKeys::from_str(s)
.map(|e| e.into())
.map_err(|e| wasm_bindgen::JsError::new(&e.to_string()))
}
}
use std::sync::Mutex;
#[cfg_attr(feature = "uniffi", derive(uniffi::Object))]
#[cfg_attr(feature = "wasm", wasm_bindgen)]
pub struct ClientResponse(Mutex<Option<ohttp::ClientResponse>>);
impl From<&ClientResponse> for ohttp::ClientResponse {
fn from(value: &ClientResponse) -> Self {
let mut data_guard = value.0.lock().unwrap();
Option::take(&mut *data_guard).expect("ClientResponse moved out of memory")
}
}
impl From<ohttp::ClientResponse> for ClientResponse {
fn from(value: ohttp::ClientResponse) -> Self {
Self(Mutex::new(Some(value)))
}
}