aboutsummaryrefslogtreecommitdiff
path: root/core/encoding/base32/base32.odin
Commit message (Collapse)AuthorAgeFilesLines
* encoding/base32: Fix padding validation for malformed inputZoltán Kéri2025-12-271-7/+7
| | | | | | | | | | | Fix a bug where padding characters in the middle of input were not detected when there was no trailing padding. The "verify no padding in middle" check was inside `if padding_count > 0`, so inputs like "MZ===YTBMZXW6YTB" would incorrectly pass validation. Test case added for this edge case.
* Link doc lines to source specifications.Jeroen van Rijn2025-10-101-3/+1
|
* Render examples.Jeroen van Rijn2025-10-101-15/+15
|
* Further overhaul of package line comments.Jeroen van Rijn2025-10-091-0/+1
|
* Package lines for base32, move its tests to tests"Jeroen van Rijn2025-10-091-1/+3
|
* Fix stray space vs. tabJeroen van Rijn2025-01-121-4/+4
|
* encoding/base32: Add `@(rodata)` attribute to default tablesZoltán Kéri2025-01-031-0/+2
| | | | | | | Add `@(rodata)` attribute to `ENC_TABLE` and `DEC_TABLE` to mark them as read-only data. This places these tables in the read-only section of the executable, protecting them from modification during program execution.
* encoding/base32: Fix RFC 4648 references and add RFC reference URLZoltán Kéri2024-12-311-1/+6
| | | | | | | | | | | | | Fix incorrect RFC 4648 section references: - Add RFC URL reference at package level - Update Error enum documentation to reference correct sections: - Invalid_Character: Section 3.3 (non-alphabet characters) - Invalid_Length: Section 6 (base32 block size requirements) - Malformed_Input: Section 3.2 (padding) - Fix test file section references to match correct sections This ensures all RFC references are accurate and adds a link to the source RFC for reference.
* encoding/base32: Fix style issues for CIZoltán Kéri2024-12-311-5/+4
|
* encoding/base32: Convert files to UTF-8 with Unix line endingsZoltán Kéri2024-12-301-223/+224
|
* encoding/base32: Remove incorrect defer delete in encode()Zoltán Kéri2024-12-301-1/+0
| | | | | | | | Remove premature deallocation of the output buffer which was causing use-after-free behavior. The returned string needs to take ownership of this memory, but the defer delete was freeing it before the string could be used. This fixes issues with encoding that were introduced by overly aggressive memory cleanup in 93238db2.
* encoding/base32: Move tests to base32_test.odinZoltán Kéri2024-12-291-126/+0
| | | | | Move existing test procedures to a dedicated test file for better code organization and maintainability.
* encoding/base32: Expand `DEC_TABLE` to full 256 bytesZoltán Kéri2024-12-261-13/+15
| | | | | | The decoding table was only 224 bytes which caused type mismatches when using custom alphabets, so expand with zeroes to cover full byte range while maintaining the same decoding logic.
* encoding/base32: Use `ENC_TBL` parameter consistently in encode()Zoltán Kéri2024-12-261-9/+9
| | | | | | | Fix encoding to properly use provided encoding table parameter instead of hardcoded `ENC_TABLE`. This makes encode properly support custom alphabets as documented.
* encoding/base32: Add custom validation supportZoltán Kéri2024-12-251-5/+16
| | | | | | | | Add support for custom alphabet validation through an optional validation function parameter. The default validation follows RFC 4648 base32 alphabet rules (A-Z, 2-7). This properly supports the documented ability to use custom alphabets.
* encoding/base32: Replace padding map with switch statementZoltán Kéri2024-12-241-9/+11
| | | | | | Replace package-level map with a simple switch statement for padding validation. This eliminates allocations we can't properly free while maintaining the same validation logic.
* encoding/base32: Set optimization mode for decode()Zoltán Kéri2024-12-241-0/+1
|
* encoding/base32: Use consistent allocator and add proper cleanupZoltán Kéri2024-12-241-22/+43
| | | | | | | | | | | | Fix memory handling throughout base32 package: - Make padding map package-level constant (to avoid repeated allocs) - Use passed allocator in encode's make() call - Add defer delete for allocated memory in encode - Add proper cleanup in test cases - Fix memory cleanup of output buffers The changes ensure consistent allocator usage and cleanup in both implementation and tests.
* encoding/base32: Fix decode implementation per RFC 4648Zoltán Kéri2024-12-241-58/+79
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Rework base32.decode() to properly handle all cases per RFC 4648: - Fix error detection order: - Check minimum length first (Invalid_Length) - Check character validity (Invalid_Character) - Check padding and structure (Malformed_Input) - Fix padding validation: - Add required padding length checks (2=6, 4=4, 5=3, 7=1 chars) - Ensure padding only appears at end - Fix handling of unpadded inputs - Fix buffer handling: - Proper output buffer size calculation - Add bounds checking for buffer access - Add proper buffer validation For example: - "M" correctly returns Invalid_Length (too short) - "mzxq====" correctly returns Invalid_Character (lowercase) - "MZXQ=" correctly returns Malformed_Input (wrong padding) - Unpadded input lengths must be multiples of 8 These changes make the decode function fully compliant with RFC 4648 requirements while providing proper error handling.
* encoding/base32: Add RFC 4648 test suiteZoltán Kéri2024-12-241-0/+104
| | | | | | | | | | | | | | | Add test suite based on RFC 4648 test vectors and validation rules: - Add section 10 test vectors for valid encoding/decoding - Add test cases for invalid character handling (section 3.2) - Add test cases for padding validation (section 4) - Add test cases for length requirements (section 6) The test vectors verify that: - Empty string encodes/decodes correctly - Standard cases like "foo" -> "MZXW6===" work - Invalid characters are rejected - Missing or malformed padding is detected - Invalid lengths are caught
* encoding/base32: Fix buffer allocation and bounds checkingZoltán Kéri2024-12-241-6/+24
| | | | | | | | | | | Fix buffer allocation size calculation and add proper bounds checking to ensure output buffer has sufficient space. This fixes crashes that could occur with inputs like "AA" and other edge cases where the output buffer was too small. Remove #no_bounds_check as proper bounds checking is necessary for safe error handling. The small performance trade-off is worth the improved robustness.
* encoding/base32: Replace assertions with error returnsZoltán Kéri2024-12-241-9/+31
| | | | | | | Replace assertions with proper error handling in base32.decode() to allow programs to handle invalid input gracefully rather than crashing. The function now returns ([]byte, Error) instead of just []byte.
* Indentation fixesgingerBill2024-06-291-116/+116
|
* Update numerous package declaration namesgingerBill2024-04-181-1/+1
|
* Remove unneeded semicolons from the core librarygingerBill2021-08-311-65/+65
|
* Make base32 and base64 adhere to `-strict-style`gingerBill2021-03-141-2/+2
|
* vet all core packagesgingerBill2021-01-091-1/+0
|
* Remove usage of `do` in core librarygingerBill2020-09-231-2/+6
|
* Add extra information to `-show-more-timings`gingerBill2020-05-211-12/+12
|
* Missed onezhibog2019-11-091-1/+1
|
* Fixed indentingzhibog2019-11-091-44/+44
|
* Removed comments regarding RFC test vectorszhibog2019-11-081-36/+1
|
* Added Base32 + official test vectors from the RFCzhibog2019-11-011-0/+180