forked from php/php-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Add base32 decode base32 encode #1
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
nyamsprod
wants to merge
12
commits into
master
Choose a base branch
from
feature/add-base32_decode_base32_encode
base: master
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.
Draft
Changes from 4 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
01f37ea
Adding base32 test files
nyamsprod e340992
Adding base32 stub info
nyamsprod 7b5c4a7
Adding arginfo entry and base32 headers
nyamsprod ec7211a
Adding arginfo entry and base32 headers
nyamsprod cdb04bf
Improve test suite
nyamsprod fbc1083
Update base32 files and declaration
nyamsprod 3adc8b0
Update base32 files and declaration
nyamsprod 5ca79d9
Update base32 test suite
nyamsprod 61ab6aa
Adding base32_encode function to php-src
nyamsprod 4d249d6
Adding missing smart_str_free call
nyamsprod 14ba351
Adding base32_decode function skeleton
nyamsprod 1c447ed
Fix base32_decode parameters count
nyamsprod File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
|
|
||
| #ifndef BASE32_H | ||
| #define BASE32_H | ||
|
|
||
| extern const char *PHP_BASE32_ASCII = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"; | ||
| extern const char *PHP_BASE32_HEX = "0123456789ABCDEFGHIJKLMNOPQRSTUV"; | ||
| PHP_FUNCTION(base32_decode); | ||
| PHP_FUNCTION(base32_encode); | ||
|
|
||
| #endif | ||
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
168 changes: 168 additions & 0 deletions
168
ext/standard/tests/url/base32_decode_invalid_parameters_relax_001.phpt
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,168 @@ | ||
| --TEST-- | ||
| Test base32_decode() function : invalid parameters in relax mode | ||
| --FILE-- | ||
| <?php | ||
| echo "*** Testing base32_decode() : invalid parameters in relax mode***\n\n"; | ||
| $testData = [ | ||
| 'characters outside of base32 extended hex alphabet' => [ | ||
| 'sequence' => 'CPNMUOJ1E8Z======', | ||
| 'message' => 'The encoded string contains characters outside of the base32 alphabet.', | ||
| 'alphabet' => PHP_BASE32_HEX, | ||
| 'padding' => '=', | ||
| ], | ||
| 'characters outside of base32 us ascii alphabet' => [ | ||
| 'sequence' => '90890808', | ||
| 'message' => 'The encoded string contains characters outside of the base32 alphabet.', | ||
| 'alphabet' => PHP_BASE32_ASCII, | ||
| 'padding' => '=', | ||
| ], | ||
| 'characters not upper-cased' => [ | ||
| 'sequence' => 'MzxQ====', | ||
| 'message' => 'The encoded string contains lower-cased characters which is forbidden on strict mode.', | ||
| 'alphabet' => PHP_BASE32_ASCII, | ||
| 'padding' => '=', | ||
| ], | ||
| 'padding character in the middle of the sequence' => [ | ||
| 'sequence' => 'Mzx==Q====', | ||
| 'message' => 'A padding character is contained in the middle of the encoded string.', | ||
| 'alphabet' => PHP_BASE32_ASCII, | ||
| 'padding' => '=', | ||
| ], | ||
| 'invalid padding length' => [ | ||
| 'sequence' => 'MzxQ=======', | ||
| 'message' => 'The encoded string contains an invalid padding length.', | ||
| 'alphabet' => PHP_BASE32_ASCII, | ||
| 'padding' => '=', | ||
| ], | ||
| 'invalid encoded string length' => [ | ||
| 'sequence' => 'A', | ||
| 'message' => 'The encoded string length is not a multiple of 8.', | ||
| 'alphabet' => PHP_BASE32_ASCII, | ||
| 'padding' => '=', | ||
| ], | ||
| 'invalid alphabet length' => [ | ||
| 'sequence' => 'A', | ||
| 'message' => 'The alphabet must be a 32 bytes long string.', | ||
| 'alphabet' => '1234567890asdfghjklzxcvbnm', | ||
| 'padding' => '=', | ||
| ], | ||
| 'the padding character is contained within the alphabet' => [ | ||
| 'sequence' => 'A', | ||
| 'message' => 'The alphabet can not contain a reserved character.', | ||
| 'alphabet' => str_replace('A', '*', PHP_BASE32_ASCII), | ||
| 'padding' => '*', | ||
| ], | ||
| 'the padding character is contained within the alphabet is case insensitive' => [ | ||
| 'sequence' => 'A', | ||
| 'message' => 'The alphabet can not contain a reserved character.', | ||
| 'alphabet' => str_replace('A', '*', PHP_BASE32_ASCII), | ||
| 'padding' => 'a', | ||
| ], | ||
| 'the padding character is different than one byte' => [ | ||
| 'sequence' => 'A', | ||
| 'message' => 'The padding character must be a non reserved single byte character.', | ||
| 'alphabet' => PHP_BASE32_ASCII, | ||
| 'padding' => 'yo', | ||
| ], | ||
| 'the padding character can not contain "\r"' => [ | ||
| 'sequence' => 'A', | ||
| 'message' => 'The padding character must be a non reserved single byte character.', | ||
| 'alphabet' => PHP_BASE32_ASCII, | ||
| 'padding' => "\r", | ||
| ], | ||
| 'the padding character can not contain "\n"' => [ | ||
| 'sequence' => 'A', | ||
| 'message' => 'The padding character must be a non reserved single byte character.', | ||
| 'alphabet' => PHP_BASE32_ASCII, | ||
| 'padding' => "\n", | ||
| ], | ||
| 'the padding character can not contain "\t"' => [ | ||
| 'sequence' => 'A', | ||
| 'message' => 'The padding character must be a non reserved single byte character.', | ||
| 'alphabet' => PHP_BASE32_ASCII, | ||
| 'padding' => "\t", | ||
| ], | ||
| 'the alphabet can not contain "\r"' => [ | ||
| 'sequence' => 'A', | ||
| 'message' => 'The alphabet can not contain a reserved character.', | ||
| 'alphabet' => substr(PHP_BASE32_ASCII, 0, -1)."\r", | ||
| 'padding' => '=', | ||
| ], | ||
| 'the alphabet can not contain "\n"' => [ | ||
| 'sequence' => 'A', | ||
| 'message' => 'The alphabet can not contain a reserved character.', | ||
| 'alphabet' => substr(PHP_BASE32_HEX, 0, -1)."\n", | ||
| 'padding' => '=', | ||
| ], | ||
| 'the alphabet can not contain "\t"' => [ | ||
| 'sequence' => 'A', | ||
| 'message' => 'The alphabet can not contain a reserved character.', | ||
| 'alphabet' => substr(PHP_BASE32_HEX, 0, -1)."\t", | ||
| 'padding' => '=', | ||
| ], | ||
| ]; | ||
|
|
||
| foreach ($testData as $testTitle => $data) { | ||
| try { | ||
| echo "$testTitle\n"; | ||
| var_dump(base32_decode($data['sequence'], $data['alphabet'], $data['padding'], false)); | ||
| echo "===\n"; | ||
| } catch (ValueError $exception) { | ||
| echo "error message: ", $exception->getMessage(), "\n===\n"; | ||
| } | ||
| } | ||
| echo "\nDone\n"; | ||
| ?> | ||
| --EXPECT-- | ||
| *** Testing base32_decode() : invalid parameters in relax mode*** | ||
|
|
||
| characters outside of base32 extended hex alphabet | ||
| string(6) "foobar" | ||
| === | ||
| characters outside of base32 us ascii alphabet | ||
| string(0) "" | ||
| === | ||
| characters not upper-cased | ||
| string(2) "fo" | ||
| === | ||
| padding character in the middle of the sequence | ||
| string(2) "fo" | ||
| === | ||
| invalid padding length | ||
| string(2) "fo" | ||
| === | ||
| invalid encoded string length | ||
| string(0) "" | ||
| === | ||
| invalid alphabet length | ||
| error message: The alphabet must be a 32 bytes long string. | ||
| === | ||
| the padding character is contained within the alphabet | ||
| error message: The alphabet can not contain a reserved character. | ||
| === | ||
| the padding character is contained within the alphabet is case insensitive | ||
| string(0) "" | ||
| === | ||
| the padding character is different than one byte | ||
| error message: The padding character must be a non-reserved single byte character. | ||
| === | ||
| the padding character can not contain "\r" | ||
| error message: The padding character must be a non-reserved single byte character. | ||
| === | ||
| the padding character can not contain "\n" | ||
| error message: The padding character must be a non-reserved single byte character. | ||
| === | ||
| the padding character can not contain "\t" | ||
| error message: The padding character must be a non-reserved single byte character. | ||
| === | ||
| the alphabet can not contain "\r" | ||
| error message: The alphabet can not contain a reserved character. | ||
| === | ||
| the alphabet can not contain "\n" | ||
| error message: The alphabet can not contain a reserved character. | ||
| === | ||
| the alphabet can not contain "\t" | ||
| error message: The alphabet can not contain a reserved character. | ||
| === | ||
|
|
||
| Done |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.