Skip to content

Commit 625e617

Browse files
authored
Merge pull request #3976 from Songhee120/pk-exception
Raise exception on libplanet for zero byte prive key
2 parents 2b8189d + 2c8ca49 commit 625e617

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/Libplanet.Crypto/PrivateKey.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,11 @@ private static ECPrivateKeyParameters GenerateKeyParam()
405405

406406
private static ECPrivateKeyParameters GenerateKeyFromBytes(byte[] privateKey)
407407
{
408+
if (privateKey.All(b => b.Equals(0x00)))
409+
{
410+
throw new ArgumentException("Every bytes in Private key is zero value.");
411+
}
412+
408413
var param = new ECPrivateKeyParameters(
409414
"ECDSA",
410415
new BigInteger(1, privateKey),

test/Libplanet.Tests/Crypto/PrivateKeyTest.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,5 +360,18 @@ public void PrivateKeyGenerateLongerThan31Bytes()
360360

361361
Assert.Empty(faults);
362362
}
363+
364+
[Theory]
365+
[InlineData(new byte[]
366+
{
367+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
368+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
369+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
370+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
371+
})]
372+
public void ThrowsWhenZeroBytesPrivateKey(byte[] bytes)
373+
{
374+
Assert.Throws<ArgumentException>(() => new PrivateKey(bytes));
375+
}
363376
}
364-
}
377+
}

0 commit comments

Comments
 (0)