This commit is contained in:
parent
63c1fd453a
commit
c75060e65f
1 changed files with 3 additions and 12 deletions
|
|
@ -12,19 +12,9 @@ module Binary_format_rsa = struct
|
|||
leading zeroes are stripped unless they are required to keep a value positive
|
||||
no 0-termination *)
|
||||
|
||||
let rev_string len s = String.init len (fun i -> s.[len - 1 - i])
|
||||
|
||||
(* we reverse bytes because Z.of_bits reads bytes in little endian *)
|
||||
let z_of_bits_be src pos len =
|
||||
String.sub src pos len |> rev_string len |> Z.of_bits
|
||||
|
||||
let z_to_bits_be z =
|
||||
let bits = Z.to_bits z in
|
||||
rev_string (String.length bits) bits
|
||||
|
||||
let z_array_to_octets (arr : Z.t array) =
|
||||
let nb = Array.length arr in
|
||||
let bits_arr = Array.map z_to_bits_be arr in
|
||||
let bits_arr = Array.map Mirage_crypto_pk.Z_extra.to_octets_be arr in
|
||||
let len_arr = Array.map String.length bits_arr in
|
||||
let len = (2 * nb) + Array.fold_left ( + ) 0 len_arr in
|
||||
let b = Bytes.make len '\x00' in
|
||||
|
|
@ -63,7 +53,8 @@ module Binary_format_rsa = struct
|
|||
let z_arr =
|
||||
Array.init nb (fun i ->
|
||||
let len = len_arr.(i) in
|
||||
let z = z_of_bits_be s !pos len in
|
||||
let s = String.sub s !pos len in
|
||||
let z = Mirage_crypto_pk.Z_extra.of_octets_be s in
|
||||
pos := !pos + len;
|
||||
z)
|
||||
in
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue