Skip to content

You're viewing documentation for a pre-release version. View the latest stable version

Instance MethodSwift

secureCompare(to:)

Performs a full-comparison of all elements in two collections. If the two collections have a different number of elements, the function will compare all elements in the smaller collection first and then return false.
func secureCompare<C>(to other: C) -> Bool where C : Collection, Self.Element == C.Element

Parameters

other

Collection to compare to.

Return Value

true if the collections are equal.

Discussion

let a, b: Data
let res = a.secureCompare(to: b)

This method does not make use of any early exit functionality, making it harder to perform timing attacks on the comparison logic. Use this method if when comparing secure data like hashes.