+2003-12-16 Simon Josefsson <jas@extundo.com>
+
+ * sha1-el.el (autoload): Don't use ignore-errors.
+ (sha1-use-external): Use condition-case. Suggested by Katsumi
+ Yamaoka <yamaoka@jpl.org>.
+
+2003-12-15 Simon Josefsson <jas@extundo.com>
+
+ * sha1-el.el (autoload): Ignore errors for
+ executable-find. (XEmacs ecrypto does not require sh-script where
+ executable.el is located.)
+ (sha1-use-external): Likewise.
+
+ * sha1-el.el (sha1): Add defgroup.
+ (sha1-maximum-internal-length, sha1-program, sha1-use-external)
+ (sha1-program): Use 'sha1sum' from GNU CoreUtils instead of OpenSSL.
+ (sha1): Autoload.
+
+2001-12-29 ShengHuo ZHU <zsh@cs.rochester.edu>
+
+ * sha1-el.el (sha1-use-external): New variable.
+ (sha1-region): Use it.
+ (sha1-string): Ditto.
+
2004-01-05 Katsumi Yamaoka <yamaoka@jpl.org>
* ntlm.el (ntlm-string-as-unibyte): New macro.
;;; sha1-el.el --- SHA1 Secure Hash Algorithm in Emacs-Lisp.
-;; Copyright (C) 1999, 2001 Free Software Foundation, Inc.
+;; Copyright (C) 1999, 2001, 2003 Free Software Foundation, Inc.
;; Author: Shuhei KOBAYASHI <shuhei@aqua.ocn.ne.jp>
;; Keywords: SHA1, FIPS 180-1
(require 'hex-util)
+(autoload 'executable-find "executable")
+
;;;
;;; external SHA1 function.
;;;
-(defvar sha1-maximum-internal-length 500
+(defgroup sha1 nil
+ "Elisp interface for SHA1 hash computation."
+ :group 'extensions)
+
+(defcustom sha1-maximum-internal-length 500
"*Maximum length of message to use lisp version of SHA1 function.
If message is longer than this, `sha1-program' is used instead.
If this variable is set to 0, use extarnal program only.
-If this variable is set to nil, use internal function only.")
+If this variable is set to nil, use internal function only."
+ :type 'integer
+ :group 'sha1)
-(defvar sha1-program '("openssl" "sha1")
+(defcustom sha1-program '("sha1sum")
"*Name of program to compute SHA1.
-It must be a string \(program name\) or list of strings \(name and its args\).")
+It must be a string \(program name\) or list of strings \(name and its args\)."
+ :type '(repeat string)
+ :group 'sha1)
+
+(defcustom sha1-use-external (condition-case ()
+ (executable-find (car sha1-program))
+ (error))
+ "*Use external SHA1 program.
+If this variable is set to nil, use internal function only."
+ :type 'boolean
+ :group 'sha1)
(defun sha1-string-external (string)
;; `with-temp-buffer' is new in v20, so we do not use it.
;;;
(defun sha1-region (beg end)
- (if (and sha1-maximum-internal-length
+ (if (and sha1-use-external
+ sha1-maximum-internal-length
(> (abs (- end beg)) sha1-maximum-internal-length))
(sha1-region-external beg end)
(sha1-region-internal beg end)))
(defun sha1-string (string)
- (if (and sha1-maximum-internal-length
+ (if (and sha1-use-external
+ sha1-maximum-internal-length
(> (length string) sha1-maximum-internal-length))
(sha1-string-external string)
(sha1-string-internal string)))
+;;;###autoload
(defun sha1 (object &optional beg end)
"Return the SHA1 (Secure Hash Algorithm) of an object.
OBJECT is either a string or a buffer.