From: Tobias Ulmer Date: Tue, 20 Dec 2016 19:44:49 +0000 (+0100) Subject: digest: add helper functions X-Git-Tag: e2factory-2.3.16rc1~19 X-Git-Url: https://git.e2factory.org/?a=commitdiff_plain;h=3fe0e379df0378e7c6a3bb517c8aa616e66e6046;p=e2factory.git digest: add helper functions Signed-off-by: Tobias Ulmer --- diff --git a/local/digest.lua b/local/digest.lua index 0cb425c..dd48db7 100644 --- a/local/digest.lua +++ b/local/digest.lua @@ -595,6 +595,32 @@ function digest.write(dt, filename) return true end +--- +function digest.type_to_string(digest_type) + assert(digest_type == digest.SHA1 or digest_type == digest.SHA256) + if digest_type == digest.SHA1 then + return "SHA1" + else + return "SHA256" + end +end + +--- +function digest.assertSha1(dgst) + assert(type(dgst) == "string") + assert(#dgst == digest.SHA1_LEN) + local s, e = dgst:find("[a-f0-9]*") + assert(s == 1 and e == digest.SHA1_LEN) +end + +--- +function digest.assertSha256(dgst) + assert(type(dgst) == "string") + assert(#dgst == digest.SHA256_LEN) + local s, e = dgst:find("[a-f0-9]*") + assert(s == 1 and e == digest.SHA256_LEN) +end + return strict.lock(digest) -- vim:sw=4:sts=4:et: