module Sodium::Utils

Constants

HEXY
ZERO

Public Instance Methods

bin2hex(bytes) click to toggle source
# File lib/sodium/utils.rb, line 33
def bin2hex(bytes)
  String(bytes).unpack(HEXY).first
end
check_length(data, length, description) click to toggle source
# File lib/sodium/utils.rb, line 17
def check_length(data, length, description)
  if data.respond_to?(:bytesize)
    data.bytesize == length || fail(LengthError, "Expected a length=#{length} bytes #{description}, got bytesize=#{data.bytesize} bytes", caller)
  else
    data.size == length || fail(LengthError, "Expected a length=#{length} bytes #{description}, got size=#{data.size} bytes", caller)
  end
end
get_size(data) click to toggle source
# File lib/sodium/utils.rb, line 9
def get_size(data)
  if data.respond_to?(:bytesize)
    data.bytesize
  else
    data.size
  end
end
hex2bin(hex) click to toggle source
# File lib/sodium/utils.rb, line 37
def hex2bin(hex)
  [String(hex)].pack(HEXY)
end
zeros(n) click to toggle source
# File lib/sodium/utils.rb, line 27
def zeros(n)
  ZERO * n
end