script_bindings/home/runner/work/servo/servo/target/debug/build/script_bindings-d55f55d5af1efaee/out/Bindings/
CryptoKeyBinding.rs

1/* THIS FILE IS AUTOGENERATED - DO NOT EDIT */
2
3#![allow(non_camel_case_types,non_upper_case_globals,unsafe_op_in_unsafe_fn,unused_imports,unused_variables,unused_assignments,unused_mut,clippy::approx_constant,clippy::enum_variant_names,clippy::let_unit_value,clippy::needless_return,clippy::too_many_arguments,clippy::unnecessary_cast,clippy::upper_case_acronyms)]
4
5use crate::import::base::*;
6
7
8#[repr(usize)]
9#[derive(Copy, Clone, Debug, JSTraceable, MallocSizeOf, PartialEq)]
10pub enum KeyType {
11    Public,
12    Private,
13    Secret
14}
15pub mod KeyTypeValues {
16
17    use crate::utils::find_enum_value;
18    use js::conversions::ConversionResult;
19    use js::conversions::FromJSValConvertible;
20    use js::conversions::ToJSValConvertible;
21    use js::context::RawJSContext;
22    use js::rust::HandleValue;
23    use js::rust::MutableHandleValue;
24    use js::jsval::JSVal;
25
26    pub(crate) const pairs: &[(&str, super::KeyType)] = &[
27        ("public", super::KeyType::Public),
28        ("private", super::KeyType::Private),
29        ("secret", super::KeyType::Secret),
30    ];
31
32    impl super::KeyType {
33        pub fn as_str(&self) -> &'static str {
34            pairs[*self as usize].0
35        }
36    }
37
38    impl Default for super::KeyType {
39        fn default() -> super::KeyType {
40            pairs[0].1
41        }
42    }
43
44    impl std::str::FromStr for super::KeyType {
45        type Err = ();
46
47        fn from_str(s: &str) -> Result<Self, Self::Err> {
48            pairs
49                .iter()
50                .find(|&&(key, _)| s == key)
51                .map(|&(_, ev)| ev)
52                .ok_or(())
53        }
54    }
55
56    impl ToJSValConvertible for super::KeyType {
57        unsafe fn to_jsval(&self, cx: *mut RawJSContext, rval: MutableHandleValue) {
58            pairs[*self as usize].0.to_jsval(cx, rval);
59        }
60    }
61
62    impl FromJSValConvertible for super::KeyType {
63        type Config = ();
64        unsafe fn from_jsval(cx: *mut RawJSContext, value: HandleValue, _option: ())
65                             -> Result<ConversionResult<super::KeyType>, ()> {
66            match find_enum_value(cx, value, pairs) {
67                Err(_) => Err(()),
68                Ok((None, search)) => {
69                    Ok(ConversionResult::Failure(
70                        format!("'{}' is not a valid enum value for enumeration 'KeyType'.", search).into()
71                    ))
72                }
73                Ok((Some(&value), _)) => Ok(ConversionResult::Success(value)),
74            }
75        }
76    }
77        } // mod KeyTypeValues
78
79
80#[repr(usize)]
81#[derive(Copy, Clone, Debug, JSTraceable, MallocSizeOf, PartialEq)]
82pub enum KeyUsage {
83    Encrypt,
84    Decrypt,
85    Sign,
86    Verify,
87    DeriveKey,
88    DeriveBits,
89    WrapKey,
90    UnwrapKey,
91    EncapsulateKey,
92    EncapsulateBits,
93    DecapsulateKey,
94    DecapsulateBits
95}
96pub mod KeyUsageValues {
97
98    use crate::utils::find_enum_value;
99    use js::conversions::ConversionResult;
100    use js::conversions::FromJSValConvertible;
101    use js::conversions::ToJSValConvertible;
102    use js::context::RawJSContext;
103    use js::rust::HandleValue;
104    use js::rust::MutableHandleValue;
105    use js::jsval::JSVal;
106
107    pub(crate) const pairs: &[(&str, super::KeyUsage)] = &[
108        ("encrypt", super::KeyUsage::Encrypt),
109        ("decrypt", super::KeyUsage::Decrypt),
110        ("sign", super::KeyUsage::Sign),
111        ("verify", super::KeyUsage::Verify),
112        ("deriveKey", super::KeyUsage::DeriveKey),
113        ("deriveBits", super::KeyUsage::DeriveBits),
114        ("wrapKey", super::KeyUsage::WrapKey),
115        ("unwrapKey", super::KeyUsage::UnwrapKey),
116        ("encapsulateKey", super::KeyUsage::EncapsulateKey),
117        ("encapsulateBits", super::KeyUsage::EncapsulateBits),
118        ("decapsulateKey", super::KeyUsage::DecapsulateKey),
119        ("decapsulateBits", super::KeyUsage::DecapsulateBits),
120    ];
121
122    impl super::KeyUsage {
123        pub fn as_str(&self) -> &'static str {
124            pairs[*self as usize].0
125        }
126    }
127
128    impl Default for super::KeyUsage {
129        fn default() -> super::KeyUsage {
130            pairs[0].1
131        }
132    }
133
134    impl std::str::FromStr for super::KeyUsage {
135        type Err = ();
136
137        fn from_str(s: &str) -> Result<Self, Self::Err> {
138            pairs
139                .iter()
140                .find(|&&(key, _)| s == key)
141                .map(|&(_, ev)| ev)
142                .ok_or(())
143        }
144    }
145
146    impl ToJSValConvertible for super::KeyUsage {
147        unsafe fn to_jsval(&self, cx: *mut RawJSContext, rval: MutableHandleValue) {
148            pairs[*self as usize].0.to_jsval(cx, rval);
149        }
150    }
151
152    impl FromJSValConvertible for super::KeyUsage {
153        type Config = ();
154        unsafe fn from_jsval(cx: *mut RawJSContext, value: HandleValue, _option: ())
155                             -> Result<ConversionResult<super::KeyUsage>, ()> {
156            match find_enum_value(cx, value, pairs) {
157                Err(_) => Err(()),
158                Ok((None, search)) => {
159                    Ok(ConversionResult::Failure(
160                        format!("'{}' is not a valid enum value for enumeration 'KeyUsage'.", search).into()
161                    ))
162                }
163                Ok((Some(&value), _)) => Ok(ConversionResult::Success(value)),
164            }
165        }
166    }
167        } // mod KeyUsageValues
168
169#[derive(JSTraceable)]
170pub struct CryptoKeyPair<D: DomTypes> {
171    pub privateKey: Option<DomRoot<D::CryptoKey>>,
172    pub publicKey: Option<DomRoot<D::CryptoKey>>,
173}
174impl<D: DomTypes> Default for CryptoKeyPair<D> {
175    fn default() -> Self {
176        Self::empty()
177    }
178}
179
180impl<D: DomTypes> CryptoKeyPair<D> {
181    pub fn empty() -> Self {
182        Self {
183                privateKey: None,
184                publicKey: None,
185        }
186    }
187    pub fn new(cx: SafeJSContext, val: HandleValue, can_gc: CanGc)
188                      -> Result<ConversionResult<CryptoKeyPair<D>>, ()> {
189        unsafe {
190            let object = if val.get().is_null_or_undefined() {
191                ptr::null_mut()
192            } else if val.get().is_object() {
193                val.get().to_object()
194            } else {
195                return Ok(ConversionResult::Failure("Value is not an object.".into()));
196            };
197            rooted!(&in(cx) let object = object);
198        let dictionary = CryptoKeyPair {
199                privateKey: {
200                    rooted!(&in(cx) let mut rval = UndefinedValue());
201                    if get_dictionary_property(cx.raw_cx(), object.handle(), "privateKey", rval.handle_mut(), can_gc)? && !rval.is_undefined() {
202                            Some(if rval.handle().get().is_object() {
203                                match root_from_handlevalue(rval.handle(), SafeJSContext::from_ptr(cx.raw_cx())) {
204                                    Ok(val) => val,
205                                    Err(()) => {
206                                        throw_type_error(cx.raw_cx(), "value does not implement interface CryptoKey.");
207                                        return Err(());
208
209                                    }
210                                }
211
212                            } else {
213                                throw_type_error(cx.raw_cx(), "Value is not an object.");
214                                return Err(());
215
216                            })
217                    } else {
218                            None
219                    }
220                },
221                publicKey: {
222                    rooted!(&in(cx) let mut rval = UndefinedValue());
223                    if get_dictionary_property(cx.raw_cx(), object.handle(), "publicKey", rval.handle_mut(), can_gc)? && !rval.is_undefined() {
224                            Some(if rval.handle().get().is_object() {
225                                match root_from_handlevalue(rval.handle(), SafeJSContext::from_ptr(cx.raw_cx())) {
226                                    Ok(val) => val,
227                                    Err(()) => {
228                                        throw_type_error(cx.raw_cx(), "value does not implement interface CryptoKey.");
229                                        return Err(());
230
231                                    }
232                                }
233
234                            } else {
235                                throw_type_error(cx.raw_cx(), "Value is not an object.");
236                                return Err(());
237
238                            })
239                    } else {
240                            None
241                    }
242                },
243        };
244            Ok(ConversionResult::Success(dictionary))
245        }
246    }
247}
248
249impl<D: DomTypes> FromJSValConvertible for CryptoKeyPair<D> {
250    type Config = ();
251    unsafe fn from_jsval(cx: *mut RawJSContext, value: HandleValue, _option: ())
252                         -> Result<ConversionResult<CryptoKeyPair<D>>, ()> {
253        CryptoKeyPair::new(SafeJSContext::from_ptr(cx), value, CanGc::note())
254    }
255}
256
257impl<D: DomTypes> CryptoKeyPair<D> {
258    #[allow(clippy::wrong_self_convention)]
259    pub unsafe fn to_jsobject(&self, cx: *mut RawJSContext, mut obj: MutableHandleObject) {
260        if let Some(ref privateKey) = self.privateKey {
261            rooted!(in(cx) let mut privateKey_js = UndefinedValue());
262            privateKey.to_jsval(cx, privateKey_js.handle_mut());
263            set_dictionary_property(SafeJSContext::from_ptr(cx), obj.handle(), "privateKey", privateKey_js.handle()).unwrap();
264        }
265        if let Some(ref publicKey) = self.publicKey {
266            rooted!(in(cx) let mut publicKey_js = UndefinedValue());
267            publicKey.to_jsval(cx, publicKey_js.handle_mut());
268            set_dictionary_property(SafeJSContext::from_ptr(cx), obj.handle(), "publicKey", publicKey_js.handle()).unwrap();
269        }
270    }
271}
272
273impl<D: DomTypes> ToJSValConvertible for CryptoKeyPair<D> {
274    unsafe fn to_jsval(&self, cx: *mut RawJSContext, mut rval: MutableHandleValue) {
275        rooted!(in(cx) let mut obj = JS_NewObject(cx, ptr::null()));
276        self.to_jsobject(cx, obj.handle_mut());
277        rval.set(ObjectOrNullValue(obj.get()))
278    }
279}
280
281
282pub use self::CryptoKey_Binding::{Wrap, CryptoKeyMethods, GetProtoObject, DefineDOMInterface};
283pub mod CryptoKey_Binding {
284use crate::codegen::GenericBindings::CryptoKeyBinding::KeyType;
285use crate::codegen::GenericBindings::CryptoKeyBinding::KeyTypeValues;
286use crate::import::module::*;
287
288unsafe extern "C" fn get_type<D: DomTypes>
289(cx: *mut RawJSContext, _obj: RawHandleObject, this: *mut libc::c_void, args: JSJitGetterCallArgs) -> bool{
290    let mut result = false;
291    wrap_panic(&mut || result = (|| {
292        let mut cx = JSContext::from_ptr(ptr::NonNull::new(cx).unwrap());
293        let this = &*(this as *const D::CryptoKey);
294        let result: KeyType = this.Type();
295
296        (result).to_jsval(cx.raw_cx(), MutableHandleValue::from_raw(args.rval()));
297        return true;
298    })());
299    result
300}
301
302
303static type_getterinfo: ThreadUnsafeOnceLock<JSJitInfo> = ThreadUnsafeOnceLock::new();
304
305pub(crate) fn init_type_getterinfo<D: DomTypes>() {
306    type_getterinfo.set(JSJitInfo {
307    __bindgen_anon_1: JSJitInfo__bindgen_ty_1 {
308        getter: Some(get_type::<D>)
309    },
310    __bindgen_anon_2: JSJitInfo__bindgen_ty_2 {
311        protoID: PrototypeList::ID::CryptoKey as u16,
312    },
313    __bindgen_anon_3: JSJitInfo__bindgen_ty_3 { depth: 0 },
314    _bitfield_align_1: [],
315    _bitfield_1: __BindgenBitfieldUnit::new(
316        new_jsjitinfo_bitfield_1!(
317            JSJitInfo_OpType::Getter as u8,
318            JSJitInfo_AliasSet::AliasEverything as u8,
319            JSValueType::JSVAL_TYPE_STRING as u8,
320            true,
321            false,
322            false,
323            false,
324            false,
325            false,
326            0,
327        ).to_ne_bytes()
328    ),
329});
330}
331unsafe extern "C" fn get_extractable<D: DomTypes>
332(cx: *mut RawJSContext, _obj: RawHandleObject, this: *mut libc::c_void, args: JSJitGetterCallArgs) -> bool{
333    let mut result = false;
334    wrap_panic(&mut || result = (|| {
335        let mut cx = JSContext::from_ptr(ptr::NonNull::new(cx).unwrap());
336        let this = &*(this as *const D::CryptoKey);
337        let result: bool = this.Extractable();
338
339        (result).to_jsval(cx.raw_cx(), MutableHandleValue::from_raw(args.rval()));
340        return true;
341    })());
342    result
343}
344
345
346static extractable_getterinfo: ThreadUnsafeOnceLock<JSJitInfo> = ThreadUnsafeOnceLock::new();
347
348pub(crate) fn init_extractable_getterinfo<D: DomTypes>() {
349    extractable_getterinfo.set(JSJitInfo {
350    __bindgen_anon_1: JSJitInfo__bindgen_ty_1 {
351        getter: Some(get_extractable::<D>)
352    },
353    __bindgen_anon_2: JSJitInfo__bindgen_ty_2 {
354        protoID: PrototypeList::ID::CryptoKey as u16,
355    },
356    __bindgen_anon_3: JSJitInfo__bindgen_ty_3 { depth: 0 },
357    _bitfield_align_1: [],
358    _bitfield_1: __BindgenBitfieldUnit::new(
359        new_jsjitinfo_bitfield_1!(
360            JSJitInfo_OpType::Getter as u8,
361            JSJitInfo_AliasSet::AliasEverything as u8,
362            JSValueType::JSVAL_TYPE_BOOLEAN as u8,
363            true,
364            false,
365            false,
366            false,
367            false,
368            false,
369            0,
370        ).to_ne_bytes()
371    ),
372});
373}
374unsafe extern "C" fn get_algorithm<D: DomTypes>
375(cx: *mut RawJSContext, _obj: RawHandleObject, this: *mut libc::c_void, args: JSJitGetterCallArgs) -> bool{
376    let mut result = false;
377    wrap_panic(&mut || result = (|| {
378        let mut cx = JSContext::from_ptr(ptr::NonNull::new(cx).unwrap());
379        let this = &*(this as *const D::CryptoKey);
380        let result: NonNull<JSObject> = this.Algorithm(SafeJSContext::from_ptr(cx.raw_cx()));
381
382        (result).to_jsval(cx.raw_cx(), MutableHandleValue::from_raw(args.rval()));
383        return true;
384    })());
385    result
386}
387
388
389static algorithm_getterinfo: ThreadUnsafeOnceLock<JSJitInfo> = ThreadUnsafeOnceLock::new();
390
391pub(crate) fn init_algorithm_getterinfo<D: DomTypes>() {
392    algorithm_getterinfo.set(JSJitInfo {
393    __bindgen_anon_1: JSJitInfo__bindgen_ty_1 {
394        getter: Some(get_algorithm::<D>)
395    },
396    __bindgen_anon_2: JSJitInfo__bindgen_ty_2 {
397        protoID: PrototypeList::ID::CryptoKey as u16,
398    },
399    __bindgen_anon_3: JSJitInfo__bindgen_ty_3 { depth: 0 },
400    _bitfield_align_1: [],
401    _bitfield_1: __BindgenBitfieldUnit::new(
402        new_jsjitinfo_bitfield_1!(
403            JSJitInfo_OpType::Getter as u8,
404            JSJitInfo_AliasSet::AliasEverything as u8,
405            JSValueType::JSVAL_TYPE_OBJECT as u8,
406            true,
407            false,
408            false,
409            false,
410            false,
411            false,
412            0,
413        ).to_ne_bytes()
414    ),
415});
416}
417unsafe extern "C" fn get_usages<D: DomTypes>
418(cx: *mut RawJSContext, _obj: RawHandleObject, this: *mut libc::c_void, args: JSJitGetterCallArgs) -> bool{
419    let mut result = false;
420    wrap_panic(&mut || result = (|| {
421        let mut cx = JSContext::from_ptr(ptr::NonNull::new(cx).unwrap());
422        let this = &*(this as *const D::CryptoKey);
423        let result: NonNull<JSObject> = this.Usages(SafeJSContext::from_ptr(cx.raw_cx()));
424
425        (result).to_jsval(cx.raw_cx(), MutableHandleValue::from_raw(args.rval()));
426        return true;
427    })());
428    result
429}
430
431
432static usages_getterinfo: ThreadUnsafeOnceLock<JSJitInfo> = ThreadUnsafeOnceLock::new();
433
434pub(crate) fn init_usages_getterinfo<D: DomTypes>() {
435    usages_getterinfo.set(JSJitInfo {
436    __bindgen_anon_1: JSJitInfo__bindgen_ty_1 {
437        getter: Some(get_usages::<D>)
438    },
439    __bindgen_anon_2: JSJitInfo__bindgen_ty_2 {
440        protoID: PrototypeList::ID::CryptoKey as u16,
441    },
442    __bindgen_anon_3: JSJitInfo__bindgen_ty_3 { depth: 0 },
443    _bitfield_align_1: [],
444    _bitfield_1: __BindgenBitfieldUnit::new(
445        new_jsjitinfo_bitfield_1!(
446            JSJitInfo_OpType::Getter as u8,
447            JSJitInfo_AliasSet::AliasEverything as u8,
448            JSValueType::JSVAL_TYPE_OBJECT as u8,
449            true,
450            false,
451            false,
452            false,
453            false,
454            false,
455            0,
456        ).to_ne_bytes()
457    ),
458});
459}
460unsafe extern "C" fn _finalize<D: DomTypes>
461(_cx: *mut GCContext, obj: *mut JSObject){
462    wrap_panic(&mut || {
463
464        let this = native_from_object_static::<D::CryptoKey>(obj).unwrap();
465        finalize_common(this);
466    })
467}
468
469unsafe extern "C" fn _trace<D: DomTypes>
470(trc: *mut JSTracer, obj: *mut JSObject){
471    wrap_panic(&mut || {
472
473        let this = native_from_object_static::<D::CryptoKey>(obj).unwrap();
474        if this.is_null() { return; } // GC during obj creation
475        (*this).trace(trc);
476    })
477}
478
479
480static CLASS_OPS: ThreadUnsafeOnceLock<JSClassOps> = ThreadUnsafeOnceLock::new();
481
482pub(crate) fn init_class_ops<D: DomTypes>() {
483    CLASS_OPS.set(JSClassOps {
484        addProperty: None,
485        delProperty: None,
486        enumerate: None,
487        newEnumerate: None,
488        resolve: None,
489        mayResolve: None,
490        finalize: Some(_finalize::<D>),
491        call: None,
492        construct: None,
493        trace: Some(_trace::<D>),
494    });
495}
496
497pub static Class: ThreadUnsafeOnceLock<DOMJSClass> = ThreadUnsafeOnceLock::new();
498
499pub(crate) fn init_domjs_class<D: DomTypes>() {
500    init_class_ops::<D>();
501    Class.set(DOMJSClass {
502        base: JSClass {
503            name: c"CryptoKey".as_ptr(),
504            flags: JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE |
505                   (((1) & JSCLASS_RESERVED_SLOTS_MASK) << JSCLASS_RESERVED_SLOTS_SHIFT)
506                   /* JSCLASS_HAS_RESERVED_SLOTS(1) */,
507            cOps: unsafe { CLASS_OPS.get() },
508            spec: ptr::null(),
509            ext: ptr::null(),
510            oOps: ptr::null(),
511        },
512        dom_class:
513DOMClass {
514    interface_chain: [ PrototypeList::ID::CryptoKey, PrototypeList::ID::Last, PrototypeList::ID::Last, PrototypeList::ID::Last, PrototypeList::ID::Last, PrototypeList::ID::Last ],
515    depth: 0,
516    type_id: crate::codegen::InheritTypes::TopTypeId { alone: () },
517    malloc_size_of: malloc_size_of_including_raw_self::<D::CryptoKey> as unsafe fn(&mut _, _) -> _,
518    global: Globals::EMPTY,
519},
520    });
521}
522
523#[cfg_attr(crown, allow(crown::unrooted_must_root))] pub unsafe fn Wrap<D: DomTypes>
524(cx: SafeJSContext, scope: &D::GlobalScope, given_proto: Option<HandleObject>, object: Box<D::CryptoKey>, _can_gc: CanGc) -> DomRoot<D::CryptoKey>{
525
526    let raw = Root::new(MaybeUnreflectedDom::from_box(object));
527
528    let scope = scope.reflector().get_jsobject();
529    assert!(!scope.get().is_null());
530    assert!(((*get_object_class(scope.get())).flags & JSCLASS_IS_GLOBAL) != 0);
531    let _ac = JSAutoRealm::new(cx.raw_cx(), scope.get());
532
533    rooted!(&in(cx) let mut canonical_proto = ptr::null_mut::<JSObject>());
534    GetProtoObject::<D>(cx, scope, canonical_proto.handle_mut());
535    assert!(!canonical_proto.is_null());
536
537
538    rooted!(&in(cx) let mut proto = ptr::null_mut::<JSObject>());
539    if let Some(given) = given_proto {
540        proto.set(*given);
541        if get_context_realm(cx.raw_cx()) != get_object_realm(*given) {
542            assert!(JS_WrapObject(cx.raw_cx(), proto.handle_mut()));
543        }
544    } else {
545        proto.set(*canonical_proto);
546    }
547    rooted!(&in(cx) let obj = JS_NewObjectWithGivenProto(
548        cx.raw_cx(),
549        &Class.get().base,
550        proto.handle(),
551    ));
552    assert!(!obj.is_null());
553    JS_SetReservedSlot(
554        obj.get(),
555        DOM_OBJECT_SLOT,
556        &PrivateValue(raw.as_ptr() as *const libc::c_void),
557    );
558
559    let root = raw.reflect_with(obj.get());
560
561
562
563    DomRoot::from_ref(&*root)
564}
565
566pub trait CryptoKeyMethods<D: DomTypes> {
567    fn Type(&self, ) -> KeyType;
568    fn Extractable(&self, ) -> bool;
569    fn Algorithm(&self, r#cx: SafeJSContext) -> NonNull<JSObject>;
570    fn Usages(&self, r#cx: SafeJSContext) -> NonNull<JSObject>;
571}
572static sAttributes_specs: ThreadUnsafeOnceLock<&[&[JSPropertySpec]]> = ThreadUnsafeOnceLock::new();
573
574pub(crate) fn init_sAttributes_specs<D: DomTypes>() {
575    sAttributes_specs.set(Box::leak(Box::new([&Box::leak(Box::new([
576    JSPropertySpec {
577                    name: JSPropertySpec_Name { string_: c"type".as_ptr() },
578                    attributes_: (JSPROP_ENUMERATE),
579                    kind_: (JSPropertySpec_Kind::NativeAccessor),
580                    u: JSPropertySpec_AccessorsOrValue {
581                        accessors: JSPropertySpec_AccessorsOrValue_Accessors {
582                            getter: JSPropertySpec_Accessor {
583                                native: JSNativeWrapper { op: Some(generic_getter::<false>), info: unsafe { type_getterinfo.get() } },
584                            },
585                            setter: JSPropertySpec_Accessor {
586                                native: JSNativeWrapper { op: None, info: ptr::null() },
587                            }
588                        }
589                    }
590                }
591,
592    JSPropertySpec {
593                    name: JSPropertySpec_Name { string_: c"extractable".as_ptr() },
594                    attributes_: (JSPROP_ENUMERATE),
595                    kind_: (JSPropertySpec_Kind::NativeAccessor),
596                    u: JSPropertySpec_AccessorsOrValue {
597                        accessors: JSPropertySpec_AccessorsOrValue_Accessors {
598                            getter: JSPropertySpec_Accessor {
599                                native: JSNativeWrapper { op: Some(generic_getter::<false>), info: unsafe { extractable_getterinfo.get() } },
600                            },
601                            setter: JSPropertySpec_Accessor {
602                                native: JSNativeWrapper { op: None, info: ptr::null() },
603                            }
604                        }
605                    }
606                }
607,
608    JSPropertySpec {
609                    name: JSPropertySpec_Name { string_: c"algorithm".as_ptr() },
610                    attributes_: (JSPROP_ENUMERATE),
611                    kind_: (JSPropertySpec_Kind::NativeAccessor),
612                    u: JSPropertySpec_AccessorsOrValue {
613                        accessors: JSPropertySpec_AccessorsOrValue_Accessors {
614                            getter: JSPropertySpec_Accessor {
615                                native: JSNativeWrapper { op: Some(generic_getter::<false>), info: unsafe { algorithm_getterinfo.get() } },
616                            },
617                            setter: JSPropertySpec_Accessor {
618                                native: JSNativeWrapper { op: None, info: ptr::null() },
619                            }
620                        }
621                    }
622                }
623,
624    JSPropertySpec {
625                    name: JSPropertySpec_Name { string_: c"usages".as_ptr() },
626                    attributes_: (JSPROP_ENUMERATE),
627                    kind_: (JSPropertySpec_Kind::NativeAccessor),
628                    u: JSPropertySpec_AccessorsOrValue {
629                        accessors: JSPropertySpec_AccessorsOrValue_Accessors {
630                            getter: JSPropertySpec_Accessor {
631                                native: JSNativeWrapper { op: Some(generic_getter::<false>), info: unsafe { usages_getterinfo.get() } },
632                            },
633                            setter: JSPropertySpec_Accessor {
634                                native: JSNativeWrapper { op: None, info: ptr::null() },
635                            }
636                        }
637                    }
638                }
639,
640    JSPropertySpec::ZERO]))[..]
641,
642&Box::leak(Box::new([
643    JSPropertySpec {
644                    name: JSPropertySpec_Name { symbol_: SymbolCode::toStringTag as usize + 1 },
645                    attributes_: (JSPROP_READONLY),
646                    kind_: (JSPropertySpec_Kind::Value),
647                    u: JSPropertySpec_AccessorsOrValue {
648                        value: JSPropertySpec_ValueWrapper {
649                            type_: JSPropertySpec_ValueWrapper_Type::String,
650                            __bindgen_anon_1: JSPropertySpec_ValueWrapper__bindgen_ty_1 {
651                                string: c"CryptoKey".as_ptr(),
652                            }
653                        }
654                    }
655                }
656,
657    JSPropertySpec::ZERO]))[..]
658])));
659}static sAttributes: ThreadUnsafeOnceLock<&[Guard<&[JSPropertySpec]>]> = ThreadUnsafeOnceLock::new();
660
661pub(crate) fn init_sAttributes_prefs<D: DomTypes>() {
662    sAttributes.set(Box::leak(Box::new([    Guard::new(&[Condition::SecureContext(),Condition::Exposed(Globals::WINDOW),Condition::Exposed(Globals::SERVICE_WORKER_GLOBAL_SCOPE),Condition::Exposed(Globals::DEDICATED_WORKER_GLOBAL_SCOPE)], (unsafe { sAttributes_specs.get() })[0]),
663    Guard::new(&[Condition::Satisfied], (unsafe { sAttributes_specs.get() })[1])])));
664}
665pub fn GetProtoObject<D: DomTypes>
666(cx: SafeJSContext, global: HandleObject, mut rval: MutableHandleObject){
667    /* Get the interface prototype object for this class.  This will create the
668       object as needed. */get_per_interface_object_handle(cx, global, ProtoOrIfaceIndex::ID(PrototypeList::ID::CryptoKey), CreateInterfaceObjects::<D>, rval)
669}
670
671
672static PrototypeClass: JSClass = JSClass {
673    name: c"CryptoKeyPrototype".as_ptr(),
674    flags:
675        // JSCLASS_HAS_RESERVED_SLOTS()
676        (0 ) << JSCLASS_RESERVED_SLOTS_SHIFT,
677    cOps: ptr::null(),
678    spec: ptr::null(),
679    ext: ptr::null(),
680    oOps: ptr::null(),
681};
682
683
684static INTERFACE_OBJECT_CLASS: ThreadUnsafeOnceLock<NonCallbackInterfaceObjectClass> = ThreadUnsafeOnceLock::new();
685
686pub(crate) fn init_interface_object<D: DomTypes>() {
687    INTERFACE_OBJECT_CLASS.set(NonCallbackInterfaceObjectClass::new(
688        Box::leak(Box::new(InterfaceConstructorBehavior::throw())),
689        b"function CryptoKey() {\n    [native code]\n}",
690        PrototypeList::ID::CryptoKey,
691        0,
692    ));
693}
694
695pub fn DefineDOMInterface<D: DomTypes>
696(cx: SafeJSContext, global: HandleObject){
697    define_dom_interface(cx, global, ProtoOrIfaceIndex::ID(PrototypeList::ID::CryptoKey),CreateInterfaceObjects::<D>, ConstructorEnabled::<D>)
698}
699
700pub fn ConstructorEnabled<D: DomTypes>
701(aCx: SafeJSContext, aObj: HandleObject) -> bool{
702    is_exposed_in(aObj, Globals::DEDICATED_WORKER_GLOBAL_SCOPE | Globals::SERVICE_WORKER_GLOBAL_SCOPE | Globals::WINDOW) &&
703    pref!(dom_crypto_subtle_enabled) &&
704
705    unsafe {
706        let in_realm_proof = AlreadyInRealm::assert_for_cx(aCx);
707        D::GlobalScope::from_context(*aCx, InRealm::Already(&in_realm_proof)).is_secure_context()
708    }
709
710}
711
712unsafe fn CreateInterfaceObjects<D: DomTypes>
713(cx: SafeJSContext, global: HandleObject, cache: *mut ProtoOrIfaceArray){
714
715    rooted!(&in(cx) let mut prototype_proto = ptr::null_mut::<JSObject>());
716    prototype_proto.set(GetRealmObjectPrototype(cx.raw_cx()));
717    assert!(!prototype_proto.is_null());
718
719    rooted!(&in(cx) let mut prototype = ptr::null_mut::<JSObject>());
720    create_interface_prototype_object::<D>(cx,
721                                      global,
722                                      prototype_proto.handle(),
723                                      &PrototypeClass,
724                                      &[],
725                                      sAttributes.get(),
726                                      &[],
727                                      &[],
728                                      prototype.handle_mut());
729    assert!(!prototype.is_null());
730    assert!((*cache)[PrototypeList::ID::CryptoKey as usize].is_null());
731    (*cache)[PrototypeList::ID::CryptoKey as usize] = prototype.get();
732    <*mut JSObject>::post_barrier((*cache).as_mut_ptr().offset(PrototypeList::ID::CryptoKey as isize),
733                                  ptr::null_mut(),
734                                  prototype.get());
735
736    rooted!(&in(cx) let mut interface_proto = ptr::null_mut::<JSObject>());
737    interface_proto.set(GetRealmFunctionPrototype(cx.raw_cx()));
738
739    assert!(!interface_proto.is_null());
740
741    rooted!(&in(cx) let mut interface = ptr::null_mut::<JSObject>());
742    create_noncallback_interface_object::<D>(cx,
743                                        global,
744                                        interface_proto.handle(),
745                                        INTERFACE_OBJECT_CLASS.get(),
746                                        &[],
747                                        &[],
748                                        &[],
749                                        prototype.handle(),
750                                        c"CryptoKey",
751                                        0,
752                                        &[],
753                                        interface.handle_mut());
754    assert!(!interface.is_null());
755}
756
757
758        pub(crate) fn init_statics<D: DomTypes>() {
759            init_interface_object::<D>();
760            init_domjs_class::<D>();
761
762            init_type_getterinfo::<D>();
763init_extractable_getterinfo::<D>();
764init_algorithm_getterinfo::<D>();
765init_usages_getterinfo::<D>();
766
767
768            init_sAttributes_specs::<D>();
769init_sAttributes_prefs::<D>();
770        }
771        } // mod CryptoKey_Binding
772
773