-
Notifications
You must be signed in to change notification settings - Fork 0
feat(rust/cbork-utils): deterministic cbor decoder #346
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
Draft
cong-or
wants to merge
16
commits into
main
Choose a base branch
from
feat-deterministic-cbor-decoder
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Adds validation for minimal length encoding of string types (Str and Bytes) in the DeterministicDecoder according to RFC 8949 Section 4.2. This ensures that string lengths are encoded using the minimal number of bytes required. For example, strings of length 0-23 must use direct encoding, length 24-255 must use one byte, etc. The changes: - Add length validation for Type::Str and Type::Bytes - Check for indefinite length strings - Validate minimal length encoding using check_minimal_length function
Adds comprehensive test coverage for RFC 8949 Section 4.2 deterministic encoding requirements. The new tests verify: - Minimal length integer encoding rules for values 0-23, 24-255, etc. - Floating point value requirements including shortest form and non-finite prohibition - String/array/map length encoding rules and indefinite length checks - Map key ordering rules with length-first canonical ordering Each test includes detailed comments explaining: - The specific RFC requirement being tested - Byte-level breakdown of CBOR encodings - Why each test case is valid or invalid - References to relevant RFC sections This ensures proper validation of all deterministic encoding rules and helps maintainers understand the requirements.
Add detailed test cases for deterministic CBOR encoding rules as specified in RFC 8949 section 4.2. The new tests cover: - Integer boundary conditions and minimal encoding requirements - Negative integer encoding across different ranges - Map key ordering (length-first, then lexicographic) - Floating point encoding with different precision requirements - String comparison ordering including UTF-8 handling - Nested structure validation - Array length encoding rules - Duplicate map key detection The tests are extensively documented with RFC requirements and include TODOs for future validation improvements, particularly for floating point handling where additional checks for non-finite values and minimal encoding could be added. Includes commented-out test cases that can be enabled once support for validating non-finite floating point values is implemented. RFC: https://datatracker.ietf.org/doc/html/rfc8949#section-4.2
Refactor test cases to fix clippy warnings: - Use simpler iterator chaining in array length test - Remove redundant calls - Replace explicit type annotations with inferred types - Fix collect() with redundant map operations Also simplify floating point test cases to match current implementation and improve RFC 8949 compliance documentation. The floating point tests now focus on valid encodings while keeping commented-out future test cases for non-finite values validation. Tests still verify the same RFC requirements but with more idiomatic Rust code.
Improve documentation and refactor validate_next() to align with RFC 8949 § 4.2 specification for deterministically encoded CBOR. Split validation logic into smaller, focused functions for better maintainability. - Split validate_next into specialized validation functions: * validate_integer() - Handles minimal integer encoding * validate_array() - Validates definite-length arrays * validate_string() - Checks string/bytes encoding * validate_map() - Ensures proper key ordering - Add comprehensive documentation referencing RFC 8949: * Detail core deterministic encoding requirements * Document rules for integer minimality * Explain length field constraints * Specify map key ordering rules * Include examples of valid/invalid encodings This refactoring improves code organization while maintaining full compliance with the CBOR deterministic encoding specification. The enhanced documentation helps developers understand both implementation details and RFC requirements.
Improve documentation and refactor validate_next() to align with RFC 8949 § 4.2 specification for deterministically encoded CBOR. Split validation logic into smaller, focused functions for better maintainability. - Split validate_next into specialized validation functions: * validate_integer() - Handles minimal integer encoding * validate_array() - Validates definite-length arrays * validate_string() - Checks string/bytes encoding * validate_map() - Ensures proper key ordering - Add comprehensive documentation referencing RFC 8949: * Detail core deterministic encoding requirements * Document rules for integer minimality * Explain length field constraints * Specify map key ordering rules * Include examples of valid/invalid encodings This refactoring improves code organization while maintaining full compliance with the CBOR deterministic encoding specification. The enhanced documentation helps developers understand both implementation details and RFC requirements.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
WIP
RFC 8949's Section 4.2 specification: deterministic CBOR encoding requirements:
🔸 Partial Implementation: