emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

md5


From: Simon Josefsson
Subject: md5
Date: 07 Oct 2000 22:58:12 +0200
User-agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7

Hi, I've written md5 support for emacs. I seek this groups advice on
multibyte issues of this function.

The complete patch (together with some test cases) is at
http://josefsson.org/emacs-md5.html, I'm including a slightly edited
version of the relevant part below.  The function is modeled after
XEmacs' API, and the function take a string or buffer as parameter.
Optionally, a coding system can also be passed to the function to make
it explicitly encode data into this coding system before calculating
md5.  If no coding system is passed, md5 should "guess" what coding
system to use.

Of course, the md5 calculation must be performed on encoded data to be
useful.

I'd appreciate suggestions on how to make the following code correct.
I'm sure it's broken as I didn't really understand what I was doing,
and that is just happen to work for ASCII and iso-8859-1.

  if (STRINGP(object))
    {
      if (NILP (coding_system))
        {
          /* we should guess coding system */
          if (STRING_MULTIBYTE (object))
            {
              /* we make a unibyte string and guess it's coding system
                 (is this correct?) */
              object = string_make_unibyte (object);
              coding_system = detect_coding_system 
                (XSTRING(object)->data, STRING_BYTES(XSTRING (object)), 1);
            }
          else
            {
              /* guess coding system */
              coding_system = detect_coding_system
                (XSTRING(object)->data, STRING_BYTES(XSTRING (object)), 1);
            }

          /* encode unibyte string into desired coding system 
             (yes encoding functions handle unibyte source) */
          object = code_convert_string1 (object, coding_system, Qnil, 1);
        }
      else
        {
          /* convert string into given coding system */
          if (STRING_MULTIBYTE (object))
            {
              /* just encode it */
              object = code_convert_string1 (object, coding_system, Qnil, 1);
            } else {
              /* assume string is encoded */
            }
        }

...
    }
  else /* if (BUFFERP (object)) */
    {
...

      if (NILP (coding_system))
        {
          /* we should guess coding system of buffer */
          coding_system = XBUFFER (object)->buffer_file_coding_system;
          if (NILP (coding_system))
            {
              /* xxx this can (and should) be handled. I do not know how. */
              Fsignal (Qerror, 
                       Fcons (build_string ("No coding system found"), Qnil));
            }
        }

      object = make_buffer_string (b, e, 0);

      if (STRING_MULTIBYTE (object))
        object = code_convert_string1 (object, coding_system, Qnil, 1);
    }

    /* now md5 is calculated on XSTRING(object)->data */




reply via email to

[Prev in Thread] Current Thread [Next in Thread]