diff --git a/lib/curves/ecdsa.ex b/lib/curves/ecdsa.ex index 588d224..4308c57 100644 --- a/lib/curves/ecdsa.ex +++ b/lib/curves/ecdsa.ex @@ -35,6 +35,13 @@ defmodule CA.ECDSA do %CA.Point{ x: numberFromString(xs), y: numberFromString(ys)} end + def signature(name) do + {:ok, sig} = :file.read_file name + {{_,[{_,r},{_,s}]},""} = :asn1rt_nif.decode_ber_tlv sig + { :ca_enroll.decode_integer(r), + :ca_enroll.decode_integer(s) } + end + def sign(file, key) do {:ok, msg} = :file.read_file file {:ok, pem} = :file.read_file key @@ -44,7 +51,7 @@ defmodule CA.ECDSA do def verify(file, signature_file, pub) do {:ok, msg} = :file.read_file file {:ok, pem} = :file.read_file pub - verify(msg, CA.ECDSA.OTP.signature(signature_file), decodePointFromECPoint(public(pem)), []) + verify(msg, signature(signature_file), decodePointFromECPoint(public(pem)), []) end def verify(message, {r,s}, publicKey, options) do diff --git a/lib/ecdsa.ex b/lib/ecdsa.ex index ae4bc5e..0f86997 100644 --- a/lib/ecdsa.ex +++ b/lib/ecdsa.ex @@ -22,13 +22,6 @@ defmodule CA.ECDSA.OTP do [point, :crypto.ec_curve(:pubkey_cert_records.namedCurves(oid))]) end - def signature(name) do - {:ok, sig} = :file.read_file name - {{_,[{_,r},{_,s}]},""} = :asn1rt_nif.decode_ber_tlv sig - { :ca_enroll.decode_integer(r), - :ca_enroll.decode_integer(s) } - end - def sign(file, priv) do {:ok, msg} = :file.read_file file {:ok, key} = :file.read_file priv