Module: CBOR_DIAG::B64string2

Defined in:
lib/cbor-diag-parser.rb

Instance Method Summary collapse

Instance Method Details

#to_rbObject



2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
# File 'lib/cbor-diag-parser.rb', line 2452

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