Skip to content

feat(native-rust): message-header structure (V1/V2 header, header auth)#909

Open
lucasmcdonald3 wants to merge 7 commits into
aws-crypto-rust/mainlinefrom
aws-crypto-rust/header-structure-review
Open

feat(native-rust): message-header structure (V1/V2 header, header auth)#909
lucasmcdonald3 wants to merge 7 commits into
aws-crypto-rust/mainlinefrom
aws-crypto-rust/header-structure-review

Conversation

@lucasmcdonald3
Copy link
Copy Markdown
Contributor

Implements the message header body itself — V1 and V2 header bodies, header authentication, header-level types, and shared header helpers — per message-header.md.

Scope:

  • esdk/src/message/mod.rs — shared machinery (DigestWriter, NoopWriter).
  • esdk/src/message/header.rs — top-level header wrapper.
  • esdk/src/message/header_types.rs — header-level types (version, algorithm suite id, content type, etc.).
  • esdk/src/message/header_auth.rs — header IV + auth tag.
  • esdk/src/message/v1_header_body.rs — V1 header body serialization/deserialization.
  • esdk/src/message/v2_header_body.rs — V2 header body serialization/deserialization.
  • esdk/src/message/shared_header_functions.rs — helpers shared between V1 and V2.
  • Tests: esdk/tests/test_header_structure.rs, esdk/tests/test_header_types.rs, esdk/tests/test_header_auth.rs, esdk/tests/test_v1_header_body.rs, esdk/tests/test_v2_header_body.rs.

The reusable sub-structures the header embeds (encrypted data keys, encryption context, low-level serialize helpers) are reviewed separately in #901. data-format/message.md citations are absorbed into this PR since they mostly live alongside the header machinery and have no dedicated implementation file.


Note: CI does not run on this PR. This branch is scoped for focused review and intentionally omits test helpers, scaffolding, and other supporting code. Full code — including helpers, test infrastructure, and working tests — lives on the aws-crypto-rust/unreviewed branch.

If you want more context or to actually run the tests, see aws-crypto-rust/unreviewed.

Related spec: data-format/message-header.md

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Implements core Rust-side serialization/deserialization for AWS Encryption SDK message headers, focusing on V1/V2 header bodies, header authentication, and associated field types as defined in the message-header spec.

Changes:

  • Adds V1/V2 header body read/write implementations and shared header field types (version/type/content type, suite ID, message ID).
  • Adds header authentication (V1 IV+tag, V2 tag-only) read/write.
  • Introduces a suite of spec-assertion tests for header structure, header types, header auth, and V1/V2 header body layouts.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
esdk/src/message/mod.rs Introduces the message module layout plus helper writers (NoopWriter, DigestWriter).
esdk/src/message/header.rs Top-level header read/write orchestration and validation helpers.
esdk/src/message/header_types.rs Defines header field enums/structs and shared read/write helpers (version/type/content type, suite ID, message ID).
esdk/src/message/header_auth.rs Implements header authentication tag serialization/deserialization for V1 and V2.
esdk/src/message/v1_header_body.rs Implements V1 header body serialization/deserialization (reserved bytes, IV length, frame length, etc.).
esdk/src/message/v2_header_body.rs Implements V2 header body serialization/deserialization (commitment/suite data handling, etc.).
esdk/tests/test_header_structure.rs Adds structure-level tests (endianness, ordering, EDK count constraints, frame length constraints).
esdk/tests/test_header_types.rs Adds tests for version/type/content-type parsing and negative cases (including Base64-like input).
esdk/tests/test_header_auth.rs Adds tests for V1/V2 header auth layout and tamper detection.
esdk/tests/test_v1_header_body.rs Adds detailed V1 header body layout/field-size/order and negative-tamper tests.
esdk/tests/test_v2_header_body.rs Adds detailed V2 header body layout/field-size/order tests.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread esdk/src/message/mod.rs
Comment thread esdk/src/message/mod.rs
Comment thread esdk/src/message/header.rs Outdated
Comment on lines +197 to +218
let mut header_buf = Vec::new();

//= spec/data-format/message-header.md#structure
//# The header MUST consist of, in order,
//# Header Body,
//# and Header Authentication.

// Header Body

serialize_functions::write_bytes(&mut header_buf, &header.raw_header)?;

// Header Authentication

header_auth::write_header_auth_tag(&mut header_buf, &header.header_auth, &header.suite)?;
serialize_functions::write_bytes(ciphertext, &header_buf)?;

//= spec/client-apis/encrypt.md#authentication-tag
//# If the algorithm suite contains a signature algorithm and
//# this operation is [streaming](streaming.md) the encrypted message output to the caller,
//# this operation MUST input the serialized header to the signature algorithm as soon as it is serialized,
//# such that the serialized header isn't required to remain in memory to [construct the signature](#construct-the-signature).
serialize_functions::write_bytes(sig_digest, &header_buf)?;
Comment thread esdk/tests/test_header_auth.rs
Comment thread esdk/tests/test_header_structure.rs
Comment thread esdk/tests/test_header_types.rs
Comment thread esdk/tests/test_v1_header_body.rs
Comment thread esdk/tests/test_v2_header_body.rs
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