Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

API Proposal: ECPoint.IsEmpty #34459

Closed
vcsjones opened this issue Apr 2, 2020 · 10 comments
Closed

API Proposal: ECPoint.IsEmpty #34459

vcsjones opened this issue Apr 2, 2020 · 10 comments

Comments

@vcsjones
Copy link
Member

vcsjones commented Apr 2, 2020

Proposal:

namespace System.Security.Cryptography {
    public struct ECPoint {
        // Existing
        public byte[]? X;
        public byte[]? Y;

        // New:
        [MemberNotNullWhen(false, nameof(X), nameof(Y))]
        public readonly bool IsEmpty => X == null && Y == null;
    }
}

Since the intention of PR #33874 is to allow ECParameters to have an empty Q, this would be a nice addition to allow !Q.IsEmpty instead of writing Q.X != null && Q.Y != null all over the place.

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added the untriaged New issue has not been triaged by the area owner label Apr 2, 2020
@Dotnet-GitSync-Bot
Copy link
Collaborator

I couldn't figure out the best area label to add to this issue. Please help me learn by adding exactly one area label.

@vcsjones
Copy link
Member Author

vcsjones commented Apr 2, 2020

The MemberNotNullWhen might need to be broken up in to

[MemberNotNullWhen(false, nameof(X))]
[MemberNotNullWhen(false, nameof(Y))]

For CLS compliance.

@ghost
Copy link

ghost commented Apr 2, 2020

@bartonjs

@bartonjs bartonjs added api-ready-for-review and removed untriaged New issue has not been triaged by the area owner labels Apr 2, 2020
@bartonjs
Copy link
Member

bartonjs commented Apr 2, 2020

I feel like a readonly should be in that property somewhere (might require using a block body), otherwise, looks review-worthy to me.

@vcsjones
Copy link
Member Author

vcsjones commented Apr 2, 2020

@bartonjs I never remember that C# feature exists. Amended. (It seems to work fine with an expression-bodied property).

@vcsjones
Copy link
Member Author

vcsjones commented Apr 2, 2020

@bartonjs Actually, I'm not sure this proposal as-is is nullable friendly.

Consider:

[MemberNotNullWhen(false, nameof(X), nameof(Y))]
public readonly bool IsEmpty => X == null && Y == null;

This is incorrect because false will be returned if X is null, but Y is not. We could change && to ||, which then will leave the nullable annotation correct, but IsEmpty return an unexpected result.

Perhaps a better way to do this is to make the property IsNotEmpty (yucky name up for debate).

[MemberNotNullWhen(true, nameof(X), nameof(Y))]
public readonly bool IsNotEmpty => X != null && Y != null;

@bartonjs
Copy link
Member

bartonjs commented Apr 2, 2020

Seems like maybe that's HasValue, then? But I'm not sure that HasValue... has value. (Or, really, that it's self-descriptive-enough.

Something like Validate() is OK, except that given that the whole point is that Q is now effectively optional that it's weird that Validate() returning false is sometimes valid.

So perhaps it's just best off as it is.

@vcsjones
Copy link
Member Author

vcsjones commented Apr 2, 2020

Perhaps the name HasPoint?

[MemberNotNullWhen(true, nameof(X), nameof(Y))]
public readonly bool HasPoint => X != null && Y != null;

"Point" conveys that both X and Y are there (since you cannot have a point with either just X or Y).

@bartonjs
Copy link
Member

bartonjs commented Apr 2, 2020

if (point.HasPoint)? It still feels a little weird to me, but at least it's somewhat describing the case.

@stephentoub Do you have thoughts here?

@vcsjones
Copy link
Member Author

This was a small nice-to-have, but I don't think this is worth pursuing given that it's not entirely straight-forward as initially thought.

@ghost ghost locked as resolved and limited conversation to collaborators Dec 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants