class Ciphr::Functions::Base::Base64
Public Class Methods
aligned()
click to toggle source
# File lib/ciphr/functions/base_radix.rb, line 120 def self.aligned nil # preserves alignment end
params()
click to toggle source
# File lib/ciphr/functions/base_radix.rb, line 150 def self.params [:input] end
variants()
click to toggle source
# File lib/ciphr/functions/base_radix.rb, line 140 def self.variants chars = {"+"=>"p", "-"=>"h", "_"=>"u", ":"=>"c", "/"=>"s", "." => "d", "!"=>"x", "="=>"q"} types = {"+/=" => ["std"], "+/" => "utf7", "+-" => "file", "-_" => "url", "._-" => "yui", ".-" => "xml-name", "_:" => "xml-id", "_-" => "prog-id-1", "._" => "prog-id-2", "!-" => "regex"} variants = types.map{|c,n| [["b64","base64"].product([c.chars.map{|c| chars[c] }.join,n]).map{|a| a.join("-")}, {:chars => c}]} std = variants.select{|v| v[0].include? "b64-std"}[0] #add short aliases for standard std[0] = ["b64","base64"].concat(std[0]) variants end
Public Instance Methods
apply()
click to toggle source
# File lib/ciphr/functions/base_radix.rb, line 124 def apply input = @args[0] if !invert Proc.new do chunk = input.read(3) chunk && ::Base64.encode64(chunk).gsub(/\s/,'').tr("+/", options[:chars][0,2]).tr("=", options[:chars][2,3]) end else Proc.new do chunk = input.read(4) chunk = chunk && chunk + "="*(4-chunk.size) #pad chunk && ::Base64.decode64(chunk.tr(options[:chars][0,2],"+/").tr(options[:chars][2,3],"=").ljust(4,"=")) end end end