tokenMatches static method

bool tokenMatches(
  1. String? presented,
  2. String expected
)

Whether presented is expected, compared in constant time.

Implementation

static bool tokenMatches(String? presented, String expected) {
  if (presented == null) return false;
  final List<int> a = utf8.encode(presented);
  final List<int> b = utf8.encode(expected);
  int difference = a.length ^ b.length;
  for (int i = 0; i < b.length; i++) {
    difference |= (i < a.length ? a[i] : 0) ^ b[i];
  }
  return difference == 0 && b.isNotEmpty;
}