Skip to content

Commit

Permalink
Merge pull request #19 from mirage/link
Browse files Browse the repository at this point in the history
Link
  • Loading branch information
dinosaure authored Dec 7, 2017
2 parents 7d7884d + 439e231 commit 045117b
Show file tree
Hide file tree
Showing 30 changed files with 265 additions and 241 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ _tests
lib_test/files
zpipe
c/dpipe
*.install
*~
10 changes: 6 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ env:
matrix:
- PACKAGE="digestif" OCAML_VERSION=4.03 TESTS=false

- PACKAGE="digestif-test-c" OCAML_VERSION=4.03 INSTALL=false TESTS=true
PINS=$(if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then echo -n "digestif:https://github.com/$TRAVIS_PULL_REQUEST_SLUG.git"; if [ ! -z $TRAVIS_PULL_REQUEST_BRANCH ]; then echo -n "#$TRAVIS_PULL_REQUEST_BRANCH"; fi else echo -n "digestif:https://github.com/$TRAVIS_REPO_SLUG.git"; if [ ! -z $TRAVIS_BRANCH ]; then echo -n "#$TRAVIS_BRANCH"; fi fi)
- PACKAGE="digestif" OCAML_VERSION=4.03 INSTALL=false
PINS="digestif-test-c:test"
EXTRA_DEPS="digestif-test-c"

- PACKAGE="digestif-test-ocaml" OCAML_VERSION=4.03 INSTALL=false TESTS=true
PINS=$(if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then echo -n "digestif:https://github.com/$TRAVIS_PULL_REQUEST_SLUG.git"; if [ ! -z $TRAVIS_PULL_REQUEST_BRANCH ]; then echo -n "#$TRAVIS_PULL_REQUEST_BRANCH"; fi else echo -n "digestif:https://github.com/$TRAVIS_REPO_SLUG.git"; if [ ! -z $TRAVIS_BRANCH ]; then echo -n "#$TRAVIS_BRANCH"; fi fi)
- PACKAGE="digestif" OCAML_VERSION=4.03 INSTALL=false
PINS="digestif-test-ocaml:test"
EXTRA_DEPS="digestif-test-ocaml"
4 changes: 2 additions & 2 deletions _tags
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
true: safe_string, bin_annot

