aboutsummaryrefslogtreecommitdiff
path: root/lib/fields.ml
diff options
context:
space:
mode:
Diffstat (limited to 'lib/fields.ml')
-rw-r--r--lib/fields.ml11
1 files changed, 8 insertions, 3 deletions
diff --git a/lib/fields.ml b/lib/fields.ml
index 912407c..f18977b 100644
--- a/lib/fields.ml
+++ b/lib/fields.ml
@@ -68,15 +68,20 @@ struct
let one = Array.init degree (function 0 -> Fp.one | _ -> Fp.zero)
let of_string s =
+ let strip_parens s =
+ if String.starts_with ~prefix:"(" s && String.ends_with ~suffix:")" s
+ then String.sub s 1 (String.length s - 2)
+ else failwith "field element missing parentheses"
+ in
let a =
- Scanf.sscanf s "(%[^)])" (String.split_on_char ',')
- |> List.map String.trim |> List.map Fp.of_string |> Array.of_list
+ strip_parens s |> String.split_on_char ',' |> List.map Fp.of_string
+ |> Array.of_list
in
if Array.length a = degree then a
else invalid_arg "wrong number of elements"
let to_string a =
- Array.map Fp.to_string a |> Array.to_list |> String.concat ", "
+ Array.map Fp.to_string a |> Array.to_list |> String.concat ","
|> Printf.sprintf "(%s)"
let equal = Array.for_all2 Fp.equal