-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
107 additions
and
5 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
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,30 @@ | ||
open Elykseer_crypto | ||
open Mlcpp_cstdio | ||
open Mlcpp_filesystem | ||
|
||
let msg = "1234567890123456789012345678901234567890123456789012345678901234" | ||
|
||
let read_file fn = | ||
Cstdio.File.fopen fn "rb" |> function | ||
| Ok fptr -> begin | ||
let sz = Filesystem.Path.file_size (Filesystem.Path.from_string fn) in | ||
let buf = Cstdio.File.Buffer.create sz in | ||
Cstdio.File.fread buf sz fptr |> function | ||
| Ok cnt -> | ||
Ok (cnt, buf) | ||
| Error (errno,errstr) -> | ||
Printf.printf "no:%d err:%s\n" errno errstr ; Error (-98) | ||
end | ||
| Error _ -> Error (-99) | ||
|
||
let md5file () = | ||
read_file "/bin/sh" |> function | ||
| Error code -> Printf.printf "Error: %d\n" code |> ignore | ||
| Ok (_cnt,buf) -> | ||
Md5.buffer buf |> Printf.printf "md5 of file: %s\n" | ||
|
||
let md5msg () = | ||
Md5.string msg |> Printf.printf "md5 of msg: %s\n" | ||
|
||
let () = | ||
md5file () ; md5msg () |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// OCaml includes | ||
extern "C" { | ||
#include <caml/mlvalues.h> | ||
#include <caml/memory.h> | ||
#include <caml/alloc.h> | ||
// #include <caml/bigarray.h> | ||
// #include <caml/custom.h> | ||
// #include <caml/callback.h> | ||
// #include <caml/fail.h> | ||
|
||
#include <sys/errno.h> | ||
} //extern C | ||
|
||
// C++ includes | ||
#include <string> | ||
#include <filesystem> | ||
|
||
#include "lxr/key128.hpp" | ||
#include "lxr/md5.hpp" | ||
|
||
using namespace lxr; | ||
|
||
struct _cpp_cstdio_buffer { | ||
char *_buf {nullptr}; | ||
long _len {0}; | ||
}; | ||
|
||
#define CPP_CSTDIO_BUFFER(v) (*((_cpp_cstdio_buffer**) Data_custom_val(v))) | ||
|
||
/* | ||
* cpp_string_md5 : string -> string | ||
*/ | ||
extern "C" { | ||
value cpp_string_md5(value vs) | ||
{ | ||
CAMLparam1(vs); | ||
const char *s = String_val(vs); | ||
const int len = caml_string_length(vs); | ||
auto k = lxr::Md5::hash(s, len); | ||
CAMLreturn(caml_copy_string(k.toHex().c_str())); | ||
} | ||
} // extern C | ||
|
||
/* | ||
* cpp_buffer_md5 : buffer -> string | ||
*/ | ||
extern "C" { | ||
value cpp_buffer_md5(value vb) | ||
{ | ||
CAMLparam1(vb); | ||
struct _cpp_cstdio_buffer *b = CPP_CSTDIO_BUFFER(vb); | ||
auto k = lxr::Md5::hash(b->_buf, b->_len); | ||
CAMLreturn(caml_copy_string(k.toHex().c_str())); | ||
} | ||
} // extern C |
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,5 @@ | ||
|
||
type b = Mlcpp_cstdio.Cstdio.File.Buffer.ta | ||
|
||
external string : string -> string = "cpp_string_md5" | ||
external buffer : b -> string = "cpp_buffer_md5" |
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,5 @@ | ||
|
||
type b = Mlcpp_cstdio.Cstdio.File.Buffer.ta | ||
|
||
val string : string -> string | ||
val buffer : b -> string |