# <common>: include (not needed to the binary test)
<src-c/digestif.{cma,cmxa}>: record_digestif_rakia_stubs
<src>: include
<src-c/digestif-c.{cma,cmxa}>: record_digestif_rakia_stubs
<src-c/digestif.cmxs>: link_digestif_rakia_stubs, use_bigarray
<src-ocaml/digestif.cmxs>: use_bigarray
<test/*.{ml,mli,byte,native}>: package(alcotest), package(cstruct)
28 changes: 16 additions & 12 deletions pkg/META
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
version = "%%VERSION%%"
requires = "bigarray"
description = "Interface of the library"
archive(byte) = "digestif.cma"
archive(native) = "digestif.cmxa"
plugin(byte) = "digestif.cma"
plugin(native) = "digestif.cmxs"

package "c" (
directory = "c"
version = "%%VERSION%%"
description = "Implementation of hash function in C"
requires = "bigarray"
archive(byte) = "digestif.cma"
archive(native) = "digestif.cmxa"
plugin(byte) = "digestif.cma"
plugin(native) = "digestif.cmxs"
exists_if = "digestif.cma"
requires = "bigarray digestif"
archive(byte) = "digestif-c.cma"
archive(native) = "digestif-c.cmxa"
plugin(byte) = "digestif-c.cma"
plugin(native) = "digestif-c.cmxs"
exists_if = "digestif-c.cma"
)

package "ocaml" (
directory = "ocaml"
version = "%%VERSION%%"
description = "Implementation of hash function in OCaml"
requires = "bigarray"
archive(byte) = "digestif.cma"
archive(native) = "digestif.cmxa"
plugin(byte) = "digestif.cma"
plugin(native) = "digestif.cmxs"
exists_if = "digestif.cma"
requires = "bigarray digestif"
archive(byte) = "digestif-ocaml.cma"
archive(native) = "digestif-ocaml.cmxa"
plugin(byte) = "digestif-ocaml.cma"
plugin(native) = "digestif-ocaml.cmxs"
exists_if = "digestif-ocaml.cma"
)
7 changes: 4 additions & 3 deletions pkg/pkg.ml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ let () =
; Pkg.doc "CHANGES.md"

; Pkg.clib "src-c/librakia_stubs.clib" ~lib_dst_dir:"c"
; Pkg.lib "common/digestif.cmi" ~dst:"digestif.cmi"
; Pkg.mllib ~api:["Digestif"] "src-c/digestif.mllib" ~dst_dir:"c"
; Pkg.mllib ~api:["Digestif"] "src-ocaml/digestif.mllib" ~dst_dir:"ocaml" ]
; Pkg.lib "src/digestif_sig.cmi" ~dst:"digestif_sig.cmi"
; Pkg.mllib "src/digestif.mllib"
; Pkg.mllib ~api:["Digestif"] "src-c/digestif-c.mllib" ~dst_dir:"c"
; Pkg.mllib ~api:["Digestif"] "src-ocaml/digestif-ocaml.mllib" ~dst_dir:"ocaml" ]
2 changes: 2 additions & 0 deletions src-c/digestif-c.mllib
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Digestif
Rakia_native
110 changes: 21 additions & 89 deletions src-c/digestif.ml
Original file line number Diff line number Diff line change
@@ -1,67 +1,12 @@
module type S = Digestif_sig.S
module type T = Digestif_sig.T

module Bi = Digestif_bigstring
module By = Digestif_bytes
module Pp = Digestif_pp
module Native = Rakia_native

module type S =
sig
val digest_size : int

module Bigstring :
sig
type buffer = Native.ba
type ctx
type t = Native.ba

val init : unit -> ctx
val feed : ctx -> buffer -> unit
val feed_bytes : ctx -> By.t -> unit
val feed_bigstring : ctx -> Bi.t -> unit
val get : ctx -> t

val digest : buffer -> t
val digestv : buffer list -> t
val hmac : key:buffer -> buffer -> t
val hmacv : key:buffer -> buffer list -> t

val compare : t -> t -> int
val eq : t -> t -> bool
val neq : t -> t -> bool

val pp : Format.formatter -> t -> unit
val of_hex : buffer -> t
val to_hex : t -> buffer
end

module Bytes :
sig
type buffer = Native.st
type ctx
type t = Native.st

val init : unit -> ctx
val feed : ctx -> buffer -> unit
val feed_bytes : ctx -> By.t -> unit
val feed_bigstring : ctx -> Bi.t -> unit
val get : ctx -> t

val digest : buffer -> t
val digestv : buffer list -> t
val hmac : key:buffer -> buffer -> t
val hmacv : key:buffer -> buffer list -> t

val compare : t -> t -> int
val eq : t -> t -> bool
val neq : t -> t -> bool

val pp : Format.formatter -> t -> unit
val of_hex : buffer -> t
val to_hex : t -> buffer
end
end

module type Foreign =
sig
module type Foreign = sig
open Native

module Bigstring :
Expand All @@ -87,17 +32,15 @@ sig
val digest_size : int
end

module type Convenience =
sig
module type Convenience = sig
type t

val compare : t -> t -> int
val eq : t -> t -> bool
val neq : t -> t -> bool
end

module Core (F : Foreign) (D : Desc) =
struct
module Core (F : Foreign) (D : Desc) = struct
let block_size = D.block_size
and digest_size = D.digest_size
and ctx_size = F.ctx_size ()
Expand Down Expand Up @@ -134,8 +77,7 @@ struct
let t = init () in ( List.iter (feed t) bufs; get t )
end

module Bigstring =
struct
module Bigstring = struct
type buffer = Native.ba
type ctx = Native.ctx

Expand Down Expand Up @@ -167,8 +109,7 @@ struct
end
end

module Make (F : Foreign) (D : Desc) =
struct
module Make (F : Foreign) (D : Desc) = struct
type ctx = Native.ctx

module C = Core (F) (D)
Expand Down Expand Up @@ -199,8 +140,7 @@ struct
let hmac ~key msg = hmacv ~key [ msg ]
end

module Bigstring =
struct
module Bigstring = struct
include C.Bigstring

let opad = Bi.init C.block_size (fun _ -> '\x5c')
Expand All @@ -222,8 +162,7 @@ struct
end
end

module type ForeignExt =
sig
module type ForeignExt = sig
open Native

module Bigstring :
Expand All @@ -246,8 +185,7 @@ sig
val key_size : unit -> int
end

module Make_BLAKE2 (F : ForeignExt) (D : Desc) : S =
struct
module Make_BLAKE2 (F : ForeignExt) (D : Desc) : Digestif_sig.S = struct
let block_size = D.block_size
and digest_size = D.digest_size
and ctx_size = F.ctx_size ()
Expand Down Expand Up @@ -296,8 +234,7 @@ struct
hmacv ~key [ msg ]
end

module Bigstring =
struct
module Bigstring = struct
type buffer = Native.ba
type ctx = Native.ctx

Expand Down Expand Up @@ -353,16 +290,7 @@ module BLAKE2B = Make_BLAKE2(Native.BLAKE2B) (struct let (digest_size, block_siz
module BLAKE2S = Make_BLAKE2(Native.BLAKE2S) (struct let (digest_size, block_size) = (32, 64) end)
module RMD160 : S = Make (Native.RMD160) (struct let (digest_size, block_size) = (20, 64) end)

type hash =
[ `MD5
| `SHA1
| `SHA224
| `SHA256
| `SHA384
| `SHA512
| `BLAKE2B
| `BLAKE2S
| `RMD160 ]
type hash = Digestif_sig.hash

let module_of = function
| `MD5 -> (module MD5 : S)
Expand All @@ -375,8 +303,10 @@ let module_of = function
| `BLAKE2S -> (module BLAKE2S : S)
| `RMD160 -> (module RMD160 : S)

module Bytes =
struct
module Bytes = struct
type t = Bytes.t
type buffer = Bytes.t

let digest hash =
let module H = (val (module_of hash)) in
H.Bytes.digest
Expand Down Expand Up @@ -406,8 +336,10 @@ struct
H.Bytes.pp
end

module Bigstring =
struct
module Bigstring = struct
type t = Bi.t
type buffer = Bi.t

let digest hash =
let module H = (val (module_of hash)) in
H.Bigstring.digest
Expand Down
1 change: 0 additions & 1 deletion src-c/digestif.mli

This file was deleted.

23 changes: 23 additions & 0 deletions src-c/digestif.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module type S = Digestif_sig.S
module type T = Digestif_sig.T

type hash = Digestif_sig.hash

val digest_size : hash -> int

module MD5 : S
module SHA1 : S
module SHA224 : S
module SHA256 : S
module SHA384 : S
module SHA512 : S
module BLAKE2B : S
module BLAKE2S : S
module RMD160 : S

module Bytes : T
with type t = Bytes.t
and type buffer = Bytes.t
module Bigstring : T
with type t = Digestif_sig.Bigstring.t
and type buffer = Digestif_sig.Bigstring.t
5 changes: 0 additions & 5 deletions src-c/digestif.mllib

This file was deleted.

1 change: 0 additions & 1 deletion src-c/digestif_bigstring.ml

This file was deleted.

1 change: 0 additions & 1 deletion src-c/digestif_bytes.ml

This file was deleted.

1 change: 0 additions & 1 deletion src-c/digestif_pp.ml

This file was deleted.

3 changes: 0 additions & 3 deletions src-ocaml/digestif.mllib → src-ocaml/digestif-ocaml.mllib
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
Digestif
Digestif_pp
Digestif_bytes
Digestif_bigstring
Baijiu_xor
Baijiu_buffer
Baijiu_sha1
Expand Down
Loading

0 comments on commit 045117b

Please sign in to comment.