aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-02-28 13:15:23 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-02-28 13:15:23 +0200
commitd928de165f8bb896ee77f5668f35611f57429c93 (patch)
tree13161cec5af997984aaeac22c54b8c934cb8e0c6 /tests
parente4a63cd55c6347dd24938ec8a1ef203409be058e (diff)
Add SHA256 calculator
Based on the sha256c.c file from the FreeBSD project and ported to compile on Linux, Mac OS, and Windows. The file is licensed under the simplified/2-clause BSD license so the library is now MIT/BSD-licensed.
Diffstat (limited to 'tests')
-rw-r--r--tests/buildfile2
-rw-r--r--tests/sha256/buildfile7
-rw-r--r--tests/sha256/driver.cxx34
3 files changed, 42 insertions, 1 deletions
diff --git a/tests/buildfile b/tests/buildfile
index 57e632e..0ad40e5 100644
--- a/tests/buildfile
+++ b/tests/buildfile
@@ -2,6 +2,6 @@
# copyright : Copyright (c) 2014-2016 Code Synthesis Ltd
# license : MIT; see accompanying LICENSE file
-d = dir-iterator/ path/ prefix-map/ triplet/
+d = dir-iterator/ path/ prefix-map/ sha256/ triplet/
.: $d
include $d
diff --git a/tests/sha256/buildfile b/tests/sha256/buildfile
new file mode 100644
index 0000000..4116ff6
--- /dev/null
+++ b/tests/sha256/buildfile
@@ -0,0 +1,7 @@
+# file : tests/sha256/buildfile
+# copyright : Copyright (c) 2014-2016 Code Synthesis Ltd
+# license : MIT; see accompanying LICENSE file
+
+exe{driver}: cxx{driver} ../../butl/lib{butl}
+
+include ../../butl/
diff --git a/tests/sha256/driver.cxx b/tests/sha256/driver.cxx
new file mode 100644
index 0000000..12928b2
--- /dev/null
+++ b/tests/sha256/driver.cxx
@@ -0,0 +1,34 @@
+// file : tests/triplet/driver.cxx -*- C++ -*-
+// copyright : Copyright (c) 2014-2016 Code Synthesis Ltd
+// license : MIT; see accompanying LICENSE file
+
+#include <string>
+#include <cassert>
+#include <iostream>
+
+#include <butl/sha256>
+
+using namespace std;
+using namespace butl;
+
+int
+main ()
+{
+ assert (string (sha256 ().string ()) ==
+ "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855");
+
+ assert (string (sha256 ("123").string ()) ==
+ "a665a45920422f9d417e4867efdc4fb8a04a1f3fff1fa07e998e86f7f7a27ae3");
+
+ sha256 h;
+ h.append ("1");
+ h.append (string ("2"));
+ h.append ("3", 1);
+
+ auto& b (h.binary ());
+ assert (b[0] == 0xa6 && b[31] == 0xe3);
+
+ string s (h.string ());
+ assert (s ==
+ "a665a45920422f9d417e4867efdc4fb8a04a1f3fff1fa07e998e86f7f7a27ae3");
+}