mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-03-08 02:44:43 +01: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
1 changed files with 3 additions and 1 deletions
|
|
@ -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…
Add table
Add a link
Reference in a new issue