apple / swift-crypto

Open-source implementation of a substantial portion of the API of Apple CryptoKit suitable for use on Linux platforms.
https://apple.github.io/swift-crypto
Apache License 2.0
1.47k stars 165 forks source link

Add an inequality operator ( != ) for digest and DataProtocol comparison. #178

Closed joey-gm closed 1 year ago

joey-gm commented 1 year ago

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

Checklist

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 {...}