;; Copyright (C) 1999 Shuhei KOBAYASHI
;; Author: Shuhei KOBAYASHI <shuhei@aqua.ocn.ne.jp>
+;; Kenichi OKADA <okada@opaopa.org>
+;; Maintainer: Kenichi OKADA <okada@opaopa.org>
;; Keywords: SHA1, FIPS 180-1
;; This file is part of FLIM (Faithful Library about Internet Message).
;;; Code:
+(require 'hex-util)
+
+(eval-when-compile
+ (or (fboundp 'sha1-string)
+ (defun sha1-string (a))))
+
+(defvar sha1-dl-module
+ (if (and (fboundp 'sha1-string)
+ (subrp (symbol-function 'sha1-string)))
+ nil
+ (if (fboundp 'dynamic-link)
+ (let ((path (expand-file-name "sha1.so" exec-directory)))
+ (and (file-exists-p path)
+ path)))))
+
(cond
- ((and (fboundp 'dynamic-link)
- (file-exists-p (expand-file-name "sha1.so" exec-directory)))
+ (sha1-dl-module
;; Emacs with DL patch.
- (require 'sha1 "sha1-dl"))
+ (require 'sha1-dl))
(t
- (require 'sha1 "sha1-el")
- (defun sha1 (object &optional beg end)
- "Return the SHA1 (Secure Hash Algorithm) of an object.
-OBJECT is either a string or a buffer.
-Optional arguments BEG and END denote buffer positions for computing the
-hash of a portion of OBJECT."
- (if (stringp object)
- (sha1-encode object)
- (save-excursion
- (set-buffer object)
- (sha1-encode
- (buffer-substring-no-properties
- (or beg (point-min)) (or end (point-max)))))))
- ))
-
-;;; sha1.el ends here.
+ (require 'sha1-el)))
+
+;; compatibility for another sha1.el by Keiichi Suzuki.
+(defun sha1-encode (string)
+ (decode-hex-string
+ (sha1-string string)))
+(defun sha1-encode-binary (string)
+ (decode-hex-string
+ (sha1-string string)))
+
+(make-obsolete 'sha1-encode "It's old API.")
+(make-obsolete 'sha1-encode-binary "It's old API.")
+
+(provide 'sha1)
+
+;;; sha1.el ends here