Update FSF's address in GPL notices.
[elisp/flim.git] / sha1-dl.el
1 ;;; sha1-dl.el --- SHA1 Secure Hash Algorithm using DL module.
2
3 ;; Copyright (C) 1999, 2001, 2004  Free Software Foundation, Inc.
4
5 ;; Author: Shuhei KOBAYASHI <shuhei@aqua.ocn.ne.jp>
6 ;; Keywords: SHA1, FIPS 180-1
7
8 ;; This file is part of FLIM (Faithful Library about Internet Message).
9
10 ;; This program is free software; you can redistribute it and/or
11 ;; modify it under the terms of the GNU General Public License as
12 ;; published by the Free Software Foundation; either version 2, or
13 ;; (at your option) any later version.
14
15 ;; This program is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with this program; see the file COPYING.  If not, write to
22 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 ;; Boston, MA 02110-1301, USA.
24
25 ;;; Commentary:
26
27 ;;; Code:
28
29 (provide 'sha1-dl)                      ; beware of circular dependency.
30 (eval-when-compile (require 'sha1))     ; sha1-dl-module.
31
32 ;;; This file is loaded (from "sha1.el") only when sha1-dl-module exists.
33 (defvar sha1-dl-handle (dynamic-link sha1-dl-module))
34
35 ;;; sha1-dl-module provides `sha1-string' and `sha1-binary'.
36 (dynamic-call "emacs_sha1_init" sha1-dl-handle)
37
38 (defun sha1-region (beg end &optional binary)
39   (if binary
40       (sha1-binary (buffer-substring-no-properties beg end))
41     (sha1-string (buffer-substring-no-properties beg end))))
42
43 (defun sha1 (object &optional beg end binary)
44   "Return the SHA1 (Secure Hash Algorithm) of an object.
45 OBJECT is either a string or a buffer.
46 Optional arguments BEG and END denote buffer positions for computing the
47 hash of a portion of OBJECT.
48 If BINARY is non-nil, return a string in binary form."
49   (if (stringp object)
50       (if binary
51           (sha1-binary object)
52         (sha1-string object))
53     (save-excursion
54       (set-buffer object)
55       (sha1-region (or beg (point-min)) (or end (point-max)) binary))))
56
57 ;;; sha1-dl.el ends here