annotate lisp/net/hmac-md5.el @ 107777:13c077500eb3

2010-04-04 John Wiegley <jwiegley@gmail.com> * ido.el (ido-use-virtual-buffers): New variable to indicate whether "virtual buffer" support is enabled for IDO. Essentially it works as follows: Say you are visiting a file and the buffer gets cleaned up by mignight.el. Later, you want to switch to that buffer, but find it's no longer open. With virtual buffers enabled, the buffer name stays in the buffer list (using the ido-virtual face, and always at the end), and if you select it, it opens the file back up again. This allows you to think less about whether recently opened files are still open or not. Most of the time you can quit Emacs, restart, and then switch to a file buffer that was previously open as if it still were. NOTE: This feature has been present in iswitchb for several years now, and I'm porting the same logic to IDO. (ido-virtual): Face used to indicate virtual buffers in the list. (ido-buffer-internal): If a buffer is chosen, and no such buffer exists, but a virtual buffer of that name does (which would be why it was in the list), recreate the buffer by reopening the file. (ido-make-buffer-list): If virtual buffers are being used, call `ido-add-virtual-buffers-to-list' before the make list hook. (ido-virtual-buffers): New variable which contains a copy of the current contents of the `recentf-list', albeit pared down for the sake of speed, and with proper faces applied. (ido-add-virtual-buffers-to-list): Using the `recentf-list', create a list of "virtual buffers" to present to the user in addition to the currently open set. Note that this logic could get rather slow if that list is too large. With the default `recentf-max-saved-items' of 200, there is little speed penalty.
author jwiegley@gmail.com
date Sun, 04 Apr 2010 02:55:19 -0400
parents bb307bf2e752
children 8d09094063d0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
86795
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1 ;;; hmac-md5.el --- Compute HMAC-MD5.
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
2
106815
1d1d5d9bd884 Add 2010 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
3 ;; Copyright (C) 1999, 2001, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
86795
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
4
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
5 ;; Author: Shuhei KOBAYASHI <shuhei@aqua.ocn.ne.jp>
107390
bb307bf2e752 Fix keywords.
Juri Linkov <juri@jurta.org>
parents: 107358
diff changeset
6 ;; Keywords: HMAC, RFC2104, HMAC-MD5, MD5, KEYED-MD5, CRAM-MD5
86795
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
7
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
9
94677
91e5880a36c1 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
86795
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
94677
91e5880a36c1 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
12 ;; the Free Software Foundation, either version 3 of the License, or
91e5880a36c1 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
13 ;; (at your option) any later version.
86795
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
14
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
18 ;; GNU General Public License for more details.
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
19
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
94677
91e5880a36c1 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
86795
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
22
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
23 ;;; Commentary:
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
24
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
25 ;; Test cases from RFC 2202, "Test Cases for HMAC-MD5 and HMAC-SHA-1".
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
26 ;;
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
27 ;; (encode-hex-string (hmac-md5 "Hi There" (make-string 16 ?\x0b)))
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
28 ;; => "9294727a3638bb1c13f48ef8158bfc9d"
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
29 ;;
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
30 ;; (encode-hex-string (hmac-md5 "what do ya want for nothing?" "Jefe"))
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
31 ;; => "750c783e6ab0b503eaa86e310a5db738"
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
32 ;;
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
33 ;; (encode-hex-string (hmac-md5 (make-string 50 ?\xdd) (make-string 16 ?\xaa)))
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
34 ;; => "56be34521d144c88dbb8c733f0e8b3f6"
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
35 ;;
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
36 ;; (encode-hex-string
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
37 ;; (hmac-md5
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
38 ;; (make-string 50 ?\xcd)
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
39 ;; (decode-hex-string "0102030405060708090a0b0c0d0e0f10111213141516171819")))
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
40 ;; => "697eaf0aca3a3aea3a75164746ffaa79"
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
41 ;;
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
42 ;; (encode-hex-string
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
43 ;; (hmac-md5 "Test With Truncation" (make-string 16 ?\x0c)))
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
44 ;; => "56461ef2342edc00f9bab995690efd4c"
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
45 ;;
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
46 ;; (encode-hex-string
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
47 ;; (hmac-md5-96 "Test With Truncation" (make-string 16 ?\x0c)))
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
48 ;; => "56461ef2342edc00f9bab995"
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
49 ;;
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
50 ;; (encode-hex-string
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
51 ;; (hmac-md5
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
52 ;; "Test Using Larger Than Block-Size Key - Hash Key First"
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
53 ;; (make-string 80 ?\xaa)))
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
54 ;; => "6b1ab7fe4bd7bf8f0b62e6ce61b9d0cd"
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
55 ;;
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
56 ;; (encode-hex-string
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
57 ;; (hmac-md5
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
58 ;; "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data"
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
59 ;; (make-string 80 ?\xaa)))
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
60 ;; => "6f630fad67cda0ee1fb1f562db3aa53e"
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
61
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
62 ;;; Code:
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
63
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
64 (eval-when-compile (require 'hmac-def))
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
65 (require 'hex-util) ; (decode-hex-string STRING)
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
66 (require 'md5) ; expects (md5 STRING)
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
67
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
68 (defun md5-binary (string)
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
69 "Return the MD5 of STRING in binary form."
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
70 (if (condition-case nil
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
71 ;; `md5' of v21 takes 4th arg CODING (and 5th arg NOERROR).
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
72 (md5 "" nil nil 'binary) ; => "d41d8cd98f00b204e9800998ecf8427e"
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
73 (wrong-number-of-arguments nil))
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
74 (decode-hex-string (md5 string nil nil 'binary))
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
75 (decode-hex-string (md5 string))))
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
76
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
77 (define-hmac-function hmac-md5 md5-binary 64 16) ; => (hmac-md5 TEXT KEY)
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
78 (define-hmac-function hmac-md5-96 md5-binary 64 16 96)
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
79
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
80 (provide 'hmac-md5)
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
81
93975
1e3a407766b9 Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87665
diff changeset
82 ;; arch-tag: 0ab3f4f6-3d4b-4167-a9fa-635b7fed7f27
86795
6cd3c68dd6ab Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
83 ;;; hmac-md5.el ends here