aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Kangas2019-09-16 23:42:56 +0200
committerStefan Kangas2019-10-04 17:30:57 +0200
commitef8fadf8c1399b4ce7086141ebf96610b6475df2 (patch)
treeab17fa1d761d73b67d028029cbd607fbb0e11b4b
parentdd3592564aaaee15077800a093c9e04f5da898dc (diff)
downloademacs-ef8fadf8c1399b4ce7086141ebf96610b6475df2.tar.gz
emacs-ef8fadf8c1399b4ce7086141ebf96610b6475df2.zip
Add tests for secure-hash and improve doc string (Bug#37420)
* src/fns.c (Fsecure_hash_algorithms): Fix typo. (Fsecure_hash): Add algorithm list to doc string. * test/src/fns-tests.el (test-secure-hash): New test.
-rw-r--r--src/fns.c9
-rw-r--r--test/src/fns-tests.el18
2 files changed, 25 insertions, 2 deletions
diff --git a/src/fns.c b/src/fns.c
index b800f1c47fe..fa52e5e1978 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -5081,7 +5081,7 @@ make_digest_string (Lisp_Object digest, int digest_size)
5081 5081
5082DEFUN ("secure-hash-algorithms", Fsecure_hash_algorithms, 5082DEFUN ("secure-hash-algorithms", Fsecure_hash_algorithms,
5083 Ssecure_hash_algorithms, 0, 0, 0, 5083 Ssecure_hash_algorithms, 0, 0, 0,
5084 doc: /* Return a list of all the supported `secure_hash' algorithms. */) 5084 doc: /* Return a list of all the supported `secure-hash' algorithms. */)
5085 (void) 5085 (void)
5086{ 5086{
5087 return list (Qmd5, Qsha1, Qsha224, Qsha256, Qsha384, Qsha512); 5087 return list (Qmd5, Qsha1, Qsha224, Qsha256, Qsha384, Qsha512);
@@ -5388,7 +5388,12 @@ anything security-related. See `secure-hash' for alternatives. */)
5388DEFUN ("secure-hash", Fsecure_hash, Ssecure_hash, 2, 5, 0, 5388DEFUN ("secure-hash", Fsecure_hash, Ssecure_hash, 2, 5, 0,
5389 doc: /* Return the secure hash of OBJECT, a buffer or string. 5389 doc: /* Return the secure hash of OBJECT, a buffer or string.
5390ALGORITHM is a symbol specifying the hash to use: 5390ALGORITHM is a symbol specifying the hash to use:
5391md5, sha1, sha224, sha256, sha384 or sha512. 5391- md5 corresponds to MD5
5392- sha1 corresponds to SHA-1
5393- sha224 corresponds to SHA-2 (SHA-224)
5394- sha256 corresponds to SHA-2 (SHA-256)
5395- sha384 corresponds to SHA-2 (SHA-384)
5396- sha512 corresponds to SHA-2 (SHA-512)
5392 5397
5393The two optional arguments START and END are positions specifying for 5398The two optional arguments START and END are positions specifying for
5394which part of OBJECT to compute the hash. If nil or omitted, uses the 5399which part of OBJECT to compute the hash. If nil or omitted, uses the
diff --git a/test/src/fns-tests.el b/test/src/fns-tests.el
index 7d56da77cf5..6236c9276d2 100644
--- a/test/src/fns-tests.el
+++ b/test/src/fns-tests.el
@@ -858,4 +858,22 @@
858 (puthash k k h))) 858 (puthash k k h)))
859 (should (= 100 (hash-table-count h))))) 859 (should (= 100 (hash-table-count h)))))
860 860
861(ert-deftest test-secure-hash ()
862 (should (equal (secure-hash 'md5 "foobar")
863 "3858f62230ac3c915f300c664312c63f"))
864 (should (equal (secure-hash 'sha1 "foobar")
865 "8843d7f92416211de9ebb963ff4ce28125932878"))
866 (should (equal (secure-hash 'sha224 "foobar")
867 "de76c3e567fca9d246f5f8d3b2e704a38c3c5e258988ab525f941db8"))
868 (should (equal (secure-hash 'sha256 "foobar")
869 (concat "c3ab8ff13720e8ad9047dd39466b3c89"
870 "74e592c2fa383d4a3960714caef0c4f2")))
871 (should (equal (secure-hash 'sha384 "foobar")
872 (concat "3c9c30d9f665e74d515c842960d4a451c83a0125fd3de739"
873 "2d7b37231af10c72ea58aedfcdf89a5765bf902af93ecf06")))
874 (should (equal (secure-hash 'sha512 "foobar")
875 (concat "0a50261ebd1a390fed2bf326f2673c145582a6342d5"
876 "23204973d0219337f81616a8069b012587cf5635f69"
877 "25f1b56c360230c19b273500ee013e030601bf2425"))))
878
861(provide 'fns-tests) 879(provide 'fns-tests)