mirror of
https://github.com/ziglang/zig.git
synced 2026-02-14 21:38:33 +00:00
crypto.Ed25519.KeyPair: return an error rather than assert
When runtime safety is turned on, `Ed25519.fromSecretKey()` can currently hit an assertion if the format of the secret key is invalid. Return an error instead, so that applications can recover.
This commit is contained in:
parent
05d8b565ad
commit
65e7ede499
@ -299,7 +299,9 @@ pub const Ed25519 = struct {
|
||||
if (std.debug.runtime_safety) {
|
||||
const pk_p = try Curve.fromBytes(secret_key.publicKeyBytes());
|
||||
const recomputed_kp = try generateDeterministic(secret_key.seed());
|
||||
debug.assert(mem.eql(u8, &recomputed_kp.public_key.toBytes(), &pk_p.toBytes()));
|
||||
if (!mem.eql(u8, &recomputed_kp.public_key.toBytes(), &pk_p.toBytes())) {
|
||||
return error.NonCanonical;
|
||||
}
|
||||
}
|
||||
return KeyPair{
|
||||
.public_key = try PublicKey.fromBytes(secret_key.publicKeyBytes()),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user