Class: CBOR_DIAG::App_b64

Inherits:
Object
  • Object
show all
Defined in:
lib/cbor-diagnostic-app/b64.rb

Overview

mockup only; needs parser!

Class Method Summary collapse

Class Method Details

.decode(_, s) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/cbor-diagnostic-app/b64.rb', line 4

def self.decode(_, s)
  t = s.gsub(/\s/, '').chars.each_slice(4).map(&:join)
  if last = t[-1]
    last << "=" * (4 - last.size)
  end
  b = t.join.tr("-_", "+/")
  begin
    b.unpack("m0")[0]
  rescue ArgumentError
    raise ArgumentError, "cbor-diagnostic: invalid base64 #{b.inspect}", caller[1..-1]
  end
end