[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#663180: Provides no zero value



Package: ocaml-sha
Version: 1.7-2
Severity: wishlist
Tags: upstream patch

Hi,

I found myself in a situation where I needed to fill in a dummy Sha1.t
into a record to initialize an array. I didn't want to use an Sha1.t
option because the value is only every invalid during initialization
and an option type would mean extracting from "Some x" at every other
place.

The attached patch adds a Sha*.zero value that can be used for this
purpose.

MfG
	Goswin

-- System Information:
Debian Release: wheezy/sid
  APT prefers unstable
  APT policy: (500, 'unstable')
Architecture: amd64 (x86_64)

Kernel: Linux 3.1.0-1-amd64 (SMP w/4 CPU cores)
Locale: LANG=C, LC_CTYPE=de_DE (charmap=ISO-8859-1)
Shell: /bin/sh linked to /bin/dash
Description: zero value patch
 This patch adds a zero value (digest with all bits 0) to each of the
 Sha modules. This can be used as placeholder or invalid digest in
 situations where the proper digest can not be computed yet.
 .
 Technically a digest with all bits 0 is valid but the chance of it
 actually occuring is remote. Still, the value should be compared using
 physical equality.
 .
 TODO: should there be a 'val is_zero : t -> bool'?
Author: Goswin von Brederlow <goswin-v-b@web.de>
Last-Update: <2012-03-09>

---
The information above should follow the Patch Tagging Guidelines, please
checkout http://dep.debian.net/deps/dep3/ to learn about the format. Here
are templates for supplementary fields that you might want to add:

Origin: <vendor|upstream|other>, <url of original patch>
Bug: <url in upstream bugtracker>
Bug-Debian: http://bugs.debian.org/<bugnumber>
Bug-Ubuntu: https://launchpad.net/bugs/<bugnumber>
Forwarded: <no|not-needed|url proving that it has been forwarded>
Reviewed-By: <name and email of someone who approved the patch>

Index: ocaml-sha-1.7/sha1_stubs.c
===================================================================
--- ocaml-sha-1.7.orig/sha1_stubs.c	2012-03-09 07:36:37.000000000 +0100
+++ ocaml-sha-1.7/sha1_stubs.c	2012-03-09 07:36:48.000000000 +0100
@@ -111,3 +111,13 @@
 
 	CAMLreturn(result);
 }
+
+CAMLprim value stub_sha1_zero(void)
+{
+	CAMLlocal1(zero);
+
+	zero = caml_alloc(sizeof(sha1_digest), Abstract_tag);
+	memset(zero, 0, sizeof(sha1_digest));
+
+	CAMLreturn(zero);
+}
Index: ocaml-sha-1.7/sha1.mli
===================================================================
--- ocaml-sha-1.7.orig/sha1.mli	2012-03-09 07:36:37.000000000 +0100
+++ ocaml-sha-1.7/sha1.mli	2012-03-09 07:36:48.000000000 +0100
@@ -17,6 +17,9 @@
 (** digest type - opaque *)
 type t
 
+(** The zero digest *)
+val zero : t
+
 (** Return the digest of the given string. *)
 val string : string -> t
 
Index: ocaml-sha-1.7/sha1.ml
===================================================================
--- ocaml-sha-1.7.orig/sha1.ml	2012-03-09 07:36:37.000000000 +0100
+++ ocaml-sha-1.7/sha1.ml	2012-03-09 07:36:48.000000000 +0100
@@ -22,6 +22,9 @@
 external to_bin: t -> string = "stub_sha1_to_bin"
 external to_hex: t -> string = "stub_sha1_to_hex"
 external file_fast: string -> t = "stub_sha1_file"
+external sha1_zero : unit -> t = "stub_sha1_zero"
+
+let zero = sha1_zero ()
 
 let blksize = 4096
 
Index: ocaml-sha-1.7/sha512.mli
===================================================================
--- ocaml-sha-1.7.orig/sha512.mli	2012-03-09 07:36:35.000000000 +0100
+++ ocaml-sha-1.7/sha512.mli	2012-03-09 07:36:48.000000000 +0100
@@ -17,6 +17,9 @@
 (** digest type - opaque *)
 type t
 
+(** The zero digest *)
+val zero : t
+
 (** Return the digest of the given string. *)
 val string : string -> t
 
Index: ocaml-sha-1.7/sha256.ml
===================================================================
--- ocaml-sha-1.7.orig/sha256.ml	2012-03-09 07:36:35.000000000 +0100
+++ ocaml-sha-1.7/sha256.ml	2012-03-09 07:36:48.000000000 +0100
@@ -22,6 +22,9 @@
 external to_bin: t -> string = "stub_sha256_to_bin"
 external to_hex: t -> string = "stub_sha256_to_hex"
 external file_fast: string -> t = "stub_sha256_file"
+external sha1_zero : unit -> t = "stub_sha256_zero"
+
+let zero = sha256_zero ()
 
 let blksize = 4096
 
Index: ocaml-sha-1.7/sha256_stubs.c
===================================================================
--- ocaml-sha-1.7.orig/sha256_stubs.c	2012-03-09 07:36:35.000000000 +0100
+++ ocaml-sha-1.7/sha256_stubs.c	2012-03-09 07:36:48.000000000 +0100
@@ -110,3 +110,13 @@
 
 	CAMLreturn(result);
 }
+
+CAMLprim value stub_sha256_zero(void)
+{
+	CAMLlocal1(zero);
+
+	zero = caml_alloc(sizeof(sha256_digest), Abstract_tag);
+	memset(zero, 0, sizeof(sha256_digest));
+
+	CAMLreturn(zero);
+}
Index: ocaml-sha-1.7/sha512.ml
===================================================================
--- ocaml-sha-1.7.orig/sha512.ml	2012-03-09 07:36:35.000000000 +0100
+++ ocaml-sha-1.7/sha512.ml	2012-03-09 07:36:48.000000000 +0100
@@ -22,6 +22,9 @@
 external to_bin: t -> string = "stub_sha512_to_bin"
 external to_hex: t -> string = "stub_sha512_to_hex"
 external file_fast: string -> t = "stub_sha512_file"
+external sha1_zero : unit -> t = "stub_sha512_zero"
+
+let zero = sha512_zero ()
 
 let blksize = 4096
 
Index: ocaml-sha-1.7/sha512_stubs.c
===================================================================
--- ocaml-sha-1.7.orig/sha512_stubs.c	2012-03-09 07:36:36.000000000 +0100
+++ ocaml-sha-1.7/sha512_stubs.c	2012-03-09 07:36:48.000000000 +0100
@@ -110,3 +110,13 @@
 
 	CAMLreturn(result);
 }
+
+CAMLprim value stub_sha512_zero(void)
+{
+	CAMLlocal1(zero);
+
+	zero = caml_alloc(sizeof(sha512_digest), Abstract_tag);
+	memset(zero, 0, sizeof(sha512_digest));
+
+	CAMLreturn(zero);
+}
Index: ocaml-sha-1.7/sha256.mli
===================================================================
--- ocaml-sha-1.7.orig/sha256.mli	2012-03-09 07:36:36.000000000 +0100
+++ ocaml-sha-1.7/sha256.mli	2012-03-09 07:36:48.000000000 +0100
@@ -17,6 +17,9 @@
 (** digest type - opaque *)
 type t
 
+(** The zero digest *)
+val zero : t
+
 (** Return the digest of the given string. *)
 val string : string -> t
 

Reply to: