Module: SimplyAES::Format::Base64

Extended by:
Base64
Includes:
SimplyAES::Format
Included in:
Base64
Defined in:
lib/simply-aes/format.rb

Overview

A Base64 implementation of SimplyAES::Format that emits strings without newlines and can handle concatenated-b64 strings

Instance Method Summary collapse

Methods included from SimplyAES::Format

[], []=, included

Instance Method Details

#dump(bytestring) ⇒ Object



62
63
64
# File 'lib/simply-aes/format.rb', line 62

def dump(bytestring)
  ::Base64.encode64(bytestring).tr("\n", '')
end

#load(formatted) ⇒ Object



53
54
55
56
57
58
59
60
# File 'lib/simply-aes/format.rb', line 53

def load(formatted)
  # Because Base64 has 3:4 raw:formated ratio, it doesn't always break
  # cleanly on byte boundaries; add support for concatenated
  # iv+ciphertext encoded payloads
  formatted.scan(/[^=]+(?:=+|\Z)/m).map do |chunk|
    ::Base64.decode64(chunk)
  end.join
end