operator == method

  1. @override
bool operator == (
  1. Object other
)
override

Returns whether this is equal to another digest.

This should be used instead of manual comparisons to avoid leaking information via timing.

Implementation

@override
bool operator ==(Object other) {
  if (other is Digest) {
    final a = bytes;
    final b = other.bytes;
    if (a.length != b.length) {
      return false;
    }
    final n = a.length;
    var mismatch = 0;
    for (var i = 0; i < n; i++) {
      mismatch |= a[i] ^ b[i];
    }
    return mismatch == 0;
  }
  return false;
}