module RbNaCl::Util
def check_length(string, length, description)
-
description
(String
) -- Description of the string (used in the error) -
length
(Integer
) -- The desired length -
string
(String
) -- The string to compare
Raises:
-
(RbNaCl::LengthError)
- If the string is not the right length
def check_length(string, length, description) if string.nil? # code below is runs only in test cases # nil can't be converted to str with #to_str method raise LengthError, "#{description} was nil (Expected #{length.to_int})", caller end if string.bytesize != length.to_int raise LengthError, "#{description} was #{string.bytesize} bytes (Expected #{length.to_int})", caller end true end