From 476808d8bacf084e6632b3aebbe14c28ec49e09a Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Mon, 22 Dec 2014 22:19:50 +0000 Subject: [PATCH] zone.lisp: New utility for hashing files. --- zone.lisp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/zone.lisp b/zone.lisp index 28ee038..177ded6 100644 --- a/zone.lisp +++ b/zone.lisp @@ -202,6 +202,19 @@ "Call FUNC on TAG/VALUE pairs from the enumeration called NAME." (maphash func (get name 'enum-forward))) +(defun hash-file (hash file context) + "Hash the FILE using the OpenSSL HASH function, returning an octet string. + + CONTEXT is a temporary-files context." + (let ((temp (temporary-file context "hash"))) + (run-program (list "openssl" "dgst" (concatenate 'string "-" hash)) + :input file :output temp) + (with-open-file (in temp) + (let ((line (read-line in))) + (assert (and (>= (length line) 9) + (string= line "(stdin)= " :end1 9))) + (decode-hex line :start 9))))) + ;;;-------------------------------------------------------------------------- ;;; Zone types. -- 2.11.0