Skip to main content

servo_constellation_traits/structured_data/
serializable.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5//! This module contains implementations in script that are serializable,
6//! as per <https://html.spec.whatwg.org/multipage/#serializable-objects>.
7//! The implementations are here instead of in script as they need to
8//! be passed through the Constellation.
9
10use std::cell::RefCell;
11use std::path::PathBuf;
12
13use euclid::default::Transform3D;
14use malloc_size_of_derive::MallocSizeOf;
15use net_traits::filemanager_thread::RelativePos;
16use pixels::SharedSnapshot;
17use rustc_hash::FxHashMap;
18use serde::{Deserialize, Serialize};
19use servo_base::id::{
20    BlobId, CryptoKeyId, DomExceptionId, DomMatrixId, DomPointId, DomQuadId, DomRectId, FileId,
21    FileListId, ImageBitmapId, ImageDataId, QuotaExceededErrorId,
22};
23use servo_url::ImmutableOrigin;
24use strum::EnumIter;
25use uuid::Uuid;
26use zeroize::{Zeroize, ZeroizeOnDrop};
27
28use super::StructuredSerializedData;
29
30pub(crate) trait BroadcastClone
31where
32    Self: Sized,
33{
34    /// The ID type that uniquely identify each value.
35    type Id: Eq + std::hash::Hash + Copy;
36    /// Clone this value so that it can be reused with a broadcast channel.
37    /// Only return None if cloning is impossible.
38    fn clone_for_broadcast(&self) -> Option<Self>;
39    /// The field from which to clone values.
40    fn source(data: &StructuredSerializedData) -> &Option<FxHashMap<Self::Id, Self>>;
41    /// The field into which to place cloned values.
42    fn destination(data: &mut StructuredSerializedData) -> &mut Option<FxHashMap<Self::Id, Self>>;
43}
44
45/// All the DOM interfaces that can be serialized.
46///
47/// NOTE: Variants which are derived from other serializable interfaces must come before their
48/// parents because serialization is attempted in order of the variants.
49#[derive(Clone, Copy, Debug, EnumIter)]
50pub enum Serializable {
51    /// The `File` interface.
52    File,
53    /// The `FileList` interface.
54    FileList,
55    /// The `Blob` interface.
56    Blob,
57    /// The `DOMPoint` interface.
58    DomPoint,
59    /// The `DOMPointReadOnly` interface.
60    DomPointReadOnly,
61    /// The `DOMRect` interface.
62    DomRect,
63    /// The `DOMRectReadOnly` interface.
64    DomRectReadOnly,
65    /// The `DOMQuad` interface.
66    DomQuad,
67    /// The `DOMMatrix` interface.
68    DomMatrix,
69    /// The `DOMMatrixReadOnly` interface.
70    DomMatrixReadOnly,
71    /// The `QuotaExceededError` interface.
72    QuotaExceededError,
73    /// The `DOMException` interface.
74    DomException,
75    /// The `ImageBitmap` interface.
76    ImageBitmap,
77    /// The `ImageData` interface.
78    ImageData,
79    /// The `CryptoKey` interface.
80    #[cfg(feature = "webcrypto")]
81    CryptoKey,
82}
83
84impl Serializable {
85    pub(super) fn clone_values(
86        &self,
87    ) -> fn(&StructuredSerializedData, &mut StructuredSerializedData) {
88        match self {
89            Serializable::File => StructuredSerializedData::clone_all_of_type::<SerializableFile>,
90            Serializable::FileList => {
91                StructuredSerializedData::clone_all_of_type::<SerializableFileList>
92            },
93            Serializable::Blob => StructuredSerializedData::clone_all_of_type::<BlobImpl>,
94            Serializable::DomPoint => StructuredSerializedData::clone_all_of_type::<DomPoint>,
95            Serializable::DomPointReadOnly => {
96                StructuredSerializedData::clone_all_of_type::<DomPoint>
97            },
98            Serializable::DomRect => StructuredSerializedData::clone_all_of_type::<DomRect>,
99            Serializable::DomRectReadOnly => StructuredSerializedData::clone_all_of_type::<DomRect>,
100            Serializable::DomQuad => StructuredSerializedData::clone_all_of_type::<DomQuad>,
101            Serializable::DomMatrix => StructuredSerializedData::clone_all_of_type::<DomMatrix>,
102            Serializable::DomMatrixReadOnly => {
103                StructuredSerializedData::clone_all_of_type::<DomMatrix>
104            },
105            Serializable::DomException => {
106                StructuredSerializedData::clone_all_of_type::<DomException>
107            },
108            Serializable::ImageBitmap => {
109                StructuredSerializedData::clone_all_of_type::<SerializableImageBitmap>
110            },
111            Serializable::QuotaExceededError => {
112                StructuredSerializedData::clone_all_of_type::<SerializableQuotaExceededError>
113            },
114            Serializable::ImageData => {
115                StructuredSerializedData::clone_all_of_type::<SerializableImageData>
116            },
117            #[cfg(feature = "webcrypto")]
118            Serializable::CryptoKey => {
119                StructuredSerializedData::clone_all_of_type::<SerializableCryptoKey>
120            },
121        }
122    }
123}
124
125/// Message for communication between the constellation and a global managing broadcast channels.
126#[derive(Debug, Deserialize, Serialize)]
127pub struct BroadcastChannelMsg {
128    /// The origin of this message.
129    pub origin: ImmutableOrigin,
130    /// The name of the channel.
131    pub channel_name: String,
132    /// A data-holder for serialized data.
133    pub data: StructuredSerializedData,
134}
135
136impl Clone for BroadcastChannelMsg {
137    fn clone(&self) -> BroadcastChannelMsg {
138        BroadcastChannelMsg {
139            data: self.data.clone_for_broadcast(),
140            origin: self.origin.clone(),
141            channel_name: self.channel_name.clone(),
142        }
143    }
144}
145
146#[derive(Debug, Deserialize, MallocSizeOf, Serialize)]
147pub struct SerializableFile {
148    pub blob_impl: BlobImpl,
149    pub name: String,
150    pub modified: i64,
151    pub webkit_relative_path: String,
152}
153
154impl BroadcastClone for SerializableFile {
155    type Id = FileId;
156
157    fn source(data: &StructuredSerializedData) -> &Option<FxHashMap<Self::Id, Self>> {
158        &data.files
159    }
160
161    fn destination(data: &mut StructuredSerializedData) -> &mut Option<FxHashMap<Self::Id, Self>> {
162        &mut data.files
163    }
164
165    fn clone_for_broadcast(&self) -> Option<Self> {
166        let blob_impl = self.blob_impl.clone_for_broadcast()?;
167        Some(SerializableFile {
168            blob_impl,
169            name: self.name.clone(),
170            modified: self.modified,
171            webkit_relative_path: self.webkit_relative_path.clone(),
172        })
173    }
174}
175
176#[derive(Debug, Deserialize, MallocSizeOf, Serialize)]
177pub struct SerializableFileList {
178    pub files: Vec<SerializableFile>,
179}
180
181impl BroadcastClone for SerializableFileList {
182    type Id = FileListId;
183
184    fn source(data: &StructuredSerializedData) -> &Option<FxHashMap<Self::Id, Self>> {
185        &data.file_lists
186    }
187
188    fn destination(data: &mut StructuredSerializedData) -> &mut Option<FxHashMap<Self::Id, Self>> {
189        &mut data.file_lists
190    }
191
192    fn clone_for_broadcast(&self) -> Option<Self> {
193        let files = self
194            .files
195            .iter()
196            .map(|file| file.clone_for_broadcast())
197            .collect::<Option<Vec<_>>>()?;
198        Some(SerializableFileList { files })
199    }
200}
201
202/// File-based blob
203#[derive(Debug, Deserialize, MallocSizeOf, Serialize)]
204pub struct FileBlob {
205    id: Uuid,
206    name: Option<PathBuf>,
207    cache: RefCell<Option<Vec<u8>>>,
208    size: u64,
209}
210
211impl FileBlob {
212    /// Create a new file blob.
213    pub fn new(id: Uuid, name: Option<PathBuf>, cache: Option<Vec<u8>>, size: u64) -> FileBlob {
214        FileBlob {
215            id,
216            name,
217            cache: RefCell::new(cache),
218            size,
219        }
220    }
221
222    /// Get the size of the file.
223    pub fn get_size(&self) -> u64 {
224        self.size
225    }
226
227    /// Get the cached file data, if any.
228    pub fn get_cache(&self) -> Option<Vec<u8>> {
229        self.cache.borrow().clone()
230    }
231
232    /// Cache data.
233    pub fn cache_bytes(&self, bytes: Vec<u8>) {
234        *self.cache.borrow_mut() = Some(bytes);
235    }
236
237    /// Get the file id.
238    pub fn get_id(&self) -> Uuid {
239        self.id
240    }
241}
242
243impl BroadcastClone for BlobImpl {
244    type Id = BlobId;
245
246    fn source(data: &StructuredSerializedData) -> &Option<FxHashMap<Self::Id, Self>> {
247        &data.blobs
248    }
249
250    fn destination(data: &mut StructuredSerializedData) -> &mut Option<FxHashMap<Self::Id, Self>> {
251        &mut data.blobs
252    }
253
254    fn clone_for_broadcast(&self) -> Option<Self> {
255        let type_string = self.type_string();
256
257        if let BlobData::Memory(bytes) = self.blob_data() {
258            let blob_clone = BlobImpl::new_from_bytes(bytes.clone(), type_string);
259
260            // Note: we insert the blob at the original id,
261            // otherwise this will not match the storage key as serialized by SM in `serialized`.
262            // The clone has it's own new Id however.
263            return Some(blob_clone);
264        } else {
265            // Not panicking only because this is called from the constellation.
266            log::warn!("Serialized blob not in memory format(should never happen).");
267        }
268        None
269    }
270}
271
272/// The data backing a DOM Blob.
273#[derive(Debug, Deserialize, MallocSizeOf, Serialize)]
274pub struct BlobImpl {
275    /// UUID of the blob.
276    blob_id: BlobId,
277    /// Content-type string
278    type_string: String,
279    /// Blob data-type.
280    blob_data: BlobData,
281    /// Sliced blobs referring to this one.
282    slices: Vec<BlobId>,
283}
284
285/// Different backends of Blob
286#[derive(Debug, Deserialize, MallocSizeOf, Serialize)]
287pub enum BlobData {
288    /// File-based blob, whose content lives in the net process
289    File(FileBlob),
290    /// Memory-based blob, whose content lives in the script process
291    Memory(Vec<u8>),
292    /// Sliced blob, including parent blob-id and
293    /// relative positions of current slicing range,
294    /// IMPORTANT: The depth of tree is only two, i.e. the parent Blob must be
295    /// either File-based or Memory-based
296    Sliced(BlobId, RelativePos),
297}
298
299impl BlobImpl {
300    /// Construct memory-backed BlobImpl
301    pub fn new_from_bytes(bytes: Vec<u8>, type_string: String) -> BlobImpl {
302        let blob_id = BlobId::new();
303        let blob_data = BlobData::Memory(bytes);
304        BlobImpl {
305            blob_id,
306            type_string,
307            blob_data,
308            slices: vec![],
309        }
310    }
311
312    /// Construct file-backed BlobImpl from File ID
313    pub fn new_from_file(file_id: Uuid, name: PathBuf, size: u64, type_string: String) -> BlobImpl {
314        let blob_id = BlobId::new();
315        let blob_data = BlobData::File(FileBlob {
316            id: file_id,
317            name: Some(name),
318            cache: RefCell::new(None),
319            size,
320        });
321        BlobImpl {
322            blob_id,
323            type_string,
324            blob_data,
325            slices: vec![],
326        }
327    }
328
329    /// Construct a BlobImpl from a slice of a parent.
330    pub fn new_sliced(range: RelativePos, parent: BlobId, type_string: String) -> BlobImpl {
331        let blob_id = BlobId::new();
332        let blob_data = BlobData::Sliced(parent, range);
333        BlobImpl {
334            blob_id,
335            type_string,
336            blob_data,
337            slices: vec![],
338        }
339    }
340
341    /// Get a clone of the blob-id
342    pub fn blob_id(&self) -> BlobId {
343        self.blob_id
344    }
345
346    /// Get a clone of the type-string
347    pub fn type_string(&self) -> String {
348        self.type_string.clone()
349    }
350
351    /// Get a mutable ref to the data
352    pub fn blob_data(&self) -> &BlobData {
353        &self.blob_data
354    }
355
356    /// Get a mutable ref to the data
357    pub fn blob_data_mut(&mut self) -> &mut BlobData {
358        &mut self.blob_data
359    }
360}
361
362#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
363/// A serializable version of the DOMPoint/DOMPointReadOnly interface.
364pub struct DomPoint {
365    /// The x coordinate.
366    pub x: f64,
367    /// The y coordinate.
368    pub y: f64,
369    /// The z coordinate.
370    pub z: f64,
371    /// The w coordinate.
372    pub w: f64,
373}
374
375impl BroadcastClone for DomPoint {
376    type Id = DomPointId;
377
378    fn source(data: &StructuredSerializedData) -> &Option<FxHashMap<Self::Id, Self>> {
379        &data.points
380    }
381
382    fn destination(data: &mut StructuredSerializedData) -> &mut Option<FxHashMap<Self::Id, Self>> {
383        &mut data.points
384    }
385
386    fn clone_for_broadcast(&self) -> Option<Self> {
387        Some(self.clone())
388    }
389}
390
391#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
392/// A serializable version of the DOMRect/DOMRectReadOnly interface.
393pub struct DomRect {
394    /// The x coordinate.
395    pub x: f64,
396    /// The y coordinate.
397    pub y: f64,
398    /// The width.
399    pub width: f64,
400    /// The height.
401    pub height: f64,
402}
403
404impl BroadcastClone for DomRect {
405    type Id = DomRectId;
406
407    fn source(data: &StructuredSerializedData) -> &Option<FxHashMap<Self::Id, Self>> {
408        &data.rects
409    }
410
411    fn destination(data: &mut StructuredSerializedData) -> &mut Option<FxHashMap<Self::Id, Self>> {
412        &mut data.rects
413    }
414
415    fn clone_for_broadcast(&self) -> Option<Self> {
416        Some(self.clone())
417    }
418}
419
420#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
421/// A serializable version of the DOMQuad interface.
422pub struct DomQuad {
423    /// The first point.
424    pub p1: DomPoint,
425    /// The second point.
426    pub p2: DomPoint,
427    /// The third point.
428    pub p3: DomPoint,
429    /// The fourth point.
430    pub p4: DomPoint,
431}
432
433impl BroadcastClone for DomQuad {
434    type Id = DomQuadId;
435
436    fn source(data: &StructuredSerializedData) -> &Option<FxHashMap<Self::Id, Self>> {
437        &data.quads
438    }
439
440    fn destination(data: &mut StructuredSerializedData) -> &mut Option<FxHashMap<Self::Id, Self>> {
441        &mut data.quads
442    }
443
444    fn clone_for_broadcast(&self) -> Option<Self> {
445        Some(self.clone())
446    }
447}
448
449#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
450/// A serializable version of the DOMMatrix/DOMMatrixReadOnly interface.
451pub struct DomMatrix {
452    /// The matrix.
453    pub matrix: Transform3D<f64>,
454    /// Whether this matrix represents a 2D transformation.
455    pub is_2d: bool,
456}
457
458impl BroadcastClone for DomMatrix {
459    type Id = DomMatrixId;
460
461    fn source(data: &StructuredSerializedData) -> &Option<FxHashMap<Self::Id, Self>> {
462        &data.matrices
463    }
464
465    fn destination(data: &mut StructuredSerializedData) -> &mut Option<FxHashMap<Self::Id, Self>> {
466        &mut data.matrices
467    }
468
469    fn clone_for_broadcast(&self) -> Option<Self> {
470        Some(self.clone())
471    }
472}
473
474#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
475/// A serializable version of the DOMException interface.
476pub struct DomException {
477    pub message: String,
478    pub name: String,
479}
480
481impl BroadcastClone for DomException {
482    type Id = DomExceptionId;
483
484    fn source(data: &StructuredSerializedData) -> &Option<FxHashMap<Self::Id, Self>> {
485        &data.exceptions
486    }
487
488    fn destination(data: &mut StructuredSerializedData) -> &mut Option<FxHashMap<Self::Id, Self>> {
489        &mut data.exceptions
490    }
491
492    fn clone_for_broadcast(&self) -> Option<Self> {
493        Some(self.clone())
494    }
495}
496
497#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
498/// A serializable version of the QuotaExceededError interface.
499pub struct SerializableQuotaExceededError {
500    pub dom_exception: DomException,
501    pub quota: Option<f64>,
502    pub requested: Option<f64>,
503}
504
505impl BroadcastClone for SerializableQuotaExceededError {
506    type Id = QuotaExceededErrorId;
507
508    fn source(data: &StructuredSerializedData) -> &Option<FxHashMap<Self::Id, Self>> {
509        &data.quota_exceeded_errors
510    }
511
512    fn destination(data: &mut StructuredSerializedData) -> &mut Option<FxHashMap<Self::Id, Self>> {
513        &mut data.quota_exceeded_errors
514    }
515
516    fn clone_for_broadcast(&self) -> Option<Self> {
517        Some(self.clone())
518    }
519}
520
521#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
522/// A serializable version of the ImageBitmap interface.
523pub struct SerializableImageBitmap {
524    pub bitmap_data: SharedSnapshot,
525}
526
527impl BroadcastClone for SerializableImageBitmap {
528    type Id = ImageBitmapId;
529
530    fn source(data: &StructuredSerializedData) -> &Option<FxHashMap<Self::Id, Self>> {
531        &data.image_bitmaps
532    }
533
534    fn destination(data: &mut StructuredSerializedData) -> &mut Option<FxHashMap<Self::Id, Self>> {
535        &mut data.image_bitmaps
536    }
537
538    fn clone_for_broadcast(&self) -> Option<Self> {
539        Some(self.clone())
540    }
541}
542
543#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
544pub struct SerializableImageData {
545    pub data: Vec<u8>,
546    pub width: u32,
547    pub height: u32,
548}
549
550impl BroadcastClone for SerializableImageData {
551    type Id = ImageDataId;
552
553    fn source(data: &StructuredSerializedData) -> &Option<FxHashMap<Self::Id, Self>> {
554        &data.image_data
555    }
556
557    fn destination(data: &mut StructuredSerializedData) -> &mut Option<FxHashMap<Self::Id, Self>> {
558        &mut data.image_data
559    }
560
561    fn clone_for_broadcast(&self) -> Option<Self> {
562        Some(self.clone())
563    }
564}
565
566/// A serializable version of the `Algorithm` dictionary, used by the `SubtleCrypto` interface.
567#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
568pub struct SerializableAlgorithm {
569    pub name: String,
570}
571
572/// A serializable version of the `CShakeParams` dictionary, used by the `SubtleCrypto` interface.
573#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
574pub struct SerializableCShakeParams {
575    pub name: String,
576    pub output_length: u32,
577    pub function_name: Option<Vec<u8>>,
578    pub customization: Option<Vec<u8>>,
579}
580
581/// A serializable version of the `TurboShakeParams` dictionary, used by the `SubtleCrypto`
582/// interface.
583#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
584pub struct SerializableTurboShakeParams {
585    pub name: String,
586    pub output_length: u32,
587    pub domain_separation: Option<u8>,
588}
589
590/// A serializable version of the `KangarooTwelvelParams` dictionary, used by the `SubtleCrypto`
591/// interface.
592#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
593pub struct SerializableKangarooTwelveParams {
594    pub name: String,
595    pub output_length: u32,
596    pub customization: Option<Vec<u8>>,
597}
598
599/// A serializable version of the `DigestAlgorithm` type, used the `SubtleCrypto` interface.
600#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
601pub enum SerializableDigestAlgorithm {
602    Sha(SerializableAlgorithm),
603    Sha3(SerializableAlgorithm),
604    CShake(SerializableCShakeParams),
605    TurboShake(SerializableTurboShakeParams),
606    KangarooTwelve(SerializableKangarooTwelveParams),
607}
608
609/// A serializable version of the `KeyAlgorithm` dictionary, used the `SubtleCrypto` interface.
610#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
611pub struct SerializableKeyAlgorithm {
612    pub name: String,
613}
614
615/// A serializable version of the `RsaHashedKeyAlgorithm` dictionary, used the `SubtleCrypto`
616/// interface.
617#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
618pub struct SerializableRsaHashedKeyAlgorithm {
619    pub name: String,
620    pub modulus_length: u32,
621    pub public_exponent: Vec<u8>,
622    pub hash: SerializableDigestAlgorithm,
623}
624
625/// A serializable version of the `EcKeyAlgorithm` dictionary, used the `SubtleCrypto` interface.
626#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
627pub struct SerializableEcKeyAlgorithm {
628    pub name: String,
629    pub named_curve: String,
630}
631
632/// A serializable version of the `AesKeyAlgorithm` dictionary, used the `SubtleCrypto` interface.
633#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
634pub struct SerializableAesKeyAlgorithm {
635    pub name: String,
636    pub length: u16,
637}
638
639/// A serializable version of the `HmacKeyAlgorithm` dictionary, used the `SubtleCrypto` interface.
640#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
641pub struct SerializableHmacKeyAlgorithm {
642    pub name: String,
643    pub hash: SerializableDigestAlgorithm,
644    pub length: u32,
645}
646
647/// A serializable version of the `KmacKeyAlgorithm` dictionary, used the `SubtleCrypto` interface.
648#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
649pub struct SerializableKmacKeyAlgorithm {
650    pub name: String,
651    pub length: u32,
652}
653
654/// A serializable version of the `KeyAlgorithmAndDerivatives` type, used by the `SubtleCrypto`
655/// interface.
656#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
657pub enum SerializableKeyAlgorithmAndDerivatives {
658    KeyAlgorithm(SerializableKeyAlgorithm),
659    RsaHashedKeyAlgorithm(SerializableRsaHashedKeyAlgorithm),
660    EcKeyAlgorithm(SerializableEcKeyAlgorithm),
661    AesKeyAlgorithm(SerializableAesKeyAlgorithm),
662    HmacKeyAlgorithm(SerializableHmacKeyAlgorithm),
663    KmacKeyAlgorithm(SerializableKmacKeyAlgorithm),
664}
665
666/// A serializable version of the `Handle` type, used by the `CryptoKey` interface.
667#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize, Zeroize, ZeroizeOnDrop)]
668pub enum SerializableCryptoKeyHandle {
669    RsaPrivateKey(Vec<u8>),
670    RsaPublicKey(Vec<u8>),
671    P256PrivateKey(Vec<u8>),
672    P384PrivateKey(Vec<u8>),
673    P521PrivateKey(Vec<u8>),
674    P256PublicKey(Vec<u8>),
675    P384PublicKey(Vec<u8>),
676    P521PublicKey(Vec<u8>),
677    Ed25519PrivateKey([u8; 32]),
678    Ed25519PublicKey([u8; 32]),
679    X25519PrivateKey([u8; 32]),
680    X25519PublicKey([u8; 32]),
681    Ed448PrivateKey(Vec<u8>),
682    Ed448PublicKey(Vec<u8>),
683    X448PrivateKey(Vec<u8>),
684    X448PublicKey(Vec<u8>),
685    Aes128Key(Vec<u8>),
686    Aes192Key(Vec<u8>),
687    Aes256Key(Vec<u8>),
688    HkdfSecret(Vec<u8>),
689    Pbkdf2(Vec<u8>),
690    Hmac(Vec<u8>),
691    MlKem512PrivateKey(Vec<u8>),
692    MlKem768PrivateKey(Vec<u8>),
693    MlKem1024PrivateKey(Vec<u8>),
694    MlKem512PublicKey(Vec<u8>),
695    MlKem768PublicKey(Vec<u8>),
696    MlKem1024PublicKey(Vec<u8>),
697    MlDsa44PrivateKey(Vec<u8>),
698    MlDsa65PrivateKey(Vec<u8>),
699    MlDsa87PrivateKey(Vec<u8>),
700    MlDsa44PublicKey(Vec<u8>),
701    MlDsa65PublicKey(Vec<u8>),
702    MlDsa87PublicKey(Vec<u8>),
703    ChaCha20Poly1305Key(Vec<u8>),
704    KmacKey(Vec<u8>),
705    Argon2Password(Vec<u8>),
706}
707
708/// A serializable version of the `CryptoKey` interface.
709#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
710pub struct SerializableCryptoKey {
711    pub key_type: String,
712    pub extractable: bool,
713    pub algorithm: SerializableKeyAlgorithmAndDerivatives,
714    pub usages: Vec<String>,
715    pub handle: SerializableCryptoKeyHandle,
716}
717
718impl BroadcastClone for SerializableCryptoKey {
719    type Id = CryptoKeyId;
720
721    fn source(data: &StructuredSerializedData) -> &Option<FxHashMap<Self::Id, Self>> {
722        &data.crypto_keys
723    }
724
725    fn destination(data: &mut StructuredSerializedData) -> &mut Option<FxHashMap<Self::Id, Self>> {
726        &mut data.crypto_keys
727    }
728
729    fn clone_for_broadcast(&self) -> Option<Self> {
730        Some(self.clone())
731    }
732}