summaryrefslogtreecommitdiffstats
path: root/toolkit/components/telemetry/dap/ffi/src/types.rs
diff options
context:
space:
mode:
Diffstat (limited to 'toolkit/components/telemetry/dap/ffi/src/types.rs')
-rw-r--r--toolkit/components/telemetry/dap/ffi/src/types.rs83
1 files changed, 50 insertions, 33 deletions
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<u8>) {
+ fn encode(&self, bytes: &mut Vec<u8>) -> 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<u8>) {
- u64::encode(&self.0, bytes);
+ fn encode(&self, bytes: &mut Vec<u8>) -> 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<u8>) {
- (self.extension_type as u16).encode(bytes);
- encode_u16_items(bytes, &(), &self.extension_data);
+ fn encode(&self, bytes: &mut Vec<u8>) -> 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<u8>) {
- encode_u16_items(bytes, &(), &self.extensions);
- encode_u32_items(bytes, &(), &self.payload);
+ fn encode(&self, bytes: &mut Vec<u8>) -> 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<u8>) {
- self.0.encode(bytes);
+ fn encode(&self, bytes: &mut Vec<u8>) -> 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<u8>) {
- 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<u8>) -> 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<u8>) {
- self.config_id.encode(bytes);
- encode_u16_items(bytes, &(), &self.enc);
- encode_u32_items(bytes, &(), &self.payload);
+ fn encode(&self, bytes: &mut Vec<u8>) -> 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<u8>) {
+ fn encode(&self, bytes: &mut Vec<u8>) -> 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<u8>) {
- self.report_id.encode(bytes);
- self.time.encode(bytes);
+ fn encode(&self, bytes: &mut Vec<u8>) -> 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<u8>) {
- 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<u8>) -> 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(())
}
}