update to ipaddr 4.0.0 & decompress 0.9.0
This commit is contained in:
parent
95a46638fa
commit
bf59b7b930
|
@ -9,7 +9,7 @@ depends: [
|
||||||
"ocaml" {>= "4.05.0"}
|
"ocaml" {>= "4.05.0"}
|
||||||
"dune" {build}
|
"dune" {build}
|
||||||
"lwt" {>= "3.0.0"}
|
"lwt" {>= "3.0.0"}
|
||||||
"ipaddr" {>= "2.9.0"}
|
"ipaddr" {>= "4.0.0"}
|
||||||
"hex"
|
"hex"
|
||||||
"cstruct"
|
"cstruct"
|
||||||
"logs"
|
"logs"
|
||||||
|
@ -24,7 +24,7 @@ depends: [
|
||||||
"nocrypto"
|
"nocrypto"
|
||||||
"asn1-combinators" {>= "0.2.0"}
|
"asn1-combinators" {>= "0.2.0"}
|
||||||
"duration"
|
"duration"
|
||||||
"decompress" {>= "0.8.1"}
|
"decompress" {>= "0.9.0"}
|
||||||
"checkseum"
|
"checkseum"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -24,8 +24,8 @@ let projections_of asn =
|
||||||
(decode_strict c, Asn.encode c)
|
(decode_strict c, Asn.encode c)
|
||||||
|
|
||||||
let ipv4 =
|
let ipv4 =
|
||||||
let f cs = Ipaddr.V4.of_bytes_exn (Cstruct.to_string cs)
|
let f cs = Ipaddr.V4.of_octets_exn (Cstruct.to_string cs)
|
||||||
and g ip = Cstruct.of_string (Ipaddr.V4.to_bytes ip)
|
and g ip = Cstruct.of_string (Ipaddr.V4.to_octets ip)
|
||||||
in
|
in
|
||||||
Asn.S.map f g Asn.S.octet_string
|
Asn.S.map f g Asn.S.octet_string
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
(* copied n 2018-03-18 from github.com:mirage/decompress.git (bin/easy.ml)
|
(* copied n 2018-03-18 from github.com:mirage/decompress.git (bin/easy.ml)
|
||||||
(MIT licensed) at fa1551b19165503fc77da6da99411fa59b6a7f6a by Hannes Mehnert
|
(MIT licensed) at fa1551b19165503fc77da6da99411fa59b6a7f6a by Hannes Mehnert
|
||||||
*)
|
*)
|
||||||
|
(* edited to reflect later API (v0.9.0) changes on 2019-07-16 *)
|
||||||
|
module Stdlib_buffer = Buffer
|
||||||
open Decompress
|
open Decompress
|
||||||
|
|
||||||
(* Keep in your mind, this is an easy example of Decompress but not efficient.
|
(* Keep in your mind, this is an easy example of Decompress but not efficient.
|
||||||
|
@ -22,7 +23,7 @@ let compress ?(level = 4) data =
|
||||||
(* We need to allocate an output buffer, is like you can. it's depends your
|
(* We need to allocate an output buffer, is like you can. it's depends your
|
||||||
capabilities of your writing. *)
|
capabilities of your writing. *)
|
||||||
let pos = ref 0 in
|
let pos = ref 0 in
|
||||||
let res = Buffer.create (String.length data) in
|
let res = Stdlib_buffer.create (String.length data) in
|
||||||
(* The buffer is not a good idea. In fact, we can have a memory problem with
|
(* The buffer is not a good idea. In fact, we can have a memory problem with
|
||||||
that (like if the output is too big). You need to keep in your mind that
|
that (like if the output is too big). You need to keep in your mind that
|
||||||
is insecure to let a buffer to grow automatically (an attacker can use
|
is insecure to let a buffer to grow automatically (an attacker can use
|
||||||
|
@ -66,13 +67,13 @@ let compress ?(level = 4) data =
|
||||||
pos := !pos + n ;
|
pos := !pos + n ;
|
||||||
n )
|
n )
|
||||||
(fun output_buffer len ->
|
(fun output_buffer len ->
|
||||||
Buffer.add_subbytes res output_buffer 0 len ;
|
Stdlib_buffer.add_subbytes res output_buffer 0 len ;
|
||||||
0xFFFF )
|
0xFFFF )
|
||||||
(Zlib_deflate.default ~witness:B.bytes level)
|
(Zlib_deflate.default ~witness:Buffer.bytes level)
|
||||||
(* We can specify the level of the compression, see the documentation to know
|
(* We can specify the level of the compression, see the documentation to know
|
||||||
what we use for each level. The default is 4. *)
|
what we use for each level. The default is 4. *)
|
||||||
|> function
|
|> function
|
||||||
| Ok _ -> Buffer.contents res
|
| Ok _ -> Stdlib_buffer.contents res
|
||||||
| Error e ->
|
| Error e ->
|
||||||
Logs.err (fun m -> m "error %a while compressing" Zlib_deflate.pp_error e) ;
|
Logs.err (fun m -> m "error %a while compressing" Zlib_deflate.pp_error e) ;
|
||||||
invalid_arg "cannot compress"
|
invalid_arg "cannot compress"
|
||||||
|
@ -83,7 +84,7 @@ let uncompress data =
|
||||||
your reading. *)
|
your reading. *)
|
||||||
let output_buffer = Bytes.create 0xFFFF in
|
let output_buffer = Bytes.create 0xFFFF in
|
||||||
(* Same as [compress]. *)
|
(* Same as [compress]. *)
|
||||||
let window = Window.create ~witness:B.bytes in
|
let window = Window.create ~crc:Window.adler32 ~witness:Buffer.bytes in
|
||||||
(* We allocate a window. We let the user to do that to reuse the window if
|
(* We allocate a window. We let the user to do that to reuse the window if
|
||||||
it's needed. In fact, the window is a big buffer ([size = (1 << 15)]) and
|
it's needed. In fact, the window is a big buffer ([size = (1 << 15)]) and
|
||||||
allocate this buffer costs.
|
allocate this buffer costs.
|
||||||
|
@ -91,7 +92,7 @@ let uncompress data =
|
||||||
So in this case, we decompress only one time but if you want to decompress
|
So in this case, we decompress only one time but if you want to decompress
|
||||||
some flows, you can reuse this window after a [Window.reset]. *)
|
some flows, you can reuse this window after a [Window.reset]. *)
|
||||||
let pos = ref 0 in
|
let pos = ref 0 in
|
||||||
let res = Buffer.create (String.length data) in
|
let res = Stdlib_buffer.create (String.length data) in
|
||||||
Zlib_inflate.bytes input_buffer output_buffer
|
Zlib_inflate.bytes input_buffer output_buffer
|
||||||
(* Same logic as [compress]. *)
|
(* Same logic as [compress]. *)
|
||||||
(fun input_buffer ->
|
(fun input_buffer ->
|
||||||
|
@ -100,11 +101,11 @@ let uncompress data =
|
||||||
pos := !pos + n ;
|
pos := !pos + n ;
|
||||||
n )
|
n )
|
||||||
(fun output_buffer len ->
|
(fun output_buffer len ->
|
||||||
Buffer.add_subbytes res output_buffer 0 len ;
|
Stdlib_buffer.add_subbytes res output_buffer 0 len ;
|
||||||
0xFFFF )
|
0xFFFF )
|
||||||
(Zlib_inflate.default ~witness:B.bytes window)
|
(Zlib_inflate.default ~witness:Buffer.bytes window)
|
||||||
|> function
|
|> function
|
||||||
| Ok _ -> Ok (Buffer.contents res)
|
| Ok _ -> Ok (Stdlib_buffer.contents res)
|
||||||
| Error exn ->
|
| Error exn ->
|
||||||
Logs.err (fun m -> m "error %a while uncompressing" Zlib_inflate.pp_error exn) ;
|
Logs.err (fun m -> m "error %a while uncompressing" Zlib_inflate.pp_error exn) ;
|
||||||
Error ()
|
Error ()
|
||||||
|
|
Loading…
Reference in a new issue