operator == method

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

Equality operator

Returns true if both crypts are the same. That is, uses the same algorithm, the same rounds, the same salt and has the same hash.

If one crypt uses the default number of rounds for the algorithm (i.e. rounds is null) and the other crypt explicitly specifies the number of rounds, the rounds are considered the same if their numeric values are the same.

Implementation

@override
bool operator ==(Object that) {
  if (that is Crypt) {
    if (_type == that._type) {
      int defaultRounds;
      switch (_type) {
        case idSha256:
          defaultRounds = _defaultShaRounds;
          break;
        case idSha512:
          defaultRounds = _defaultShaRounds;
          break;
        default:
          // unknown or unsupported algorithm
          return false;
      }
      final r1 = _rounds ?? defaultRounds;
      final r2 = _rounds ?? defaultRounds;

      return r1 == r2 && _salt == that._salt && _hash == that._hash;
    }
    return false;
  } else {
    return false;
  }
}