-;; Not so magic character for padding the key. 0x00
-(defconst rfc2104-zero ?\x00)
-
-;; Alist for converting hex to decimal.
-(defconst rfc2104-hex-alist
- '((?0 . 0) (?a . 10) (?A . 10)
- (?1 . 1) (?b . 11) (?B . 11)
- (?2 . 2) (?c . 12) (?C . 12)
- (?3 . 3) (?d . 13) (?D . 13)
- (?4 . 4) (?e . 14) (?E . 14)
- (?5 . 5) (?f . 15) (?F . 15)
- (?6 . 6)
- (?7 . 7)
- (?8 . 8)
- (?9 . 9)))
-
-(defun rfc2104-hex-to-int (str)
- (if str
- (if (listp str)
- (+ (* 16 (rfc2104-hex-to-int (cdr str)))
- (cdr (assoc (car str) rfc2104-hex-alist)))
- (rfc2104-hex-to-int (reverse (append str nil))))
- 0))
-
-(defun rfc2104-hexstring-to-bitstring (str)
- (let (out)
- (while (< 0 (length str))
- (push (rfc2104-hex-to-int (substring str -2)) out)
- (setq str (substring str 0 -2)))
- (apply (if (fboundp 'unibyte-string) 'unibyte-string 'string) out)))
+(defconst rfc2104-nybbles
+ (let ((v (make-vector
+ ;; Find upper bound to save some space.
+ (1+ (max ?0 ?9 ?a ?f ?A ?F))
+ ;; Use non-numeric default to catch bogus hex strings.
+ nil))
+ (ls '((?0 . 0) (?a . 10) (?A . 10)
+ (?1 . 1) (?b . 11) (?B . 11)
+ (?2 . 2) (?c . 12) (?C . 12)
+ (?3 . 3) (?d . 13) (?D . 13)
+ (?4 . 4) (?e . 14) (?E . 14)
+ (?5 . 5) (?f . 15) (?F . 15)
+ (?6 . 6)
+ (?7 . 7)
+ (?8 . 8)
+ (?9 . 9))))
+ (while ls
+ (aset v (caar ls) (cdar ls))
+ (setq ls (cdr ls)))
+ v))
+
+(eval-when-compile
+ (defmacro rfc2104-string-make-unibyte (string)
+ "Return the unibyte equivalent of STRING.
+In XEmacs return just STRING."
+ (if (featurep 'xemacs)
+ string
+ `(string-make-unibyte ,string))))