From e092c36ce903b3c895167fb0bb55c8f1287253d3 Mon Sep 17 00:00:00 2001 From: Mathias Herberts Date: Mon, 2 Dec 2024 15:29:27 +0100 Subject: [PATCH 1/2] Added support for specifying private key in multiple ways --- .../io/warp10/script/functions/ECPRIVATE.java | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/warp10/src/main/java/io/warp10/script/functions/ECPRIVATE.java b/warp10/src/main/java/io/warp10/script/functions/ECPRIVATE.java index 575509930c..fb43ec57dc 100644 --- a/warp10/src/main/java/io/warp10/script/functions/ECPRIVATE.java +++ b/warp10/src/main/java/io/warp10/script/functions/ECPRIVATE.java @@ -1,5 +1,5 @@ // -// Copyright 2020-2021 SenX S.A.S. +// Copyright 2020-2024 SenX S.A.S. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -66,18 +66,7 @@ public Object apply(WarpScriptStack stack) throws WarpScriptException { throw new WarpScriptException(getName() + " curve name not in " + ECGEN.getCurves() + "."); } - if (!(params.get(Constants.KEY_D) instanceof String)) { - throw new WarpScriptException(getName() + " missing or non-String parameter '" + Constants.KEY_D + "'."); - } - - String dstr = (String) params.get(Constants.KEY_D); - final BigInteger d; - - if (dstr.startsWith("0x") || dstr.startsWith("0X")) { - d = new BigInteger(dstr.substring(2), 16); - } else { - d = new BigInteger(dstr); - } + final BigInteger d = TOBD.toBigInteger(getName(), params.get(Constants.KEY_D)); ECPrivateKey privateKey = new ECPrivateKey() { public String getFormat() { return "PKCS#8"; } From fb7305dba048c3ce6d284d094dd4a3bff7f808e6 Mon Sep 17 00:00:00 2001 From: Mathias Herberts Date: Mon, 16 Dec 2024 10:05:36 +0100 Subject: [PATCH 2/2] Added check for 'd' parameter --- .../src/main/java/io/warp10/script/functions/ECPRIVATE.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/warp10/src/main/java/io/warp10/script/functions/ECPRIVATE.java b/warp10/src/main/java/io/warp10/script/functions/ECPRIVATE.java index fb43ec57dc..9cdb25e300 100644 --- a/warp10/src/main/java/io/warp10/script/functions/ECPRIVATE.java +++ b/warp10/src/main/java/io/warp10/script/functions/ECPRIVATE.java @@ -66,6 +66,10 @@ public Object apply(WarpScriptStack stack) throws WarpScriptException { throw new WarpScriptException(getName() + " curve name not in " + ECGEN.getCurves() + "."); } + if (null == params.get(Constants.KEY_D)) { + throw new WarpScriptException(getName() + " missing private key under '" + Constants.KEY_D + "'."); + } + final BigInteger d = TOBD.toBigInteger(getName(), params.get(Constants.KEY_D)); ECPrivateKey privateKey = new ECPrivateKey() {