Module: ElFinder2::HashUtils

Included in:
Command::Base, Command::Size, File, FileSerializer
Defined in:
lib/el_finder2/hash_utils.rb

Instance Method Summary collapse

Instance Method Details

#from_base64url(hash) ⇒ Object



3
4
5
6
# File 'lib/el_finder2/hash_utils.rb', line 3

def from_base64url(hash)
  padding = ['', '', '==', '='][hash.length % 4] # ensure input is padded
  Base64.urlsafe_decode64(hash + padding)
end

#to_base64url(string) ⇒ Object



8
9
10
# File 'lib/el_finder2/hash_utils.rb', line 8

def to_base64url(string)
  Base64.urlsafe_encode64(string).tr("=\n", '')
end

#to_path(hash, default = nil) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/el_finder2/hash_utils.rb', line 12

def to_path(hash, default = nil)
  volume_id, target = hash.split('_')

  valid = volume_id == ElFinder2::VOLUME_ID && target

  valid && from_base64url(target) || default
rescue ArgumentError
  default
end