Script 'mail_helper' called by obssrc
Hello community,

here is the log from the commit of package ocaml-sha for openSUSE:Factory 
checked in at 2021-10-18 21:59:13
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/ocaml-sha (Old)
 and      /work/SRC/openSUSE:Factory/.ocaml-sha.new.1890 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "ocaml-sha"

Mon Oct 18 21:59:13 2021 rev:7 rq:925817 version:1.15.1

Changes:
--------
--- /work/SRC/openSUSE:Factory/ocaml-sha/ocaml-sha.changes      2021-04-29 
01:38:14.242564574 +0200
+++ /work/SRC/openSUSE:Factory/.ocaml-sha.new.1890/ocaml-sha.changes    
2021-10-18 22:02:04.838088730 +0200
@@ -1,0 +2,5 @@
+Sun Oct 10 10:10:10 UTC 2021 - oher...@suse.de
+
+- Update to version 1.15.1
+
+-------------------------------------------------------------------

Old:
----
  ocaml-sha-1.14.tar.xz

New:
----
  ocaml-sha-1.15.1.tar.xz

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ ocaml-sha.spec ++++++
--- /var/tmp/diff_new_pack.euaoBn/_old  2021-10-18 22:02:05.274089046 +0200
+++ /var/tmp/diff_new_pack.euaoBn/_new  2021-10-18 22:02:05.274089046 +0200
@@ -25,7 +25,7 @@
 
 %define     pkg ocaml-sha
 Name:           %{pkg}%{nsuffix}
-Version:        1.14
+Version:        1.15.1
 Release:        0
 %{?ocaml_preserve_bytecode}
 Summary:        Binding to the SHA cryptographic functions
@@ -34,12 +34,12 @@
 URL:            https://opam.ocaml.org/packages/sha
 Source0:        %{pkg}-%{version}.tar.xz
 BuildRequires:  ocaml
-BuildRequires:  ocaml-dune >= 2.0
+BuildRequires:  ocaml-dune >= 2.9
 BuildRequires:  ocamlfind(stdlib-shims)
-BuildRequires:  ocaml-rpm-macros >= 20210409
+BuildRequires:  ocaml-rpm-macros >= 20210911
 
 %if "%{build_flavor}" == "testsuite"
-BuildRequires:  ocamlfind(oUnit)
+BuildRequires:  ocamlfind(ounit2)
 BuildRequires:  ocamlfind(sha)
 %endif
 

++++++ _service ++++++
--- /var/tmp/diff_new_pack.euaoBn/_old  2021-10-18 22:02:05.310089072 +0200
+++ /var/tmp/diff_new_pack.euaoBn/_new  2021-10-18 22:02:05.314089075 +0200
@@ -1,7 +1,7 @@
 <services>
   <service name="tar_scm" mode="disabled">
     <param name="filename">ocaml-sha</param>
-    <param name="revision">c86a4c76b23a6bd3ae700ea054dc4b6e4d4feef7</param>
+    <param name="revision">af5c7b1c7d3b8f9492038b7b40ba9cad82fb4ee8</param>
     <param name="scm">git</param>
     <param name="submodules">disable</param>
     <param name="url">https://github.com/djs55/ocaml-sha.git</param>

++++++ ocaml-sha-1.14.tar.xz -> ocaml-sha-1.15.1.tar.xz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/ocaml-sha-1.14/.github/workflows/main.yml 
new/ocaml-sha-1.15.1/.github/workflows/main.yml
--- old/ocaml-sha-1.14/.github/workflows/main.yml       1970-01-01 
01:00:00.000000000 +0100
+++ new/ocaml-sha-1.15.1/.github/workflows/main.yml     2021-10-04 
14:49:31.000000000 +0200
@@ -0,0 +1,38 @@
+name: Main workflow
+
+on:
+  pull_request:
+  push:
+  schedule:
+    # Prime the caches every Monday
+    - cron: 0 1 * * MON
+
+jobs:
+  build:
+    strategy:
+      fail-fast: false
+      matrix:
+        os:
+          - macos-latest
+          - ubuntu-latest
+          - windows-latest
+        ocaml-compiler:
+          - 4.02.x
+          - 4.13.x
+
+    runs-on: ${{ matrix.os }}
+
+    steps:
+      - name: Checkout code
+        uses: actions/checkout@v2
+
+      - name: Use OCaml ${{ matrix.ocaml-compiler }}
+        uses: ocaml/setup-ocaml@v2
+        with:
+          ocaml-compiler: ${{ matrix.ocaml-compiler }}
+
+      - run: opam install . --deps-only --with-test
+
+      - run: opam exec -- dune build
+
+      - run: opam exec -- dune runtest
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/ocaml-sha-1.14/.gitignore 
new/ocaml-sha-1.15.1/.gitignore
--- old/ocaml-sha-1.14/.gitignore       1970-01-01 01:00:00.000000000 +0100
+++ new/ocaml-sha-1.15.1/.gitignore     2021-10-04 14:49:31.000000000 +0200
@@ -0,0 +1,3 @@
+_build
+.merlin
+*.install
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/ocaml-sha-1.14/CHANGES.md 
new/ocaml-sha-1.15.1/CHANGES.md
--- old/ocaml-sha-1.14/CHANGES.md       2021-03-15 09:17:31.000000000 +0100
+++ new/ocaml-sha-1.15.1/CHANGES.md     2021-10-04 14:49:31.000000000 +0200
@@ -1,3 +1,18 @@
+## v1.15.1
+
+Opam CI fixes by @MisterDA (#54):
+
+- update to Dune 2.9 to fix [lint 
warning](https://opam.ci.ocaml.org/github/ocaml/opam-repository/commit/8cf1e193733c6d6c0330b46c1a7b7a2819e9a977/variant/(lint));
+  > (lint) (failed: Warning in sha.1.15: Dubious use of 'dune subst'. 'dune 
subst' should always only be called with {dev} (i.e. ["dune" "subst"] {dev}) If 
your opam file has been autogenerated by dune, you need to upgrade your 
dune-project to at least (lang dune 2.7).)
+- define `Bytes_val` ourselves before OCaml 4.06;
+- add setup-ocaml GitHub action to catch mistakes earlier.
+
+## v1.15
+
+- Add `equal` function to compare digests by @MisterDA (#52)
+- Improve documentation formatting by @MisterDA (#51)
+- Add `of_hex` and `of_bin` functions to unserialise `ShaX.t` values by 
@MisterDA (#50)
+
 ## v1.14
 
 - Handle `safe-string` by @olafhering, reviewed by @nojb (#47)
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/ocaml-sha-1.14/dune new/ocaml-sha-1.15.1/dune
--- old/ocaml-sha-1.14/dune     2021-03-15 09:17:31.000000000 +0100
+++ new/ocaml-sha-1.15.1/dune   2021-10-04 14:49:31.000000000 +0200
@@ -1,4 +1,7 @@
-(rule (with-stdout-to c_flags.sexp (run %{ocaml} %{dep:c_flags.ml})))
+(rule
+ (with-stdout-to
+  c_flags.sexp
+  (run %{ocaml} %{dep:c_flags.ml})))
 
 (library
  (name sha)
@@ -6,9 +9,10 @@
  (synopsis "SHA-1 and SHA-2 family implementations")
  (wrapped false)
  (modules sha1 sha256 sha512)
- (flags -warn-error -3)
  (libraries stdlib-shims)
  (foreign_stubs
   (language c)
-  (flags (:include c_flags.sexp))
+  (flags
+   :standard
+   (:include c_flags.sexp))
   (names sha1_stubs sha256_stubs sha512_stubs)))
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/ocaml-sha-1.14/dune-project 
new/ocaml-sha-1.15.1/dune-project
--- old/ocaml-sha-1.14/dune-project     2021-03-15 09:17:31.000000000 +0100
+++ new/ocaml-sha-1.15.1/dune-project   2021-10-04 14:49:31.000000000 +0200
@@ -1,4 +1,4 @@
-(lang dune 2.0)
+(lang dune 2.9)
 
 (name sha)
 
@@ -19,6 +19,7 @@
          "Nicol??s Ojeda B??r"
          "Christopher Zimmermann"
          "Thomas Leonard"
+         "Antonin D??cimo"
 )
 
 (maintainers d...@recoil.org)
@@ -29,6 +30,11 @@
  (description "This is the binding for SHA interface code in OCaml. Offering 
the same
 interface than the MD5 digest included in the OCaml standard library.
 It's currently providing SHA1, SHA256 and SHA512 hash functions.")
- (depends (dune (>= 2.0)) (stdlib-shims (>= 0.3.0)) (ounit :with-test)))
+ (depends
+  (ocaml (>= 4.02))
+  (stdlib-shims (>= 0.3.0))
+  (ounit2 :with-test)))
 
 (generate_opam_files true)
+(formatting disabled)
+(use_standard_c_and_cxx_flags true)
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/ocaml-sha-1.14/pkg/pkg.ml 
new/ocaml-sha-1.15.1/pkg/pkg.ml
--- old/ocaml-sha-1.14/pkg/pkg.ml       2021-03-15 09:17:31.000000000 +0100
+++ new/ocaml-sha-1.15.1/pkg/pkg.ml     1970-01-01 01:00:00.000000000 +0100
@@ -1,3 +0,0 @@
-#!/usr/bin/env ocaml
-#use "topfind"
-#require "topkg-jbuilder.auto"
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/ocaml-sha-1.14/sha.opam new/ocaml-sha-1.15.1/sha.opam
--- old/ocaml-sha-1.14/sha.opam 2021-03-15 09:17:31.000000000 +0100
+++ new/ocaml-sha-1.15.1/sha.opam       2021-10-04 14:49:31.000000000 +0200
@@ -20,17 +20,20 @@
   "Nicol??s Ojeda B??r"
   "Christopher Zimmermann"
   "Thomas Leonard"
+  "Antonin D??cimo"
 ]
 license: "ISC"
 homepage: "https://github.com/djs55/ocaml-sha";
 bug-reports: "https://github.com/djs55/ocaml-sha/issues";
 depends: [
-  "dune" {>= "2.0"}
+  "dune" {>= "2.9"}
+  "ocaml" {>= "4.02"}
   "stdlib-shims" {>= "0.3.0"}
-  "ounit" {with-test}
+  "ounit2" {with-test}
+  "odoc" {with-doc}
 ]
 build: [
-  ["dune" "subst"] {pinned}
+  ["dune" "subst"] {dev}
   [
     "dune"
     "build"
@@ -38,9 +41,11 @@
     name
     "-j"
     jobs
+    "--promote-install-files=false"
     "@install"
     "@runtest" {with-test}
     "@doc" {with-doc}
   ]
+  ["dune" "install" "-p" name "--create-install-files" name]
 ]
 dev-repo: "git+https://github.com/djs55/ocaml-sha.git";
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/ocaml-sha-1.14/sha1.h new/ocaml-sha-1.15.1/sha1.h
--- old/ocaml-sha-1.14/sha1.h   2021-03-15 09:17:31.000000000 +0100
+++ new/ocaml-sha-1.15.1/sha1.h 2021-10-04 14:49:31.000000000 +0200
@@ -21,6 +21,7 @@
 #include <string.h>
 #include <stdio.h>
 #include "bitfn.h"
+#include "util.h"
 
 struct sha1_ctx
 {
@@ -288,4 +289,22 @@
        #undef D
 }
 
+/**
+ * sha1_of_bin - Transform binary data into the SHA1 digest
+ */
+static void sha1_of_bin(const char *in, sha1_digest *digest)
+{
+       memcpy(digest->digest, in, sizeof(*digest));
+}
+
+/**
+ * sha1_of_hex - Transform readable data into the SHA1 digest
+ */
+static void sha1_of_hex(const char *in, sha1_digest *digest)
+{
+       if (strlen(in) != 40)
+               return;
+       of_hex((unsigned char *) digest->digest, in, 40);
+}
+
 #endif
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/ocaml-sha-1.14/sha1.ml new/ocaml-sha-1.15.1/sha1.ml
--- old/ocaml-sha-1.14/sha1.ml  2021-03-15 09:17:31.000000000 +0100
+++ new/ocaml-sha-1.15.1/sha1.ml        2021-10-04 14:49:31.000000000 +0200
@@ -27,7 +27,10 @@
 external copy : ctx -> ctx = "stub_sha1_copy"
 external to_bin: t -> string = "stub_sha1_to_bin"
 external to_hex: t -> string = "stub_sha1_to_hex"
+external of_bin: bytes -> t = "stub_sha1_of_bin"
+external of_hex: string -> t = "stub_sha1_of_hex"
 external file_fast: string -> t = "stub_sha1_file"
+external equal: t -> t -> bool = "stub_sha1_equal"
 
 let blksize = 4096
 
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/ocaml-sha-1.14/sha1.mli new/ocaml-sha-1.15.1/sha1.mli
--- old/ocaml-sha-1.14/sha1.mli 2021-03-15 09:17:31.000000000 +0100
+++ new/ocaml-sha-1.15.1/sha1.mli       2021-10-04 14:49:31.000000000 +0200
@@ -17,62 +17,65 @@
 
 (** SHA1 OCaml binding *)
 
-(** context type - opaque *)
+(** Context type - opaque. *)
 type ctx
 
-(** buffer type *)
+(** Buffer type. *)
 type buf = (char, Bigarray.int8_unsigned_elt, Bigarray.c_layout) 
Bigarray.Array1.t
 
-(** digest type - opaque *)
+(** Digest type - opaque. *)
 type t
 
-(** The zero digest *)
+(** The zero digest. *)
 val zero : t
 
-(** Create a new context *)
-external init: unit -> ctx = "stub_sha1_init"
+(** Create a new context. *)
+external init : unit -> ctx = "stub_sha1_init"
 
-(** Sha1.unsafe_update_substring ctx s ofs len updates the context
-    with the substring of s starting at character number ofs and
-    containing len characters. Unsafe: No range checking! *)
-external unsafe_update_substring: ctx -> string -> int -> int -> unit = 
"stub_sha1_update"
-
-(** Sha1.update_substring ctx s ofs len updates the context with the
-    substring of s starting at character number ofs and containing len
-    characters. *)
-val update_substring: ctx -> string -> int -> int -> unit
-
-(** Sha1.update_string ctx s updates the context with s. *)
-val update_string: ctx -> string -> unit
-
-(** Sha1.update_buffer ctx a updates the context with a.
-    Runs parallel to other threads if any exist. *)
-external update_buffer: ctx -> buf -> unit = "stub_sha1_update_bigarray"
+(** [Sha1.unsafe_update_substring ctx s ofs len] updates the context
+   with the substring of [s] starting at character number [ofs] and
+   containing [len] characters. Unsafe: No range checking! *)
+external unsafe_update_substring : ctx -> string -> int -> int -> unit = 
"stub_sha1_update"
+
+(** [Sha1.update_substring ctx s ofs len] updates the context with the
+   substring of [s] starting at character number [ofs] and containing
+   [len] characters. *)
+val update_substring : ctx -> string -> int -> int -> unit
+
+(** [Sha1.update_string ctx s] updates the context with [s]. *)
+val update_string : ctx -> string -> unit
+
+(** [Sha1.update_buffer ctx a] updates the context with [a]. Runs
+   parallel to other threads if any exist. *)
+external update_buffer : ctx -> buf -> unit = "stub_sha1_update_bigarray"
 
-(** Finalize the context and return digest *)
-external finalize: ctx -> t = "stub_sha1_finalize"
+(** Finalize the context and return digest. *)
+external finalize : ctx -> t = "stub_sha1_finalize"
 
-(** Return an copy of the context *)
+(** Return a copy of the context. *)
 external copy : ctx -> ctx = "stub_sha1_copy"
 
 (** Return the digest of the given string. *)
 val string : string -> t
 
-(** Sha1.substring s ofs len returns the digest of the substring of s starting
-at character number ofs and containing len characters. *)
+(** [Sha1.substring s ofs len] returns the digest of the substring of
+   [s] starting at character number [ofs] and containing [len]
+   characters. *)
 val substring : string -> int -> int -> t
 
-(** If len is nonnegative, Sha1.channel ic len reads len characters from
-channel ic and returns their digest, or raises End_of_file if end-of-file is
-reached before len characters are read. If len is negative, Sha1.channel ic
-len reads all characters from ic until end-of-file is reached and return their
-digest. *)
+(** If [len] is nonnegative, [Sha1.channel ic len] reads [len]
+   characters from channel [ic] and returns their digest, or raises
+   [End_of_file] if end-of-file is reached before [len] characters are
+   read. If [len] is negative, [Sha1.channel ic len] reads all
+   characters from [ic] until end-of-file is reached and return their
+   digest. *)
 val channel : in_channel -> int -> t
 
 (** Return the digest of the file whose name is given. *)
 val file : string -> t
 
-(** Return the digest of the file whose name is given using fast C function *)
+(** Return the digest of the file whose name is given using fast C
+   function. *)
 val file_fast : string -> t
 
 (** Write a digest on the given output channel. *)
@@ -81,8 +84,20 @@
 (** Read a digest from the given input channel. *)
 val input : in_channel -> t
 
-(** return a binary representation of the given digest *)
+(** Return a binary representation of the given digest. *)
 val to_bin : t -> string
 
-(** return a printable hexadecimal representation of the given digest *)
+(** Return a printable hexadecimal representation of the given
+   digest. *)
 val to_hex : t -> string
+
+(** Returns whether two hashes are equal. *)
+val equal : t -> t -> bool
+
+(** Sha1.of_bin digest converts the binary representation of a digest to the
+   internal representation of Sha1.t. *)
+val of_bin : bytes -> t
+
+(** Sha1.of_hex digest converts the hexadecimal representation of a digest to
+   the internal representation of Sha1.t. *)
+val of_hex : string -> t
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/ocaml-sha-1.14/sha1_stubs.c 
new/ocaml-sha-1.15.1/sha1_stubs.c
--- old/ocaml-sha-1.14/sha1_stubs.c     2021-03-15 09:17:31.000000000 +0100
+++ new/ocaml-sha-1.15.1/sha1_stubs.c   2021-10-04 14:49:31.000000000 +0200
@@ -62,6 +62,11 @@
 #include <caml/bigarray.h>
 #include <caml/threads.h>
 
+#include <caml/version.h>
+#if OCAML_VERSION < 40600
+#define Bytes_val(x) ((unsigned char *) Bp_val(x))
+#endif
+
 #define GET_CTX_STRUCT(a) ((struct sha1_ctx *) a)
 
 CAMLexport value stub_sha1_init(value unit)
@@ -169,3 +174,32 @@
 
        CAMLreturn(result);
 }
+
+CAMLprim value stub_sha1_equal(value t1, value t2)
+{
+       CAMLparam2(t1, t2);
+       int b = memcmp((sha1_digest *) t1, (sha1_digest *) t2, 
sizeof(sha1_digest)) == 0;
+       CAMLreturn(Bool_val(b));
+}
+
+CAMLprim value stub_sha1_of_bin(value bin)
+{
+       CAMLparam1(bin);
+       CAMLlocal1(result);
+
+       result = caml_alloc(sizeof(sha1_digest), Abstract_tag);
+       sha1_of_bin((const char *) Bytes_val(bin), (sha1_digest *) result);
+
+       CAMLreturn(result);
+}
+
+CAMLprim value stub_sha1_of_hex(value hex)
+{
+       CAMLparam1(hex);
+       CAMLlocal1(result);
+
+       result = caml_alloc(sizeof(sha1_digest), Abstract_tag);
+       sha1_of_hex(String_val(hex), (sha1_digest *) result);
+
+       CAMLreturn(result);
+}
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/ocaml-sha-1.14/sha256.h new/ocaml-sha-1.15.1/sha256.h
--- old/ocaml-sha-1.14/sha256.h 2021-03-15 09:17:31.000000000 +0100
+++ new/ocaml-sha-1.15.1/sha256.h       2021-10-04 14:49:31.000000000 +0200
@@ -22,6 +22,7 @@
 #include <string.h>
 #include <stdio.h>
 #include "bitfn.h"
+#include "util.h"
 
 struct sha256_ctx
 {
@@ -233,4 +234,22 @@
                snprintf(p, 9, "%08x", be32_to_cpu(digest->digest[i]));
 }
 
+/**
+ * sha256_of_bin - Transform binary data into the SHA256 digest
+ */
+static void sha256_of_bin(const char *in, sha256_digest *digest)
+{
+       memcpy(digest->digest, in, sizeof(*digest));
+}
+
+/**
+ * sha256_of_hex - Transform readable data into the SHA256 digest
+ */
+static void sha256_of_hex(const char *in, sha256_digest *digest)
+{
+       if (strlen(in) != 64)
+               return;
+       of_hex((unsigned char *) digest->digest, in, 64);
+}
+
 #endif
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/ocaml-sha-1.14/sha256.ml 
new/ocaml-sha-1.15.1/sha256.ml
--- old/ocaml-sha-1.14/sha256.ml        2021-03-15 09:17:31.000000000 +0100
+++ new/ocaml-sha-1.15.1/sha256.ml      2021-10-04 14:49:31.000000000 +0200
@@ -27,7 +27,10 @@
 external copy : ctx -> ctx = "stub_sha256_copy"
 external to_bin: t -> string = "stub_sha256_to_bin"
 external to_hex: t -> string = "stub_sha256_to_hex"
+external of_bin: bytes -> t = "stub_sha256_of_bin"
+external of_hex: string -> t = "stub_sha256_of_hex"
 external file_fast: string -> t = "stub_sha256_file"
+external equal: t -> t -> bool = "stub_sha256_equal"
 
 let blksize = 4096
 
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/ocaml-sha-1.14/sha256.mli 
new/ocaml-sha-1.15.1/sha256.mli
--- old/ocaml-sha-1.14/sha256.mli       2021-03-15 09:17:31.000000000 +0100
+++ new/ocaml-sha-1.15.1/sha256.mli     2021-10-04 14:49:31.000000000 +0200
@@ -17,65 +17,65 @@
 
 (** SHA256 OCaml binding *)
 
-(** context type - opaque *)
+(** Context type - opaque. *)
 type ctx
 
-(** buffer type *)
+(** Buffer type. *)
 type buf = (int, Bigarray.int8_unsigned_elt, Bigarray.c_layout) 
Bigarray.Array1.t
 
-(** digest type - opaque *)
+(** Digest type - opaque. *)
 type t
 
-(** The zero digest *)
+(** The zero digest. *)
 val zero : t
 
-(** Create a new context *)
-external init: unit -> ctx = "stub_sha256_init"
+(** Create a new context. *)
+external init : unit -> ctx = "stub_sha256_init"
 
-(** Sha256.unsafe_update_substring ctx s ofs len updates the context
-    with the substring of s starting at character number ofs and
-    containing len characters. Unsafe: No range checking! *)
-external unsafe_update_substring: ctx -> string -> int -> int -> unit = 
"stub_sha256_update"
-
-(** Sha256.update_substring ctx s ofs len updates the context with the
-    substring of s starting at character number ofs and containing len
-    characters. *)
-val update_substring: ctx -> string -> int -> int -> unit
-
-(** Sha256.update_string ctx s updates the context with s. *)
-val update_string: ctx -> string -> unit
-
-(** Sha256.update_buffer ctx a updates the context with a.
-    Runs parallel to other threads if any exist. *)
-external update_buffer: ctx -> buf -> unit = "stub_sha256_update_bigarray"
+(** [Sha256.unsafe_update_substring ctx s ofs len] updates the context with the
+   substring of [s] starting at character number [ofs] and containing [len]
+   characters. Unsafe: No range checking! *)
+external unsafe_update_substring : ctx -> string -> int -> int -> unit = 
"stub_sha256_update"
+
+(** [Sha256.update_substring ctx s ofs len] updates the context with the
+   substring of [s] starting at character number [ofs] and containing [len]
+   characters. *)
+val update_substring : ctx -> string -> int -> int -> unit
+
+(** [Sha256.update_string ctx s] updates the context with [s]. *)
+val update_string : ctx -> string -> unit
+
+(** [Sha256.update_buffer ctx a] updates the context with [a]. Runs parallel to
+   other threads if any exist. *)
+external update_buffer : ctx -> buf -> unit = "stub_sha256_update_bigarray"
 
-(** Finalize the context and return digest *)
-external finalize: ctx -> t = "stub_sha256_finalize"
+(** Finalize the context and return digest. *)
+external finalize : ctx -> t = "stub_sha256_finalize"
 
-(** Return an copy of the context *)
+(** Return a copy of the context. *)
 external copy : ctx -> ctx = "stub_sha256_copy"
 
 (** Return the digest of the given string. *)
 val string : string -> t
 
-(** Sha256.substring s ofs len returns the digest of the substring of s 
starting
-at character number ofs and containing len characters. *)
+(** [Sha256.substring s ofs len] returns the digest of the substring of [s]
+   starting at character number [ofs] and containing [len] characters. *)
 val substring : string -> int -> int -> t
 
 (** Return the digest of the given buffer. *)
 val buffer : buf -> t
 
-(** If len is nonnegative, Sha256.channel ic len reads len characters from
-channel ic and returns their digest, or raises End_of_file if end-of-file is
-reached before len characters are read. If len is negative, Sha256.channel ic
-len reads all characters from ic until end-of-file is reached and return their
-digest. *)
+(** If [len] is nonnegative, [Sha256.channel ic len] reads [len] characters 
from
+   channel [ic] and returns their digest, or raises [End_of_file] if 
end-of-file
+   is reached before [len] characters are read. If [len] is negative,
+   [Sha256.channel ic len] reads all characters from [ic] until end-of-file is
+   reached and return their digest. *)
 val channel : in_channel -> int -> t
 
 (** Return the digest of the file whose name is given. *)
 val file : string -> t
 
-(** Return the digest of the file whose name is given using fast C function *)
+(** Return the digest of the file whose name is given using fast C function. *)
 val file_fast : string -> t
 
 (** Write a digest on the given output channel. *)
@@ -84,8 +84,19 @@
 (** Read a digest from the given input channel. *)
 val input : in_channel -> t
 
-(** return a binary representation of the given digest *)
+(** Return a binary representation of the given digest. *)
 val to_bin : t -> string
 
-(** return a printable hexadecimal representation of the given digest *)
+(** Return a printable hexadecimal representation of the given digest. *)
 val to_hex : t -> string
+
+(** Returns whether two hashes are equal. *)
+val equal : t -> t -> bool
+
+(** Sha256.of_bin digest converts the binary representation of a digest to the
+   internal representation of Sha256.t. *)
+val of_bin : bytes -> t
+
+(** Sha256.of_hex digest converts the hexadecimal representation of a digest to
+   the internal representation of Sha256.t. *)
+val of_hex : string -> t
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/ocaml-sha-1.14/sha256_stubs.c 
new/ocaml-sha-1.15.1/sha256_stubs.c
--- old/ocaml-sha-1.14/sha256_stubs.c   2021-03-15 09:17:31.000000000 +0100
+++ new/ocaml-sha-1.15.1/sha256_stubs.c 2021-10-04 14:49:31.000000000 +0200
@@ -62,6 +62,11 @@
 #include <caml/bigarray.h>
 #include <caml/threads.h>
 
+#include <caml/version.h>
+#if OCAML_VERSION < 40600
+#define Bytes_val(x) ((unsigned char *) Bp_val(x))
+#endif
+
 #define GET_CTX_STRUCT(a) ((struct sha256_ctx *) a)
 
 CAMLexport value stub_sha256_init(value unit)
@@ -167,3 +172,32 @@
 
        CAMLreturn(result);
 }
+
+CAMLprim value stub_sha256_equal(value t1, value t2)
+{
+       CAMLparam2(t1, t2);
+       int b = memcmp((sha256_digest *) t1, (sha256_digest *) t2, 
sizeof(sha256_digest)) == 0;
+       CAMLreturn(Bool_val(b));
+}
+
+CAMLprim value stub_sha256_of_bin(value bin)
+{
+       CAMLparam1(bin);
+       CAMLlocal1(result);
+
+       result = caml_alloc(sizeof(sha256_digest), Abstract_tag);
+       sha256_of_bin((const char *) Bytes_val(bin), (sha256_digest *) result);
+
+       CAMLreturn(result);
+}
+
+CAMLprim value stub_sha256_of_hex(value hex)
+{
+       CAMLparam1(hex);
+       CAMLlocal1(result);
+
+       result = caml_alloc(sizeof(sha256_digest), Abstract_tag);
+       sha256_of_hex(String_val(hex), (sha256_digest *) result);
+
+       CAMLreturn(result);
+}
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/ocaml-sha-1.14/sha512.h new/ocaml-sha-1.15.1/sha512.h
--- old/ocaml-sha-1.14/sha512.h 2021-03-15 09:17:31.000000000 +0100
+++ new/ocaml-sha-1.15.1/sha512.h       2021-10-04 14:49:31.000000000 +0200
@@ -23,6 +23,7 @@
 #include <string.h>
 #include <stdio.h>
 #include "bitfn.h"
+#include "util.h"
 
 struct sha512_ctx
 {
@@ -254,7 +255,25 @@
 
        for (p = out, i = 0; i < 8; i++, p += 16)
                snprintf(p, 17, "%016llx",
-                        (unsigned long long) be64_to_cpu(digest->digest[i]));
+                         (unsigned long long) be64_to_cpu(digest->digest[i]));
+}
+
+/**
+ * sha512_of_bin - Transform binary data into the SHA512 digest
+ */
+static void sha512_of_bin(const char *in, sha512_digest *digest)
+{
+       memcpy(digest->digest, in, sizeof(*digest));
+}
+
+/**
+ * sha512_of_hex - Transform readable data into the SHA512 digest
+ */
+static void sha512_of_hex(const char *in, sha512_digest *digest)
+{
+       if (strlen(in) != 128)
+               return;
+       of_hex((unsigned char *) digest->digest, in, 128);
 }
 
 #endif
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/ocaml-sha-1.14/sha512.ml 
new/ocaml-sha-1.15.1/sha512.ml
--- old/ocaml-sha-1.14/sha512.ml        2021-03-15 09:17:31.000000000 +0100
+++ new/ocaml-sha-1.15.1/sha512.ml      2021-10-04 14:49:31.000000000 +0200
@@ -27,7 +27,10 @@
 external copy : ctx -> ctx = "stub_sha512_copy"
 external to_bin: t -> string = "stub_sha512_to_bin"
 external to_hex: t -> string = "stub_sha512_to_hex"
+external of_bin: bytes -> t = "stub_sha256_of_bin"
+external of_hex: string -> t = "stub_sha256_of_hex"
 external file_fast: string -> t = "stub_sha512_file"
+external equal: t -> t -> bool = "stub_sha512_equal"
 
 let blksize = 4096
 
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/ocaml-sha-1.14/sha512.mli 
new/ocaml-sha-1.15.1/sha512.mli
--- old/ocaml-sha-1.14/sha512.mli       2021-03-15 09:17:31.000000000 +0100
+++ new/ocaml-sha-1.15.1/sha512.mli     2021-10-04 14:49:31.000000000 +0200
@@ -17,65 +17,65 @@
 
 (** SHA512 OCaml binding *)
 
-(** context type - opaque *)
+(** Context type - opaque. *)
 type ctx
 
-(** buffer type *)
+(** Buffer type. *)
 type buf = (int, Bigarray.int8_unsigned_elt, Bigarray.c_layout) 
Bigarray.Array1.t
 
-(** digest type - opaque *)
+(** Digest type - opaque. *)
 type t
 
-(** The zero digest *)
+(** The zero digest. *)
 val zero : t
 
-(** Create a new context *)
-external init: unit -> ctx = "stub_sha512_init"
+(** Create a new context. *)
+external init : unit -> ctx = "stub_sha512_init"
 
