From a90a5cba08fdf6c0ceb95101c275108a152a3aed Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 12 Jun 2024 07:35:37 +0200 Subject: Merging upstream version 127.0. Signed-off-by: Daniel Baumann --- toolkit/components/telemetry/dap/ffi/src/types.rs | 83 ++++++++++++++--------- 1 file changed, 50 insertions(+), 33 deletions(-) (limited to 'toolkit/components/telemetry/dap/ffi/src/types.rs') diff --git a/toolkit/components/telemetry/dap/ffi/src/types.rs b/toolkit/components/telemetry/dap/ffi/src/types.rs index e8f6385dcd..c84cbf16bc 100644 --- a/toolkit/components/telemetry/dap/ffi/src/types.rs +++ b/toolkit/components/telemetry/dap/ffi/src/types.rs @@ -34,8 +34,9 @@ impl Decode for TaskID { } impl Encode for TaskID { - fn encode(&self, bytes: &mut Vec) { + fn encode(&self, bytes: &mut Vec) -> Result<(), CodecError> { bytes.extend_from_slice(&self.0); + Ok(()) } } @@ -52,8 +53,9 @@ impl Decode for Time { } impl Encode for Time { - fn encode(&self, bytes: &mut Vec) { - u64::encode(&self.0, bytes); + fn encode(&self, bytes: &mut Vec) -> Result<(), CodecError> { + u64::encode(&self.0, bytes)?; + Ok(()) } } @@ -93,9 +95,10 @@ impl Decode for Extension { } impl Encode for Extension { - fn encode(&self, bytes: &mut Vec) { - (self.extension_type as u16).encode(bytes); - encode_u16_items(bytes, &(), &self.extension_data); + fn encode(&self, bytes: &mut Vec) -> Result<(), CodecError> { + (self.extension_type as u16).encode(bytes)?; + encode_u16_items(bytes, &(), &self.extension_data)?; + Ok(()) } } @@ -131,9 +134,10 @@ pub struct PlaintextInputShare { } impl Encode for PlaintextInputShare { - fn encode(&self, bytes: &mut Vec) { - encode_u16_items(bytes, &(), &self.extensions); - encode_u32_items(bytes, &(), &self.payload); + fn encode(&self, bytes: &mut Vec) -> Result<(), CodecError> { + encode_u16_items(bytes, &(), &self.extensions)?; + encode_u32_items(bytes, &(), &self.payload)?; + Ok(()) } } @@ -150,8 +154,9 @@ impl Decode for HpkeConfigId { } impl Encode for HpkeConfigId { - fn encode(&self, bytes: &mut Vec) { - self.0.encode(bytes); + fn encode(&self, bytes: &mut Vec) -> Result<(), CodecError> { + self.0.encode(bytes)?; + Ok(()) } } @@ -189,12 +194,13 @@ impl Decode for HpkeConfig { } impl Encode for HpkeConfig { - fn encode(&self, bytes: &mut Vec) { - self.id.encode(bytes); - self.kem_id.encode(bytes); - self.kdf_id.encode(bytes); - self.aead_id.encode(bytes); - encode_u16_items(bytes, &(), &self.public_key); + fn encode(&self, bytes: &mut Vec) -> Result<(), CodecError> { + self.id.encode(bytes)?; + self.kem_id.encode(bytes)?; + self.kdf_id.encode(bytes)?; + self.aead_id.encode(bytes)?; + encode_u16_items(bytes, &(), &self.public_key)?; + Ok(()) } } @@ -227,10 +233,11 @@ impl Decode for HpkeCiphertext { } impl Encode for HpkeCiphertext { - fn encode(&self, bytes: &mut Vec) { - self.config_id.encode(bytes); - encode_u16_items(bytes, &(), &self.enc); - encode_u32_items(bytes, &(), &self.payload); + fn encode(&self, bytes: &mut Vec) -> Result<(), CodecError> { + self.config_id.encode(bytes)?; + encode_u16_items(bytes, &(), &self.enc)?; + encode_u32_items(bytes, &(), &self.payload)?; + Ok(()) } } @@ -248,8 +255,9 @@ impl Decode for ReportID { } impl Encode for ReportID { - fn encode(&self, bytes: &mut Vec) { + fn encode(&self, bytes: &mut Vec) -> Result<(), CodecError> { bytes.extend_from_slice(&self.0); + Ok(()) } } @@ -286,9 +294,10 @@ impl Decode for ReportMetadata { } impl Encode for ReportMetadata { - fn encode(&self, bytes: &mut Vec) { - self.report_id.encode(bytes); - self.time.encode(bytes); + fn encode(&self, bytes: &mut Vec) -> Result<(), CodecError> { + self.report_id.encode(bytes)?; + self.time.encode(bytes)?; + Ok(()) } } @@ -307,7 +316,6 @@ pub struct Report { pub helper_encrypted_input_share: HpkeCiphertext, } - impl Report { /// Creates a minimal report for use in tests. pub fn new_dummy() -> Self { @@ -321,8 +329,16 @@ impl Report { time: Time::generate(1), }, public_share: vec![], - leader_encrypted_input_share: HpkeCiphertext { config_id: HpkeConfigId(5), enc: vec![1, 2, 3, 4, 5], payload: vec![6, 7, 8, 9, 10] }, - helper_encrypted_input_share: HpkeCiphertext { config_id: HpkeConfigId(100), enc: enc.into(), payload: payload.into() }, + leader_encrypted_input_share: HpkeCiphertext { + config_id: HpkeConfigId(5), + enc: vec![1, 2, 3, 4, 5], + payload: vec![6, 7, 8, 9, 10], + }, + helper_encrypted_input_share: HpkeCiphertext { + config_id: HpkeConfigId(100), + enc: enc.into(), + payload: payload.into(), + }, } } } @@ -349,10 +365,11 @@ impl Decode for Report { } impl Encode for Report { - fn encode(&self, bytes: &mut Vec) { - self.metadata.encode(bytes); - encode_u32_items(bytes, &(), &self.public_share); - self.leader_encrypted_input_share.encode(bytes); - self.helper_encrypted_input_share.encode(bytes); + fn encode(&self, bytes: &mut Vec) -> Result<(), CodecError> { + self.metadata.encode(bytes)?; + encode_u32_items(bytes, &(), &self.public_share)?; + self.leader_encrypted_input_share.encode(bytes)?; + self.helper_encrypted_input_share.encode(bytes)?; + Ok(()) } } -- cgit v1.2.3