aboutsummaryrefslogtreecommitdiff
path: root/tests/sha256
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2018-01-19 00:02:21 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2018-02-08 20:49:08 +0300
commit4d30878d8efb86fd110c3693024db5da7aceb776 (patch)
treeb46ac328b499989ce27e48ca48bcc16f9f42d882 /tests/sha256
parenta12216dd1ed9582fc96805189caadc2b733a4e70 (diff)
Add abbreviated_string() to sha* classes
Diffstat (limited to 'tests/sha256')
-rw-r--r--tests/sha256/driver.cxx19
1 files changed, 14 insertions, 5 deletions
diff --git a/tests/sha256/driver.cxx b/tests/sha256/driver.cxx
index 191756c..6ba1cd1 100644
--- a/tests/sha256/driver.cxx
+++ b/tests/sha256/driver.cxx
@@ -33,13 +33,20 @@ main ()
assert (string (sha256 ("").string ()) !=
"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855");
- assert (string (sha256 ("123").string ()) ==
- "a787b6772e3e4df1b2a04d5eee56f8570ab38825eed1b6a9bda288429b7f29a1");
-
assert (string (sha256 ("123", 3).string ()) ==
"a665a45920422f9d417e4867efdc4fb8a04a1f3fff1fa07e998e86f7f7a27ae3");
{
+ sha256 h ("123");
+
+ assert (string (h.string ()) ==
+ "a787b6772e3e4df1b2a04d5eee56f8570ab38825eed1b6a9bda288429b7f29a1");
+
+ assert (h.abbreviated_string (10) == "a787b6772e");
+ assert (h.abbreviated_string (65) == h.string ());
+ }
+
+ {
sha256 h;
h.append ("1");
h.append (string ("2"));
@@ -48,8 +55,7 @@ main ()
auto& b (h.binary ());
assert (b[0] == 0x20 && b[31] == 0x9d);
- string s (h.string ());
- assert (s ==
+ assert (string (h.string ()) ==
"204d9db65789fbede7829ed77f72ba1f0fe21a833d95abad4849b82f33a69b9d");
}
@@ -71,5 +77,8 @@ main ()
"f49dc002c6b66206a548ae8735329564c2b8c96d9b28856defcafa7f04b54fa6");
assert (fingerprint_to_sha256 (fp) == sh);
+ assert (fingerprint_to_sha256 (fp, 65) == sh);
+ assert (fingerprint_to_sha256 (fp, 10) == sh.substr (0, 10));
+
assert (sha256_to_fingerprint (sh) == fp);
}