Skip to content

Commit

Permalink
Merge pull request #1383 from hbs/ecprivate.bd
Browse files Browse the repository at this point in the history
Added support for specifying private key in multiple ways
  • Loading branch information
hbs authored Dec 16, 2024
2 parents 7c471aa + fb7305d commit 408dce5
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions warp10/src/main/java/io/warp10/script/functions/ECPRIVATE.java
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -66,18 +66,11 @@ 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 + "'.");
if (null == params.get(Constants.KEY_D)) {
throw new WarpScriptException(getName() + " missing private key under '" + 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"; }
Expand Down

0 comments on commit 408dce5

Please sign in to comment.