isEqual method

bool isEqual(
  1. dynamic other
)

Checks if the message digest equals to other.

Here, the other can be a one of the following:

This function will return True if all bytes in the other matches with the bytes of this object. If the length does not match, or the type of other is not supported, it returns False immediately.

The content comparison is constant-time: it does not exit early on the first mismatching byte, making this method safe for comparing MACs and message digests.

Implementation

bool isEqual(dynamic other) {
  if (identical(this, other)) {
    return true;
  } else if (other is ByteCollector) {
    return isEqual(other.bytes);
  } else if (other is ByteBuffer) {
    return isEqual(Uint8List.view(other));
  } else if (other is TypedData && other is! Uint8List) {
    return isEqual(
      Uint8List.view(other.buffer, other.offsetInBytes, other.lengthInBytes),
    );
  } else if (other is String) {
    return isEqual(fromHex(other));
  } else if (other is Iterable<int>) {
    int i = 0, diff = 0;
    for (int x in other) {
      if (i >= bytes.length) {
        return false;
      }
      diff |= x ^ bytes[i++];
    }
    return i == bytes.length && diff == 0;
  }
  return false;
}