Skip to content

Commit

Permalink
Merge pull request #86 from mirage/assert
Browse files Browse the repository at this point in the history
Insert an explained assert false on a impossible case on finalizer
  • Loading branch information
dinosaure authored Jul 6, 2019
2 parents d721a3a + 2bf7170 commit d2a23c0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 5 additions & 3 deletions src-ocaml/baijiu_blake2b.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module By = Digestif_by
module Bi = Digestif_bi

let failwith fmt = Format.kasprintf failwith fmt

module Int32 = struct
include Int32

Expand Down Expand Up @@ -309,6 +311,7 @@ module Unsafe : S = struct
feed ~blit:By.blit_from_bigstring ~le64_to_cpu:Bi.le64_to_cpu

let with_outlen_and_key ~blit outlen key off len =
if outlen > max_outlen then failwith "out length can not be upper than %d (out length: %d)" max_outlen outlen ;
let buf = By.make 128 '\x00' in
let ctx =
{ buflen= 0
Expand Down Expand Up @@ -348,9 +351,8 @@ module Unsafe : S = struct
done ;
if ctx.outlen < default_param.digest_length
then By.sub res 0 ctx.outlen
(* XXX(dinosaure): should never appear! *)
else if ctx.outlen > default_param.digest_length
then ( let res' = By.make ctx.outlen '\x00' in
By.blit res 0 res' 0 default_param.digest_length ; res' )
then assert false
(* XXX(dinosaure): [ctx] can not be initialized with [outlen > digest_length = max_outlen]. *)
else res
end
8 changes: 5 additions & 3 deletions src-ocaml/baijiu_blake2s.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module By = Digestif_by
module Bi = Digestif_bi

let failwith fmt = Format.kasprintf failwith fmt

module Int32 = struct
include Int32

Expand Down Expand Up @@ -269,6 +271,7 @@ module Unsafe : S = struct
feed ~blit:By.blit_from_bigstring ~le32_to_cpu:Bi.le32_to_cpu

let with_outlen_and_key ~blit outlen key off len =
if outlen > max_outlen then failwith "out length can not be upper than %d (out length: %d)" max_outlen outlen ;
let buf = By.make 64 '\x00' in
let ctx =
{ buflen= 0
Expand Down Expand Up @@ -308,9 +311,8 @@ module Unsafe : S = struct
done ;
if ctx.outlen < default_param.digest_length
then By.sub res 0 ctx.outlen
(* XXX(dinosaure): should never appear! *)
else if ctx.outlen > default_param.digest_length
then ( let res' = By.make ctx.outlen '\x00' in
By.blit res 0 res' 0 default_param.digest_length ; res' )
then assert false
(* XXX(dinosaure): [ctx] can not be initialized with [outlen > digest_length = max_outlen]. *)
else res
end

0 comments on commit d2a23c0

Please sign in to comment.