worker/
mtls_certificate.rs1use crate::{env::EnvBinding, Result};
2use wasm_bindgen::{JsCast, JsValue};
3use worker_sys::MtlsCertificate as MtlsCertificateSys;
4
5#[derive(Debug, Clone)]
6pub struct MtlsCertificate(MtlsCertificateSys);
7
8unsafe impl Send for MtlsCertificate {}
9unsafe impl Sync for MtlsCertificate {}
10
11impl MtlsCertificate {
12 pub fn id(&self) -> Option<String> {
13 js_sys::Reflect::get(self.as_ref(), &JsValue::from("id"))
14 .ok()
15 .and_then(|v| v.as_string())
16 }
17
18 pub fn as_request_cf_value(&self) -> JsValue {
19 self.as_ref().clone()
20 }
21}
22
23impl EnvBinding for MtlsCertificate {
24 const TYPE_NAME: &'static str = "Object";
25
26 fn get(val: JsValue) -> Result<Self> {
27 if !val.is_object() {
28 return Err("Binding cannot be cast to MtlsCertificate from non-object value".into());
29 }
30
31 Ok(Self(val.unchecked_into()))
32 }
33}
34
35impl JsCast for MtlsCertificate {
36 fn instanceof(val: &JsValue) -> bool {
37 val.is_object()
38 }
39
40 fn unchecked_from_js(val: JsValue) -> Self {
41 Self(val.unchecked_into())
42 }
43
44 fn unchecked_from_js_ref(val: &JsValue) -> &Self {
45 unsafe { &*(val as *const JsValue as *const Self) }
46 }
47}
48
49impl AsRef<JsValue> for MtlsCertificate {
50 fn as_ref(&self) -> &JsValue {
51 &self.0
52 }
53}
54
55impl From<JsValue> for MtlsCertificate {
56 fn from(val: JsValue) -> Self {
57 Self(val.unchecked_into())
58 }
59}
60
61impl From<MtlsCertificate> for JsValue {
62 fn from(value: MtlsCertificate) -> Self {
63 value.0.into()
64 }
65}