Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pb-rust: Serde via prost + pbjson #95

Closed
wants to merge 4 commits into from

Conversation

jleightcap
Copy link
Contributor

Summary

sigstore-rs requires the serialization of compiled strcutures/enums, currently via Serde.

  • protoc_rust types do not implement Serialize/Deserialize. protoc_rust provides JSON support via internal reflection, however this approach is incompatible with existing sigstore-rs Serde derives, and proved incomplete with google.api (specifically google.api.field_behavior).
  • prost is an alternative builder to compile from .proto. It has JSON serialization support via Serde.
  • pb-json provides Serde derives for google.api.

Release Note

Documentation

@jleightcap jleightcap force-pushed the jl/pb-rust-protobuf branch 2 times, most recently from bdb34ca to 1af18d6 Compare July 19, 2023 18:39
@jleightcap
Copy link
Contributor Author

Encoding HashOutput (uses only primitive types),

use sigstore_protobuf_specs::dev::sigstore::common::v1::HashOutput;

fn main() {
    let ho = HashOutput { algorithm: 0i32, digest: vec![1u8] };
    let serialized = serde_json::to_string(&ho).unwrap();
    println!("{}", serialized);
}

Serializes,

$ cargo run
{"algorithm":0,"digest":[1]}

Signed-off-by: Jack Leightcap <jack.leightcap@trailofbits.com>
@jleightcap
Copy link
Contributor Author

jleightcap commented Jul 19, 2023

Adding some tests. Done, similar to above but for the structures defined here.

Signed-off-by: Jack Leightcap <jack.leightcap@trailofbits.com>
Signed-off-by: Jack Leightcap <jack.leightcap@trailofbits.com>
@jleightcap jleightcap marked this pull request as draft July 20, 2023 14:20
@jleightcap
Copy link
Contributor Author

Converting to draft, as Prost seems to have assumptions leading to miscellaneous serialization issues for protobuf.

Signed-off-by: Jack Leightcap <jack.leightcap@trailofbits.com>
@jleightcap
Copy link
Contributor Author

Summarizing issues with protobuf compilation/serialization:

  • compilation from protobuf source into rust structures is well-handled by both protoc_rust andprost.
  • both have some level of support for serialization;
    • protoc_rust < 3.0 leverages serde by specifying #[derive(...)] per-compilation struct/enum.
    • Similarly with prost.
    • protoc_rust >= 3.0 (betas) move to an internal reflection library that seems to be more adept, but is mutually incompatible with serde and seems to be incomplete when used with the well-known types.
  • a second approach of not manual specification of Serialize/Deserialize traits within this local crate
    • solves problems like field naming, different serializations of primitive types (u32 as number literal, u64 as string literal)
    • but is again incomplete when dealing with the well-known types and would require explicit dependencies on e.g. crono for Timestamp.
    • because this is external to the codegen, impl Serialize for, per defined protobuf structure, is (using SLOC as a metric) about equal in effort to manual definitions.

@jleightcap
Copy link
Contributor Author

Superseded by #118

@jleightcap jleightcap closed this Aug 2, 2023
@jleightcap jleightcap deleted the jl/pb-rust-protobuf branch August 2, 2023 14:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants