diff tests/f @ 35472:c1f7037c2ded

tests: teach `f` to handle sha256 checksums
author Matt Harbison <matt_harbison@yahoo.com>
date Wed, 20 Dec 2017 20:46:33 -0500
parents ea4d27aac557
children c69e78ef2b54
line wrap: on
line diff
--- a/tests/f	Wed Dec 20 20:41:12 2017 -0500
+++ b/tests/f	Wed Dec 20 20:46:33 2017 -0500
@@ -59,7 +59,7 @@
         if isfile:
             if opts.type:
                 facts.append('file')
-            if opts.hexdump or opts.dump or opts.md5 or opts.sha1:
+            if any((opts.hexdump, opts.dump, opts.md5, opts.sha1, opts.sha256)):
                 content = open(f, 'rb').read()
         elif islink:
             if opts.type:
@@ -95,6 +95,9 @@
         if opts.sha1 and content is not None:
             h = hashlib.sha1(content)
             facts.append('sha1=%s' % h.hexdigest()[:opts.bytes])
+        if opts.sha256 and content is not None:
+            h = hashlib.sha256(content)
+            facts.append('sha256=%s' % h.hexdigest()[:opts.bytes])
         if isstdin:
             outfile.write(b', '.join(facts) + b'\n')
         elif facts:
@@ -150,6 +153,8 @@
                       help="recurse into directories")
     parser.add_option("-S", "--sha1", action="store_true",
                       help="show sha1 hash of the content")
+    parser.add_option("", "--sha256", action="store_true",
+                      help="show sha256 hash of the content")
     parser.add_option("-M", "--md5", action="store_true",
                       help="show md5 hash of the content")
     parser.add_option("-D", "--dump", action="store_true",