[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH v4 04/16] osstest: introduce a helper to calculate the sha256 of a given file



The helper is going to be used to calculate the sha256 of the FreeBSD
installer images.

Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
---
Changes since v3:
 - New in this version.
---
 Osstest/TestSupport.pm | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/Osstest/TestSupport.pm b/Osstest/TestSupport.pm
index e30e5759..12ebc32d 100644
--- a/Osstest/TestSupport.pm
+++ b/Osstest/TestSupport.pm
@@ -32,6 +32,7 @@ use File::Copy;
 use File::Basename;
 use IO::Handle;
 use Carp;
+use Digest::SHA;
 
 BEGIN {
     use Exporter ();
@@ -132,6 +133,7 @@ BEGIN {
                       guest_editconfig_nocd
                       host_install_postboot_complete
                       target_core_dump_setup
+                      sha256file
                       );
     %EXPORT_TAGS = ( );
 
@@ -2769,4 +2771,15 @@ sub target_https_mitm_proxy_setup ($) {
     target_cmd_root($ho, 'update-ca-certificates', 300);
 }
 
+sub sha256file ($;$) {
+    my ($file,$truncate) = @_;
+    my $sha = Digest::SHA->new(256);
+    my $digest;
+
+    $sha->addfile($file);
+    $digest = $sha->hexdigest;
+
+    return $truncate ? substr($digest, 0, $truncate) : $digest;
+}
+
 1;
-- 
2.11.0 (Apple Git-81)


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
https://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.