Commits

simon  committed ed60499

2004-02-06 Simon Josefsson <jas@extundo.com>

* sha1-el.el: Gnus CVS sync changes for the the following
ChangeLog entries, until 2004-01-07 below, suggested by Steve
Youngs <sryoungs@bigpond.net.au>.

2004-01-07 Katsumi Yamaoka <yamaoka@jpl.org>

* sha1-el.el (sha1-string-external): Use with-temp-buffer.

2004-01-07 Katsumi Yamaoka <yamaoka@jpl.org>

* sha1-el.el (sha1-string-external): Make it can return a string
in binary form.
(sha1-region-external): Ditto.
(sha1-string-internal): Ditto.
(sha1-region-internal): Ditto.
(sha1-region): Ditto.
(sha1-string): Ditto.
(sha1): Ditto.

  • Participants
  • Parent commits 4cc3ee2

Comments (0)

Files changed (2)

+2004-02-06  Simon Josefsson  <jas@extundo.com>
+
+	* sha1-el.el: Gnus CVS sync changes for the the following
+	ChangeLog entries, until 2004-01-07 below, suggested by Steve
+	Youngs <sryoungs@bigpond.net.au>.
+
+2004-01-07  Katsumi Yamaoka  <yamaoka@jpl.org>
+
+	* sha1-el.el (sha1-string-external): Use with-temp-buffer.
+
+2004-01-07  Katsumi Yamaoka  <yamaoka@jpl.org>
+
+	* sha1-el.el (sha1-string-external): Make it can return a string
+	in binary form.
+	(sha1-region-external): Ditto.
+	(sha1-string-internal): Ditto.
+	(sha1-region-internal): Ditto.
+	(sha1-region): Ditto.
+	(sha1-string): Ditto.
+	(sha1): Ditto.
+
 2004-01-17  Norbert Koch  <viteno@xemacs.org>
 
 	* Makefile (VERSION): XEmacs package 0.16 released.
-;;; sha1-el.el --- SHA1 Secure Hash Algorithm in Emacs-Lisp.
+;;; sha1-el.el --- SHA1 Secure Hash Algorithm in Emacs-Lisp
 
-;; Copyright (C) 1999, 2001, 2003  Free Software Foundation, Inc.
+;; Copyright (C) 1999, 2001, 2003, 2004 Free Software Foundation, Inc.
 
 ;; Author: Shuhei KOBAYASHI <shuhei@aqua.ocn.ne.jp>
 ;; Keywords: SHA1, FIPS 180-1
   :type 'boolean
   :group 'sha1)
 
-(defun sha1-string-external (string)
-  ;; `with-temp-buffer' is new in v20, so we do not use it.
-  (save-excursion
-    (let (buffer)
-      (unwind-protect
-	  (let (prog args)
-	    (if (consp sha1-program)
-		(setq prog (car sha1-program)
-		      args (cdr sha1-program))
-	      (setq prog sha1-program
-		    args nil))
-	    (setq buffer (set-buffer
-			  (generate-new-buffer " *sha1 external*")))
-	    (insert string)
-	    (apply (function call-process-region)
-		   (point-min)(point-max)
-		   prog t t nil args)
-	    ;; SHA1 is 40 bytes long in hexadecimal form.
-	    (buffer-substring (point-min)(+ (point-min) 40)))
-	(and buffer
-	     (buffer-name buffer)
-	     (kill-buffer buffer))))))
+(defun sha1-string-external (string &optional binary)
+  (let (prog args digest default-enable-multibyte-characters)
+    (if (consp sha1-program)
+	(setq prog (car sha1-program)
+	      args (cdr sha1-program))
+      (setq prog sha1-program
+	    args nil))
+    (with-temp-buffer
+      (insert string)
+      (apply (function call-process-region)
+	     (point-min)(point-max)
+	     prog t t nil args)
+      ;; SHA1 is 40 bytes long in hexadecimal form.
+      (setq digest (buffer-substring (point-min)(+ (point-min) 40))))
+    (if binary
+	(decode-hex-string digest)
+      digest)))
 
-(defun sha1-region-external (beg end)
-  (sha1-string-external (buffer-substring-no-properties beg end)))
+(defun sha1-region-external (beg end &optional binary)
+  (sha1-string-external (buffer-substring-no-properties beg end) binary))
 
 ;;;
 ;;; internal SHA1 function.
       (fillarray block-high nil)
       (fillarray block-low  nil))))
 
-(defun sha1-string-internal (string)
-  (encode-hex-string (sha1-binary string)))
+(defun sha1-string-internal (string &optional binary)
+  (if binary
+      (sha1-binary string)
+    (encode-hex-string (sha1-binary string))))
 
-(defun sha1-region-internal (beg end)
-  (sha1-string-internal (buffer-substring-no-properties beg end)))
+(defun sha1-region-internal (beg end &optional binary)
+  (sha1-string-internal (buffer-substring-no-properties beg end) binary))
 
 ;;;
 ;;; application interface.
 ;;;
 
-(defun sha1-region (beg end)
+(defun sha1-region (beg end &optional binary)
   (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)))
+      (sha1-region-external beg end binary)
+    (sha1-region-internal beg end binary)))
 
-(defun sha1-string (string)
+(defun sha1-string (string &optional binary)
   (if (and sha1-use-external
 	   sha1-maximum-internal-length
 	   (> (length string) sha1-maximum-internal-length))
-      (sha1-string-external string)
-    (sha1-string-internal string)))
+      (sha1-string-external string binary)
+    (sha1-string-internal string binary)))
 
 ;;;###autoload
-(defun sha1 (object &optional beg end)
+(defun sha1 (object &optional beg end binary)
   "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."
+hash of a portion of OBJECT.
+If BINARY is non-nil, return a string in binary form."
   (if (stringp object)
-      (sha1-string object)
+      (sha1-string object binary)
     (save-excursion
       (set-buffer object)
-      (sha1-region (or beg (point-min)) (or end (point-max))))))
+      (sha1-region (or beg (point-min)) (or end (point-max)) binary))))
 
 (provide 'sha1-el)