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

Add inequality operator ( != ) for digest and DataProtocol comparison #180

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

joey-gm
Copy link
Contributor

@joey-gm joey-gm commented Apr 22, 2023

Add an inequality comparison operator to determine whether a digest is not equal to a collection of contiguous bytes.

Checklist

  • I've run tests to see all new and existing tests pass
  • I've followed the code style of the rest of the project
  • I've read the Contribution Guidelines
  • I've updated the documentation if necessary

Motivation:

The equal ( == ) and not equal ( != ) operators are available for comparing two digests. However, only the equal operator is available for the comparison between a digest and a collection of contiguous bytes.

This modification adds the missing inequality operator ( != ) for digest and DataProtocol comparison.

Modifications:

The following static method has been added to Digest.swift as an extension to Digest.

public static func != <D: DataProtocol>(lhs: Self, rhs: D) -> Bool

A corresponding test case has also been added to DigestsTests.swift.

Result:

Instead of checking if !(digest == someDataBytes) {...}, we can now write if digest != someDataBytes {...}.

Copy link
Contributor

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this! As with several other PRs open on this repo, any change to the public API surface requires synchronization with CryptoKit in Apple's SDKs. While this is a reasonable change, I'm going to defer merging it for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants