Signed-off-by: Magnus Therning <[email protected]>

 uuid/uuid.ml  |  24 +--------------------
 uuid/uuid.mli |  62 +++++++++++++++++++++++++++++++++-------------------------
 2 files changed, 37 insertions(+), 49 deletions(-)


# HG changeset patch
# User Magnus Therning <[email protected]>
# Date 1283529428 -3600
# Node ID a6aa72c10a1ab1e1f9a41cde012945d3a1a39d00
# Parent  81dbe94e62c30c70b15360a1c10418e2f6760e30
Minor clean-up in the UUID module.

Signed-off-by: Magnus Therning <[email protected]>

diff -r 81dbe94e62c3 -r a6aa72c10a1a uuid/uuid.ml
--- a/uuid/uuid.ml	Mon Aug 23 14:03:02 2010 +0100
+++ b/uuid/uuid.ml	Fri Sep 03 16:57:08 2010 +0100
@@ -11,9 +11,8 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU Lesser General Public License for more details.
  *)
-(** Type-safe UUIDs. *)
 
-(** Internally, a UUID is simply a string. *)
+(* Internally, a UUID is simply a string. *)
 type 'a t = string
 
 type cookie = string
@@ -31,7 +30,7 @@
 
 let cookie_of_string s = s
 
-(** FIXME: using /dev/random is too slow but using /dev/urandom is too
+(* FIXME: using /dev/random is too slow but using /dev/urandom is too
     deterministic. *)
 let dev_random = "/dev/urandom"
 
@@ -51,30 +50,11 @@
     uuid.(6) uuid.(7) uuid.(8) uuid.(9) uuid.(10) uuid.(11)
     uuid.(12) uuid.(13) uuid.(14) uuid.(15)
 
-(** Return a new random UUID *)
 let make_uuid() = uuid_of_int_array (read_random 16)
 
-(** Return a new random, big UUID (hopefully big and random enough to be
-    unguessable) *)
 let make_cookie() =
   let bytes = Array.to_list (read_random 64) in
   String.concat "" (List.map (Printf.sprintf "%1x") bytes)
-(*
-  let hexencode x = 
-    let nibble x =
-      char_of_int (if x < 10 
-		   then int_of_char '0' + x
-		   else int_of_char 'a' + (x - 10)) in
-    let result = String.make (String.length x * 2) ' ' in
-    for i = 0 to String.length x - 1 do
-      let byte = int_of_char x.[i] in
-      result.[i * 2 + 0] <- nibble((byte lsr 4) land 15);
-      result.[i * 2 + 1] <- nibble((byte lsr 0) land 15);
-    done;
-    result in
-  let n = 64 in
-  hexencode (String.concat "" (List.map (fun x -> String.make 1 (char_of_int x)) (Array.to_list (read_n_random_bytes n))))
-*)
 
 let int_array_of_uuid s =
   try
diff -r 81dbe94e62c3 -r a6aa72c10a1a uuid/uuid.mli
--- a/uuid/uuid.mli	Mon Aug 23 14:03:02 2010 +0100
+++ b/uuid/uuid.mli	Fri Sep 03 16:57:08 2010 +0100
@@ -13,43 +13,51 @@
  *)
 (** Type-safe UUIDs.
     Probably need to refactor this; UUIDs are used in two places:
-    1. to uniquely name things across the cluster
-    2. as secure session IDs
+    + to uniquely name things across the cluster
+    + as secure session IDs
+
     There is the additional constraint that current Xen tools use 
     a particular format of UUID (the 16 byte variety generated by fresh ())
+
+	Also, cookies aren't UUIDs and should be put somewhere else.
 *)
 
-(** A 128-bit UUID referencing a value of type 'a. *)
+(** A 128-bit UUID.  Using phantom types ('a) to achieve the requires type-safety. *)
 type 'a t
 
-(** A 512-bit UUID. *)
+(** Create a fresh UUID *)
+val make_uuid : unit -> 'a t
+
+(** Create a UUID from a string. *)
+val of_string : string -> 'a t
+
+(** Marshal a UUID to a string. *)
+val to_string : 'a t -> string
+
+(** A null UUID, as if such a thing actually existed.  It turns out to be
+ * useful though. *)
+val null : 'a t
+
+(** Deprecated alias for {! Uuid.of_string} *)
+val uuid_of_string : string -> 'a t
+
+(** Deprecated alias for {! Uuid.to_string} *)
+val string_of_uuid : 'a t -> string
+
+(** Convert an array to a UUID. *)
+val uuid_of_int_array : int array -> 'a t
+
+(** Convert a UUID to an array. *)
+val int_array_of_uuid : 'a t -> int array
+
+(** Check whether a string is a UUID. *)
+val is_uuid : string -> bool
+
+(** A 512-bit cookie. *)
 type cookie
 
-(** Create a fresh (unique!) UUID *)
-val make_uuid : unit -> 'a t
-
-(** Create a fresh secure (bigger and hopefully unguessable) UUID *)
 val make_cookie : unit -> cookie
 
-(** Create a type-safe UUID. *)
-val of_string : string -> 'a t
-
-(** Marshal a UUID to a (type-unsafe) string. *)
-val to_string : 'a t -> string
-
-val null : 'a t
-
-(* deprecated alias for previous one *)
-val uuid_of_string : string -> 'a t
-val string_of_uuid : 'a t -> string
-
 val cookie_of_string : string -> cookie
 
 val string_of_cookie : cookie -> string
-
-val uuid_of_int_array : int array -> 'a t
-
-val int_array_of_uuid : 'a t -> int array
-
-(* check if a string is a uuid *)
-val is_uuid : string -> bool
_______________________________________________
xen-api mailing list
[email protected]
http://lists.xensource.com/mailman/listinfo/xen-api

Reply via email to