[PATCH] Fixes to sha1-el.el
Simon Josefsson
jas at extundo.com
Tue Jan 6 23:16:31 JST 2004
Here are some fixes made in Gnus CVS to sha1-el.el. What do you
think? I'm not sure if you also dislike OpenSSL, but perhaps
'sha1sum' is more portable, and thus might be installed in more
places. Any suggestions appreciated.
2003-12-16 Simon Josefsson <jas at extundo.com>
* sha1-el.el (autoload): Don't use ignore-errors.
(sha1-use-external): Use condition-case. Suggested by Katsumi
Yamaoka <yamaoka at jpl.org>.
2003-12-15 Simon Josefsson <jas at 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 at cs.rochester.edu>
* sha1-el.el (sha1-use-external): New variable.
(sha1-region): Use it.
(sha1-string): Ditto.
Index: sha1-el.el
===================================================================
RCS file: /cvs/root/flim/Attic/sha1-el.el,v
retrieving revision 1.1.6.2
diff -u -p -u -w -r1.1.6.2 sha1-el.el
--- sha1-el.el 11 Mar 2001 10:10:53 -0000 1.1.6.2
+++ sha1-el.el 6 Jan 2004 14:14:43 -0000
@@ -1,6 +1,6 @@
;;; 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 at aqua.ocn.ne.jp>
;; Keywords: SHA1, FIPS 180-1
@@ -54,20 +54,38 @@
(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.
@@ -396,17 +414,20 @@ It must be a string \(program name\) or
;;;
(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.
More information about the Emacs-mime-en
mailing list