feat: add base16 cipher implementation #990
Merged
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.
Description
This PR adds an implementation of Base16 encoding (also known as hexadecimal encoding) to the ciphers module. Base16 is a binary-to-text encoding scheme that represents binary data using 16 ASCII characters (0-9 and A-F), following RFC 3548 Section 6 specifications.
Implementation Details
The implementation provides two public functions:
1.
base16_encode(data: &[u8]) -> Stringfold+write!pattern for optimal performance2.
base16_decode(data: &str) -> Result<Vec<u8>, String>Resultwith detailed error messages for invalid inputAlgorithm Details
0x48→"48")Result<Vec<u8>, String>for decodingRFC 3548 Compliance
This implementation strictly follows RFC 3548 Section 6, which specifies:
Changes Made
src/ciphers/base16.rswith complete implementationsrc/ciphers/mod.rsto include and export the new moduleType of Change
Testing
All tests pass successfully:
Test Coverage
b"Hello World!"→"48656C6C6F20576F726C6421""48656C6C6F20576F726C6421"→b"Hello World!"a-f)Examples
Code Quality
foldinstead ofmap + collectis_multiple_of()for clearer intentResulthandling with descriptive error messagesChecklist
cargo fmtcargo clippy