Skip to content

Commit

Permalink
Merge pull request #8 from baloo/baloo/extension-serialization
Browse files Browse the repository at this point in the history
extension: fixup ExtensionContents serialization
  • Loading branch information
wiktor-k authored Feb 5, 2024
2 parents 4ca0f43 + af88afb commit 5e3bd63
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/proto/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ pub use self::signature::*;

use serde::{Deserialize, Serialize};

pub type MpInt = Vec<u8>;

pub trait Blob: Sized {
fn to_blob(&self) -> ProtoResult<Vec<u8>>;
fn from_blob(blob: &[u8]) -> ProtoResult<Self>;
Expand Down
3 changes: 1 addition & 2 deletions src/proto/private_key.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use super::error::ProtoError;
use super::key_type::{KeyType, KeyTypeEnum};
use super::MpInt;
use serde::de::{Deserializer, Error};
use serde::ser::{SerializeTuple, Serializer};
use serde::{Deserialize, Serialize};

pub type MpInt = Vec<u8>;

#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
pub struct DssPrivateKey {
pub p: MpInt,
Expand Down
3 changes: 1 addition & 2 deletions src/proto/public_key.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use super::error::ProtoError;
use super::key_type::{KeyType, KeyTypeEnum};
use super::private_key::*;
use super::MpInt;
use serde::de::{Deserializer, Error};
use serde::ser::{SerializeTuple, Serializer};
use serde::{Deserialize, Serialize};

pub type MpInt = Vec<u8>;

#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
pub struct RsaPublicKey {
pub e: MpInt,
Expand Down
2 changes: 1 addition & 1 deletion src/proto/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ impl<'a, W: io::Write> ser::Serializer for &'a mut Serializer<W> {
}

fn serialize_str(self, v: &str) -> ProtoResult<()> {
(v.len() as u32).serialize(&mut *self)?;
self.serialize_bytes(v.as_bytes())
}

fn serialize_bytes(self, v: &[u8]) -> ProtoResult<()> {
(v.len() as u32).serialize(&mut *self)?;
self.writer.write_all(v).map_err(Into::into)
}

Expand Down
2 changes: 2 additions & 0 deletions src/proto/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,6 @@ fn test_extension() {
];
let extension: Extension = from_bytes(extension_bytes).unwrap();
assert_eq!(extension.extension_type, "[email protected]");
let out = to_bytes(&extension).unwrap();
assert_eq!(extension_bytes, out);
}

0 comments on commit 5e3bd63

Please sign in to comment.