-(** Sha512.unsafe_update_substring ctx s ofs len updates the context
-    with the substring of s starting at character number ofs and
-    containing len characters. Unsafe: No range checking! *)
-external unsafe_update_substring: ctx -> string -> int -> int -> unit = 
"stub_sha512_update"
-
-(** Sha512.update_substring ctx s ofs len updates the context with the
-    substring of s starting at character number ofs and containing len
-    characters. *)
-val update_substring: ctx -> string -> int -> int -> unit
-
-(** Sha512.update_string ctx s updates the context with s. *)
-val update_string: ctx -> string -> unit
-
-(** Sha512.update_buffer ctx a updates the context with a.
-    Runs parallel to other threads if any exist. *)
-external update_buffer: ctx -> buf -> unit = "stub_sha512_update_bigarray"
+(** [Sha512.unsafe_update_substring ctx s ofs len] updates the context with the
+   substring of [s] starting at character number [ofs] and containing [len]
+   characters. Unsafe: No range checking! *)
+external unsafe_update_substring : ctx -> string -> int -> int -> unit = 
"stub_sha512_update"
+
+(** [Sha512.update_substring ctx s ofs len] updates the context with the
+   substring of [s] starting at character number [ofs] and containing [len]
+   characters. *)
+val update_substring : ctx -> string -> int -> int -> unit
+
+(** [Sha512.update_string ctx s] updates the context with [s]. *)
+val update_string : ctx -> string -> unit
+
+(** [Sha512.update_buffer ctx a] updates the context with [a]. Runs parallel to
+   other threads if any exist. *)
+external update_buffer : ctx -> buf -> unit = "stub_sha512_update_bigarray"
 
-(** Finalize the context and return digest *)
-external finalize: ctx -> t = "stub_sha512_finalize"
+(** Finalize the context and return digest. *)
+external finalize : ctx -> t = "stub_sha512_finalize"
 
-(** Return an copy of the context *)
+(** Return a copy of the context. *)
 external copy : ctx -> ctx = "stub_sha512_copy"
 
 (** Return the digest of the given string. *)
 val string : string -> t
 
-(** Sha512.substring s ofs len returns the digest of the substring of s 
starting
-at character number ofs and containing len characters. *)
+(** [Sha512.substring s ofs len] returns the digest of the substring of [s]
+   starting at character number [ofs] and containing [len] characters. *)
 val substring : string -> int -> int -> t
 
 (** Return the digest of the given buffer. *)
 val buffer : buf -> t
 
-(** If len is nonnegative, Sha512.channel ic len reads len characters from
-channel ic and returns their digest, or raises End_of_file if end-of-file is
-reached before len characters are read. If len is negative, Sha512.channel ic
-len reads all characters from ic until end-of-file is reached and return their
-digest. *)
+(** If [len] is nonnegative, [Sha512.channel ic len] reads [len] characters 
from
+   channel [ic] and returns their digest, or raises [End_of_file] if 
end-of-file
+   is reached before [len] characters are read. If [len] is negative,
+   [Sha512.channel ic len] reads all characters from [ic] until end-of-file is
+   reached and return their digest. *)
 val channel : in_channel -> int -> t
 
 (** Return the digest of the file whose name is given. *)
 val file : string -> t
 
-(** Return the digest of the file whose name is given using fast C function *)
+(** Return the digest of the file whose name is given using fast C function. *)
 val file_fast : string -> t
 
 (** Write a digest on the given output channel. *)
@@ -84,8 +84,19 @@
 (** Read a digest from the given input channel. *)
 val input : in_channel -> t
 
-(** return a binary representation of the given digest *)
+(** Return a binary representation of the given digest. *)
 val to_bin : t -> string
 
-(** return a printable hexadecimal representation of the given digest *)
+(** Return a printable hexadecimal representation of the given digest. *)
 val to_hex : t -> string
+
+(** Returns whether two hashes are equal. *)
+val equal : t -> t -> bool
+
+(** Sha512.of_bin digest converts the binary representation of a digest to the
+   internal representation of Sha512.t. *)
+val of_bin : bytes -> t
+
+(** Sha512.of_hex digest converts the hexadecimal representation of a digest to
+   the internal representation of Sha512.t. *)
+val of_hex : string -> t
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/ocaml-sha-1.14/sha512_stubs.c 
new/ocaml-sha-1.15.1/sha512_stubs.c
--- old/ocaml-sha-1.14/sha512_stubs.c   2021-03-15 09:17:31.000000000 +0100
+++ new/ocaml-sha-1.15.1/sha512_stubs.c 2021-10-04 14:49:31.000000000 +0200
@@ -62,6 +62,11 @@
 #include <caml/bigarray.h>
 #include <caml/threads.h>
 
+#include <caml/version.h>
+#if OCAML_VERSION < 40600
+#define Bytes_val(x) ((unsigned char *) Bp_val(x))
+#endif
+
 #define GET_CTX_STRUCT(a) ((struct sha512_ctx *) a)
 
 CAMLexport value stub_sha512_init(value unit)
@@ -167,3 +172,32 @@
 
        CAMLreturn(result);
 }
+
+CAMLprim value stub_sha512_equal(value t1, value t2)
+{
+       CAMLparam2(t1, t2);
+       int b = memcmp((sha512_digest *) t1, (sha512_digest *) t2, 
sizeof(sha512_digest)) == 0;
+       CAMLreturn(Bool_val(b));
+}
+
+CAMLprim value stub_sha512_of_bin(value bin)
+{
+       CAMLparam1(bin);
+       CAMLlocal1(result);
+
+       result = caml_alloc(sizeof(sha512_digest), Abstract_tag);
+       sha512_of_bin((const char *) Bytes_val(bin), (sha512_digest *) result);
+
+       CAMLreturn(result);
+}
+
+CAMLprim value stub_sha512_of_hex(value hex)
+{
+       CAMLparam1(hex);
+       CAMLlocal1(result);
+
+       result = caml_alloc(sizeof(sha512_digest), Abstract_tag);
+       sha512_of_hex(String_val(hex), (sha512_digest *) result);
+
+       CAMLreturn(result);
+}
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/ocaml-sha-1.14/test/dune 
new/ocaml-sha-1.15.1/test/dune
--- old/ocaml-sha-1.14/test/dune        2021-03-15 09:17:31.000000000 +0100
+++ new/ocaml-sha-1.15.1/test/dune      2021-10-04 14:49:31.000000000 +0200
@@ -6,9 +6,10 @@
 (executable
  (name shatest)
  (modules shatest)
- (libraries sha oUnit))
+ (libraries sha ounit2))
 
 (rule
  (alias runtest)
  (deps sample.txt)
- (action (run ./shatest.exe)))
+ (action
+  (run ./shatest.exe)))
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/ocaml-sha-1.14/test/shatest.ml 
new/ocaml-sha-1.15.1/test/shatest.ml
--- old/ocaml-sha-1.14/test/shatest.ml  2021-03-15 09:17:31.000000000 +0100
+++ new/ocaml-sha-1.15.1/test/shatest.ml        2021-10-04 14:49:31.000000000 
+0200
@@ -69,9 +69,13 @@
        [ ("sample.txt",
        
"07e547d9586f6a73f73fbac0435ed76951218fb7d0c8d788a309d785436bbb642e93a252a954f23912547d1e8a3b5ed6e1bfd7097821233fa0538f3db854fee6")
 ]
 
