File: base64.rb

package info (click to toggle)
ruby-jwt 2.7.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 736 kB
  • sloc: ruby: 4,326; makefile: 4
file content (19 lines) | stat: -rw-r--r-- 361 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# frozen_string_literal: true

require 'base64'

module JWT
  # Base64 helpers
  class Base64
    class << self
      def url_encode(str)
        ::Base64.encode64(str).tr('+/', '-_').gsub(/[\n=]/, '')
      end

      def url_decode(str)
        str += '=' * (4 - str.length.modulo(4))
        ::Base64.decode64(str.tr('-_', '+/'))
      end
    end
  end
end