The OVF standard allows the use of SHA256 hashes in the manifest file.
Adding support for this.
Signed-off-by: Tomáš Golembiovský <tgolembi(a)redhat.com>
---
v2v/input_ova.ml | 21 ++++++++++++---------
1 file changed, 12 insertions(+), 9 deletions(-)
diff --git a/v2v/input_ova.ml b/v2v/input_ova.ml
index 513fe30..5420c85 100644
--- a/v2v/input_ova.ml
+++ b/v2v/input_ova.ml
@@ -133,7 +133,7 @@ object
(* Read any .mf (manifest) files and verify sha1. *)
let mf = find_files exploded ".mf" in
- let rex = Str.regexp "SHA1(\\(.*\\))= \\([0-9a-fA-F]+\\)\r?" in
+ let rex = Str.regexp "SHA\\(1\\|256\\)(\\(.*\\))= \\([0-9a-fA-F]+\\)\r?"
in
List.iter (
fun mf ->
debug "Processing manifest %s" mf;
@@ -142,20 +142,23 @@ object
let rec loop () =
let line = input_line chan in
if Str.string_match rex line 0 then (
- let disk = Str.matched_group 1 line in
- let expected = Str.matched_group 2 line in
- let cmd = sprintf "sha1sum %s" (quote (mf_folder // disk)) in
+ let sha_num = Str.matched_group 1 line in
+ let disk = Str.matched_group 2 line in
+ let expected = Str.matched_group 3 line in
+ let sha = sprintf "sha%ssum" sha_num in
+ let cmd = sprintf "%s %s" sha (quote (mf_folder // disk)) in
let out = external_command cmd in
match out with
| [] ->
- error (f_"no output from sha1sum command, see previous errors")
+ error (f_"no output from %s command, see previous errors")
+ sha
| [line] ->
let actual, _ = String.split " " line in
if actual <> expected then
- error (f_"checksum of disk %s does not match manifest %s (actual
sha1(%s) = %s, expected sha1 (%s) = %s)")
- disk mf disk actual disk expected;
- debug "sha1 of %s matches expected checksum %s" disk expected
- | _::_ -> error (f_"cannot parse output of sha1sum command")
+ error (f_"checksum of disk %s does not match manifest %s (actual
sha%s(%s) = %s, expected sha%s (%s) = %s)")
+ disk mf sha_num disk actual sha_num disk expected;
+ debug "%s of %s matches expected checksum %s" sha disk expected
+ | _::_ -> error (f_"cannot parse output of %s command") sha
)
else
warning (f_"Unable to parse line from manifest file. Line is
\"%s\"")
--
2.10.0