Skip to content

Commit

Permalink
Get rid of encode_mpint.
Browse files Browse the repository at this point in the history
  • Loading branch information
haesbaert committed Feb 16, 2017
1 parent 2e69ea6 commit 752752f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/kex.ml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ type keys = {
}

let derive_keys digestv k h session_id need =
let k = encode_mpint k in
let k = Buf.(to_cstruct @@ add_mpint k (create ())) in
let x = Cstruct.create 1 in
let rec expand kn =
if (Cstruct.len kn) >= need then
Expand Down
4 changes: 2 additions & 2 deletions lib/ssh.ml
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ let decode_mpint buf =
Nocrypto.Numeric.Z.of_cstruct_be mpbuf,
Cstruct.shift buf (len + 4)) ()

let encode_mpint mpint =
Buf.(to_cstruct @@ add_mpint mpint (create ()))
(* let encode_mpint mpint = *)
(* Buf.(to_cstruct @@ add_mpint mpint (create ())) *)

let decode_key buf =
decode_string buf >>= fun (key, buf) ->
Expand Down
7 changes: 5 additions & 2 deletions test/test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,16 @@ let t_mpint () =
* Case 2: Test identity
*)
assert (mpint =
(fst @@ get_ok_s (Ssh.decode_mpint (Ssh.encode_mpint mpint))));
(fst @@ get_ok_s
(Ssh.decode_mpint
(Buf.(to_cstruct @@
add_mpint mpint (create ()))))));

(*
* Case 3: Test the other way from 1, one zero must be prepended
* since the first byte is negative (0xff).
*)
let buf = Ssh.encode_mpint mpint in
let buf = Buf.(to_cstruct @@ add_mpint mpint (create ())) in
(* 4 for header + 1 zero prepended + 2 data*)
assert ((Cstruct.len buf) = (4 + 1 + 2));
assert_byte buf 0 0x00;
Expand Down

0 comments on commit 752752f

Please sign in to comment.