Skip to content
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

Update Return type of JWT::urlsafeB64Decode #26

Open
smyhill opened this issue Jun 13, 2024 · 0 comments
Open

Update Return type of JWT::urlsafeB64Decode #26

smyhill opened this issue Jun 13, 2024 · 0 comments

Comments

@smyhill
Copy link

smyhill commented Jun 13, 2024

After debugging for a while in my personal implementation of this library I released it is possible for the following method to return false on failure as well as the decoded string. This can happen when the core PHP base64_decode method returns false on failure because this method is returned in the parent method. To fix possible confusion my suggestion would be to update the method to use a union type to avoid confusion in the future. I imagine this can occur because the class is not strictly typed.
Old:

/**
     * Decode a string with URL-safe Base64.
     *
     * @param string $input A Base64 encoded string
     *
     * @return string A decoded string
     *
     * @throws InvalidArgumentException invalid base64 characters
     */
    public static function urlsafeB64Decode(string $input): string
    {
        return \base64_decode(self::convertBase64UrlToBase64($input));
    }

New:

/**
     * Decode a string with URL-safe Base64.
     *
     * @param string $input A Base64 encoded string
     *
     * @return string|false A decoded string or false on failure
     *
     * @throws InvalidArgumentException invalid base64 characters
     */
    public static function urlsafeB64Decode(string $input): string|false
    {
        return \base64_decode(self::convertBase64UrlToBase64($input));
    }
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

No branches or pull requests

1 participant