luciferous/jwt

Update Return type of JWT::urlsafeB64Decode

Opened this issue · 0 comments

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));
    }