Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

The Scalar and Point interface do not allow error handling #530

Open
K1li4nL opened this issue Jun 12, 2024 · 1 comment
Open

The Scalar and Point interface do not allow error handling #530

K1li4nL opened this issue Jun 12, 2024 · 1 comment

Comments

@K1li4nL
Copy link
Contributor

K1li4nL commented Jun 12, 2024

Given the structure of kyber, the following piece of code often appears:

func (P *point) Add(P1, P2 kyber.Point) kyber.Point {
	E1 := P1.(*point)
...

Unfortunately if P1 is not the right type, this will panic. Allowing to return errors would allow graceful handling of the problem:

func (P *point) Add(P1, P2 kyber.Point) (kyber.Point, error) {
	E1, ok := P1.(*point)
        if !ok {
             /* Handle error */
             return nil,  _some error_
...
@pierluca
Copy link
Contributor

pierluca commented Jul 15, 2024

Rationale discussed with @bford :
This is to emulate a generic (in pre-generics Go), panicking here makes sense because it's a programmer error, not input-dependent.

A better (longer term) solution would be to get compile-time errors by adopting generics.

@pierluca pierluca added v5 and removed v4 labels Oct 23, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

2 participants