diff options
| author | Mattias EngdegÄrd | 2020-10-27 11:52:38 +0100 |
|---|---|---|
| committer | Mattias EngdegÄrd | 2020-10-27 12:25:57 +0100 |
| commit | f971a612a92eea4c8aab6b002d7998bb0b6f5ca1 (patch) | |
| tree | 0c75fdf49e5073e9f5c6c51fcd0beb562afce854 /test | |
| parent | 990c0620cb9fee3f4779468662d8447c2b301156 (diff) | |
| download | emacs-f971a612a92eea4c8aab6b002d7998bb0b6f5ca1.tar.gz emacs-f971a612a92eea4c8aab6b002d7998bb0b6f5ca1.zip | |
Don't rely on bignums in ntlm.el
Since ntlm.el is distributed as a separate package in GNU ELPA and
should be able to run on older Emacs versions without bignums,
we cannot make use of them here. See discussion at
https://lists.gnu.org/archive/html/emacs-devel/2020-10/msg01665.html.
Instead, we add a small poor man's bignum implementation.
* lisp/net/ntlm.el (ntlm--bignat-of-int, ntlm--bignat-add)
(ntlm--bignat-shift-left, ntlm--bignat-mul-byte, ntlm--bignat-mul)
(ntlm--bignat-of-string, ntlm--bignat-of-digits)
(ntlm--bignat-to-int64): New.
(ntlm--time-to-timestamp): Use the ntlm--bignat- functions instead
of Lisp integers.
* test/lisp/net/ntlm-tests.el: New file.
Diffstat (limited to 'test')
| -rw-r--r-- | test/lisp/net/ntlm-tests.el | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/test/lisp/net/ntlm-tests.el b/test/lisp/net/ntlm-tests.el new file mode 100644 index 00000000000..e515ebe2635 --- /dev/null +++ b/test/lisp/net/ntlm-tests.el | |||
| @@ -0,0 +1,52 @@ | |||
| 1 | ;;; ntlm-tests.el --- tests for ntlm.el -*- lexical-binding: t -*- | ||
| 2 | |||
| 3 | ;; Copyright (C) 2020 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | ;; This file is part of GNU Emacs. | ||
| 6 | |||
| 7 | ;; GNU Emacs is free software: you can redistribute it and/or modify | ||
| 8 | ;; it under the terms of the GNU General Public License as published by | ||
| 9 | ;; the Free Software Foundation, either version 3 of the License, or | ||
| 10 | ;; (at your option) any later version. | ||
| 11 | |||
| 12 | ;; GNU Emacs is distributed in the hope that it will be useful, | ||
| 13 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 15 | ;; GNU General Public License for more details. | ||
| 16 | |||
| 17 | ;; You should have received a copy of the GNU General Public License | ||
| 18 | ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. | ||
| 19 | |||
| 20 | (require 'ert) | ||
| 21 | (require 'ntlm) | ||
| 22 | |||
| 23 | ;; This is the Lisp bignum implementation of `ntlm--time-to-timestamp', | ||
| 24 | ;; for reference. | ||
| 25 | (defun ntlm-tests--time-to-timestamp (time) | ||
| 26 | "Convert TIME to an NTLMv2 timestamp. | ||
| 27 | Return a unibyte string representing the number of tenths of a | ||
| 28 | microsecond since January 1, 1601 as a 64-bit little-endian | ||
| 29 | signed integer. TIME must be on the form (HIGH LOW USEC PSEC)." | ||
| 30 | (let* ((s (+ (ash (nth 0 time) 16) (nth 1 time))) | ||
| 31 | (us (nth 2 time)) | ||
| 32 | (ps (nth 3 time)) | ||
| 33 | (tenths-of-us-since-jan-1-1601 | ||
| 34 | (+ (* s 10000000) (* us 10) (/ ps 100000) | ||
| 35 | ;; tenths of microseconds between 1601-01-01 and 1970-01-01 | ||
| 36 | 116444736000000000))) | ||
| 37 | (apply #'unibyte-string | ||
| 38 | (mapcar (lambda (i) | ||
| 39 | (logand (ash tenths-of-us-since-jan-1-1601 (* i -8)) | ||
| 40 | #xff)) | ||
| 41 | (number-sequence 0 7))))) | ||
| 42 | |||
| 43 | (ert-deftest ntlm-time-to-timestamp () | ||
| 44 | ;; Verify poor man's bignums in implementation that can run on Emacs < 27.1. | ||
| 45 | (let ((time '(24471 63910 412962 0))) | ||
| 46 | (should (equal (ntlm--time-to-timestamp time) | ||
| 47 | (ntlm-tests--time-to-timestamp time)))) | ||
| 48 | (let ((time '(397431 65535 999999 999999))) | ||
| 49 | (should (equal (ntlm--time-to-timestamp time) | ||
| 50 | (ntlm-tests--time-to-timestamp time))))) | ||
| 51 | |||
| 52 | (provide 'ntlm-tests) | ||