-let stringfct_sha1 s = Sha1.to_hex (Sha1.string s)
-let stringfct_sha256 s = Sha256.to_hex (Sha256.string s)
-let stringfct_sha512 s = Sha512.to_hex (Sha512.string s)
+let stringfct_hex_sha1 s = Sha1.to_hex (Sha1.string s)
+let stringfct_hex_sha256 s = Sha256.to_hex (Sha256.string s)
+let stringfct_hex_sha512 s = Sha512.to_hex (Sha512.string s)
+
+let stringfct_bin_sha1 s = Sha1.to_bin (Sha1.string s)
+let stringfct_bin_sha256 s = Sha256.to_bin (Sha256.string s)
+let stringfct_bin_sha512 s = Sha512.to_bin (Sha512.string s)
 
 let filefct_sha1 s = Sha1.to_hex (Sha1.file s)
 let filefct_sha256 s = Sha256.to_hex (Sha256.file s)
@@ -94,25 +98,55 @@
                close_in chan;
                assert_equal r digest) arr
 
+let test_equal string eq arr _ =
+  List.fold_left (fun s (s', _) ->
+       if s = s' then
+               assert_bool "sha eq failed" (eq (string s) (string s'))
+       else
+               assert_bool "sha neq failed" (not (eq (string s) (string s')));
+       s)
+       (List.hd arr |> fst) arr |> ignore
+
+let test_of stringfct_to stringfct_of arr _ =
+       List.iter (fun (s,_) -> assert_equal (stringfct_to s) (stringfct_of s)) 
arr
+
 let suite = "SHA binding test" >:::
        [ "SHA1 example strings" >::
-               test_strings stringfct_sha1 ex_strings_sha1;
+               test_strings stringfct_hex_sha1 ex_strings_sha1;
          "SHA1 reading a file" >::
                test_file filefct_sha1 ex_files_sha1;
          "SHA1 reading few byte from channel" >::
                test_channel channelfct_sha1 ex_channels_sha1;
+         "SHA1 equality" >::
+               test_equal Sha1.string Sha1.equal ex_strings_sha1;
+         "SHA1 converting from binary representation" >::
+               test_of stringfct_bin_sha1 (fun s -> Sha1.(string s |> to_bin 
|> Bytes.of_string |> of_bin |> to_bin)) ex_strings_sha1;
+         "SHA1 converting from hexadecimal representation" >::
+               test_of stringfct_hex_sha1 (fun s -> Sha1.(string s |> to_hex 
|> of_hex |> to_hex)) ex_strings_sha1;
          "SHA256 example strings" >::
-               test_strings stringfct_sha256 ex_strings_sha256;
+               test_strings stringfct_hex_sha256 ex_strings_sha256;
          "SHA256 reading a file" >::
                test_file filefct_sha256 ex_files_sha256;
          "SHA256 reading few byte from channel" >::
                test_channel channelfct_sha256 ex_channels_sha256;
+         "SHA256 equality" >::
+               test_equal Sha256.string Sha256.equal ex_strings_sha256;
+         "SHA256 converting from binary representation" >::
+               test_of stringfct_bin_sha256 (fun s -> Sha256.(string s |> 
to_bin |> Bytes.of_string |> of_bin |> to_bin)) ex_strings_sha256;
+         "SHA256 converting from hexadecimal representation" >::
+               test_of stringfct_hex_sha256 (fun s -> Sha256.(string s |> 
to_hex |> of_hex |> to_hex)) ex_strings_sha256;
          "SHA512 example strings" >::
-               test_strings stringfct_sha512 ex_strings_sha512;
+               test_strings stringfct_hex_sha512 ex_strings_sha512;
          "SHA512 reading a file" >::
                test_file filefct_sha512 ex_files_sha512;
          "SHA512 reading few byte from channel" >::
                test_channel channelfct_sha512 ex_channels_sha512;
+         "SHA512 equality" >::
+               test_equal Sha512.string Sha512.equal ex_strings_sha512;
+         "SHA1 converting from binary representation" >::
+               test_of stringfct_bin_sha1 (fun s -> Sha1.(string s |> to_bin 
|> Bytes.of_string |> of_bin |> to_bin)) ex_strings_sha1;
+         "SHA1 converting from hexadecimal representation" >::
+               test_of stringfct_hex_sha1 (fun s -> Sha1.(string s |> to_hex 
|> of_hex |> to_hex)) ex_strings_sha1;
        ]
 
 let _ = run_test_tt ~verbose:true suite
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/ocaml-sha-1.14/util.h new/ocaml-sha-1.15.1/util.h
--- old/ocaml-sha-1.14/util.h   1970-01-01 01:00:00.000000000 +0100
+++ new/ocaml-sha-1.15.1/util.h 2021-10-04 14:49:31.000000000 +0200
@@ -0,0 +1,35 @@
+#ifndef UTIL_H
+#define UTIL_H
+
+static int hex_to_int(char c)
+{
+    if ('0' <= c && c <= '9')
+        return c - '0';
+    else if ('a' <= c && c <= 'f')
+        return c - 'a' + 10;
+    else if ('A' <= c && c <= 'F')
+        return c - 'A' + 10;
+    else
+        return -1;
+}
+
+static int of_hex(unsigned char *dst, const char *src, int n)
+{
+    int i;
+
+    if (n % 2 != 0)
+        return -1;
+    for (i = 0; i < n/2; i++) {
+        int a, b;
+        a = hex_to_int(src[i*2]);
+        if(a < 0)
+            return -1;
+        b = hex_to_int(src[i*2 + 1]);
+        if(b < 0)
+            return -1;
+        dst[i] = a*16 + b;
+    }
+    return n/2;
+}
+
+#endif

Reply via email to