lib/rbnacl/util.rb
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
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
Check the length of the passed in string

 In several places through the codebase we have to be VERY strict with
 what length of string we accept.  This method supports that.

 @raise [RbNaCl::LengthError] If the string is not the right length

 @param string [String] The string to compare
 @param length [Integer] The desired length
 @param description [String] Description of the string (used in the error)