Skip to content

Commit

Permalink
demo: Clean up serialization references
Browse files Browse the repository at this point in the history
- Serialization doesn't require mutable access.
- Use `.as_ref()` consistently to generate a `&[u8]` slice
  for deserialization. This works both with the `Bytes`
  type, where it's the simplest way to get a slice of the
  entire buffer span, and with plain `Vec` types, where
  some specific method is necessary since the arkworks
  `deserialize_canonical` function doesn't accept a
  simple `&Vec` reference.

I expect serialization/deserialization to use byte slices,
so I don't think the turbofish `::<&[u8]>` specification
is adding much.
  • Loading branch information
rillian committed Aug 14, 2024
1 parent a88b471 commit c360732
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
12 changes: 6 additions & 6 deletions demo/examples/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ lazy_static! {

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
// Create a Reqwest client
// Create a Reqwest HTTPS client
let client = Client::builder()
.https_only(true)
.danger_accept_invalid_certs(true) // Accept self-signed certificates
Expand All @@ -68,7 +68,7 @@ async fn main() -> Result<(), Box<dyn Error>> {

if http_response.status().is_success() {
let m2_bytes = http_response.bytes().await?;
let m2: IBSM = IBSM::deserialize_compressed(&mut m2_bytes.as_ref())
let m2: IBSM = IBSM::deserialize_compressed(m2_bytes.as_ref())
.expect("Failed to deserialize compressed Issuance M2");

let m3 = IBCM::generate_issuance_m3(m1.clone(), m2.clone(), &mut rng);
Expand All @@ -88,7 +88,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
println!("Successfully sent m3 to the server.");

let m4_bytes = m3_response.bytes().await?;
let _m4: IBSM = IBSM::deserialize_compressed::<&[u8]>(&m4_bytes)
let _m4: IBSM = IBSM::deserialize_compressed(m4_bytes.as_ref())
.expect("Failed to deserialize Issuance M4 from server");
println!("Successfully received m4 from the server.");
} else {
Expand All @@ -106,7 +106,7 @@ async fn main() -> Result<(), Box<dyn Error>> {

if https_response.status().is_success() {
let m2_bytes = https_response.bytes().await?;
let m2: IBSM = IBSM::deserialize_compressed(&mut m2_bytes.as_ref())
let m2: IBSM = IBSM::deserialize_compressed(m2_bytes.as_ref())
.expect("Failed to deserialize compressed Issuance M2");

let m3 = IBCM::generate_issuance_m3(m1.clone(), m2.clone(), &mut rng);
Expand All @@ -129,11 +129,11 @@ async fn main() -> Result<(), Box<dyn Error>> {
println!("Successfully sent m3 to the server.");

let m4_bytes = m3_response.bytes().await?;
let _m4: IBSM = IBSM::deserialize_compressed::<&[u8]>(&m4_bytes)
let _m4: IBSM = IBSM::deserialize_compressed(m4_bytes.as_ref())
.expect("Failed to deserialize Issuance M4 from server");
println!("Successfully received m4 from the server.");

let _m3: IBCM = IBCM::deserialize_compressed::<&[u8]>(m3_bytes_c.as_ref())
let _m3: IBCM = IBCM::deserialize_compressed(m3_bytes_c.as_ref())
.expect("Failed to deserialize compressed Issuance M2");

// FIXME: state generation fails acl signature
Expand Down
6 changes: 3 additions & 3 deletions demo/examples/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ async fn post_handler(body: Body) -> Result<Response, Infallible> {
match message.msg_type {
MessageType::M1 => {
println!("Received m1 message, processing...");
let m1: IBCM = IBCM::deserialize_compressed(&mut message.data.as_slice())
let m1: IBCM = IBCM::deserialize_compressed(message.data.as_ref())
.expect("Failed to deserialize compressed Issuance M1");

let m2 = IssuanceS::<Config>::generate_issuance_m2(m1, skp, &mut rng);
Expand All @@ -133,11 +133,11 @@ async fn post_handler(body: Body) -> Result<Response, Infallible> {
MessageType::M3 => {
println!("Received m3 message, processing...");

let m3: IBCM = IBCM::deserialize_compressed(&mut message.data.as_slice())
let m3: IBCM = IBCM::deserialize_compressed(message.data.as_ref())
.expect("Failed to deserialize compressed Issuance M3");

let m2_bytes_c = M2_BYTES_C.lock().unwrap();
let m2: IBSM = IBSM::deserialize_compressed::<&[u8]>(m2_bytes_c.as_ref())
let m2: IBSM = IBSM::deserialize_compressed(m2_bytes_c.as_ref())
.expect("Failed to deserialize compressed Issuance M2");

let m4 = IssuanceS::<Config>::generate_issuance_m4(m3.clone(), m2.clone(), skp);
Expand Down

0 comments on commit c360732

Please sign in to comment.