-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #149 from mirage/get_into_bytes
Implement get_into_bytes
- Loading branch information
Showing
8 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
(executable | ||
(name fuzz) | ||
(libraries digestif.c crowbar)) | ||
|
||
(rule | ||
(copy# ../fuzz.ml fuzz.ml)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
(rule | ||
(copy# fuzz.ml fuzz_c.ml)) | ||
|
||
(rule | ||
(copy# fuzz.ml fuzz_ocaml.ml)) | ||
|
||
(executable | ||
(name fuzz_c) | ||
(modules fuzz_c) | ||
(libraries digestif.c crowbar)) | ||
|
||
(executable | ||
(name fuzz_ocaml) | ||
(modules fuzz_ocaml) | ||
(libraries digestif.ocaml crowbar)) | ||
|
||
(rule | ||
(alias runtest) | ||
(action | ||
(run ./fuzz_ocaml.exe))) | ||
|
||
(rule | ||
(alias runtest) | ||
(action | ||
(run ./fuzz_c.exe))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
open Crowbar | ||
|
||
type pack = Pack : 'a Digestif.hash -> pack | ||
|
||
let hash = | ||
choose | ||
[ | ||
const (Pack Digestif.sha1); const (Pack Digestif.sha256); | ||
const (Pack Digestif.sha512); | ||
] | ||
|
||
let with_get_into_bytes off len (type ctx) | ||
(module Hash : Digestif.S with type ctx = ctx) (ctx : ctx) = | ||
let buf = Bytes.create len in | ||
let () = | ||
try Hash.get_into_bytes ctx ~off buf | ||
with Invalid_argument e -> ( | ||
(* Skip if the invalid argument is valid; otherwise fail *) | ||
match Bytes.sub buf off Hash.digest_size with | ||
| _ -> failf "Hash.get_into_bytes: Invalid_argument %S" e | ||
| exception Invalid_argument _ -> bad_test ()) in | ||
Bytes.sub_string buf off Hash.digest_size | ||
|
||
let () = | ||
add_test ~name:"get_into_bytes" [ hash; int8; range 1024; bytes ] | ||
@@ fun (Pack hash) off len bytes -> | ||
let (module Hash) = Digestif.module_of hash in | ||
let ctx = Hash.empty in | ||
let ctx = Hash.feed_string ctx bytes in | ||
let a = with_get_into_bytes off len (module Hash) ctx in | ||
let b = Hash.(to_raw_string (get ctx)) in | ||
check_eq ~eq:String.equal a b |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
(executable | ||
(name fuzz) | ||
(libraries digestif.ocaml crowbar)) | ||
|
||
(rule | ||
(copy# ../fuzz.ml fuzz.ml)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters