[Pkg-ocaml-maint-commits] [approx] 04/08: use cryptokit for checksum functions
Eric Cooper
ecc at cmu.edu
Sun Jul 23 21:21:57 UTC 2017
This is an automated email from the git hooks/post-receive script.
ecc-guest pushed a commit to branch master
in repository approx.
commit 36482244190b748a6f63ebd8006dfca94d304543
Author: Eric Cooper <ecc at cmu.edu>
Date: Sat Jul 22 15:11:15 2017 -0400
use cryptokit for checksum functions
---
_tags | 4 ++--
util.ml | 29 ++++++++++++++---------------
2 files changed, 16 insertions(+), 17 deletions(-)
diff --git a/_tags b/_tags
index ee83e10..3574409 100644
--- a/_tags
+++ b/_tags
@@ -8,10 +8,10 @@
<config_file.ml>: package(pcre)
<log.ml>: package(netsys)
<url.ml>: package(netstring)
-<util.ml>: package(sha)
+<util.ml>: package(cryptokit)
<import.ml>: package(pcre)
-<**/*.{byte,native}>: package(netsys), package(pcre), package(sha)
+<**/*.{byte,native}>: package(netsys), package(pcre), package(cryptokit)
<approx.{byte,native}>: package(nethttpd)
<tests/*>: package(oUnit)
diff --git a/util.ml b/util.ml
index 3cf8858..b2bee90 100644
--- a/util.ml
+++ b/util.ml
@@ -301,21 +301,20 @@ let iter_dirs = iter_of_fold fold_dirs
let iter_non_dirs = iter_of_fold fold_non_dirs
-module type MD =
- sig
- type t
- val file : string -> t
- val to_hex : t -> string
- end
-
-module FileDigest (MsgDigest : MD) =
- struct
- let sum file = MsgDigest.to_hex (MsgDigest.file file)
- end
-
-let file_md5sum = let module F = FileDigest(Digest) in F.sum
-let file_sha1sum = let module F = FileDigest(Sha1) in F.sum
-let file_sha256sum = let module F = FileDigest(Sha256) in F.sum
+let to_hex s =
+ let n = String.length s in
+ let hex = Bytes.create (2*n) in
+ for i = 0 to n-1 do
+ Bytes.blit_string (sprintf "%02x" (Char.code s.[i])) 0 hex (2*i) 2
+ done;
+ hex
+
+let hash_file hash file =
+ to_hex (with_in_channel open_in file (Cryptokit.hash_channel hash ?len:None))
+
+let file_md5sum = hash_file (Cryptokit.Hash.md5 ())
+let file_sha1sum = hash_file (Cryptokit.Hash.sha1 ())
+let file_sha256sum = hash_file (Cryptokit.Hash.sha256 ())
let user_id =
object
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ocaml-maint/packages/approx.git
More information about the Pkg-ocaml-maint-commits
mailing list