def check_string_validation(string)
      raise TypeError, "can't convert #{string.class} into String with #to_str" unless string.respond_to? :to_str

      string = string.to_str

      raise EncodingError, "strings must use BINARY encoding (got #{string.encoding})" if string.encoding != Encoding::BINARY
    end
def check_string_validation(string)
      raise TypeError, "can't convert #{string.class} into String with #to_str" unless string.respond_to? :to_str

      string = string.to_str

      raise EncodingError, "strings must use BINARY encoding (got #{string.encoding})" if string.encoding != Encoding::BINARY
    end
Check a passed string is it valid

 Raise an error if passed argument is invalid

 @raise [TypeError] If string cannot convert to a string with #to_str
 @raise [EncodingError] If string have wrong encoding

 @param string [#to_str] The input string