Class: JWT::Base64 Private
- Inherits:
-
Object
- Object
- JWT::Base64
- Defined in:
- lib/jwt/base64.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Base64 encoding and decoding
Class Method Summary collapse
- .loose_urlsafe_decode64(str) ⇒ Object private
-
.url_decode(str) ⇒ Object
private
Decode a string with URL-safe Base64 complying with RFC 4648.
-
.url_encode(str) ⇒ Object
private
Encode a string with URL-safe Base64 complying with RFC 4648 (not padded).
Class Method Details
.loose_urlsafe_decode64(str) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
30 31 32 33 |
# File 'lib/jwt/base64.rb', line 30 def loose_urlsafe_decode64(str) str += '=' * (4 - str.length.modulo(4)) ::Base64.decode64(str.tr('-_', '+/')) end |
.url_decode(str) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Decode a string with URL-safe Base64 complying with RFC 4648. Deprecated support for RFC 2045 remains for now. (“All line breaks or other characters not found in Table 1 must be ignored by decoding software”)
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/jwt/base64.rb', line 19 def url_decode(str) ::Base64.urlsafe_decode64(str) rescue ArgumentError => e raise unless e. == 'invalid base64' raise Base64DecodeError, 'Invalid base64 encoding' if JWT.configuration.strict_base64_decoding loose_urlsafe_decode64(str).tap do Deprecations.warning('Invalid base64 input detected, could be because of invalid padding, trailing whitespaces or newline chars. Graceful handling of invalid input will be dropped in the next major version of ruby-jwt', only_if_valid: true) end end |
.url_encode(str) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Encode a string with URL-safe Base64 complying with RFC 4648 (not padded).
12 13 14 |
# File 'lib/jwt/base64.rb', line 12 def url_encode(str) ::Base64.urlsafe_encode64(str, padding: false) end |