659856ca33f3810757a732b8e7b6ccd7ff690264
[elisp/flim.git] / md5-dl.el
1 ;;; md5-dl.el --- MD5 Message Digest Algorithm using DL module.
2
3 ;; Copyright (C) 1999 Shuhei KOBAYASHI
4
5 ;; Author: Shuhei KOBAYASHI <shuhei@aqua.ocn.ne.jp>
6 ;; Keywords: MD5, RFC 1321
7
8 ;; This program is free software; you can redistribute it and/or
9 ;; modify it under the terms of the GNU General Public License as
10 ;; published by the Free Software Foundation; either version 2, or
11 ;; (at your option) any later version.
12
13 ;; This program is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 ;; GNU General Public License for more details.
17
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with this program; see the file COPYING.  If not, write to
20 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 ;; Boston, MA 02111-1307, USA.
22
23 ;;; Commentary:
24
25 ;;; Code:
26
27 (defvar md5-dl-module
28   (if (and (fboundp 'md5-string)
29            (subrp (symbol-function 'md5-string)))
30       nil
31     (if (fboundp 'dynamic-link)
32         (let ((path (expand-file-name "md5.so" exec-directory)))
33           (and (file-exists-p path)
34                path)))))
35
36 (defvar md5-dl-handle
37   (and (stringp md5-dl-module)
38        (file-exists-p md5-dl-module)
39        (dynamic-link md5-dl-module)))
40
41 ;;; md5-dl-module provides `md5-string'.
42 (dynamic-call "emacs_md5_init" md5-dl-handle)
43
44 (defun md5-region (beg end)
45   (interactive "r")
46   (md5-string (buffer-substring-no-properties beg end)))
47
48 ;;; Note that XEmacs built-in version takes two more args: CODING and NOERROR.
49 ;;;###autoload
50 (defun md5 (object &optional beg end)
51   "Return the MD5 (a secure message digest algorithm) of an object.
52 OBJECT is either a string or a buffer.
53 Optional arguments BEG and END denote buffer positions for computing the
54 hash of a portion of OBJECT."
55   (if (stringp object)
56       (md5-string object)
57     (save-excursion
58       (set-buffer object)
59       (md5-region (or beg (point-min)) (or end (point-max))))))
60
61 (provide 'md5-dl)
62 (provide 'md5)
63
64 ;;; md5-dl.el ends here.