src/or/consdiff.c
static int
base64cmp(const char *hash1, const char *hash2)
{
  /* NULL is always lower, useful for last_hash which starts at NULL. */
  if (!hash1 && !hash2) {
    return 0;
  }
  if (!hash1) {
    return -1;
  }
  if (!hash2) {
    return 1;
  }

  /* Don't index with a char; char may be signed. */
  const unsigned char *a = (unsigned char*)hash1;
  const unsigned char *b = (unsigned char*)hash2;
  while (1) {
    uint8_t av = base64_compare_table[*a];
    uint8_t bv = base64_compare_table[*b];
    if (av == X) {
      if (bv == X) {
        /* Both ended with exactly the same characters. */
        return 0;
      } else {
        /* hash2 goes on longer than hash1 and thus hash1 is lower. */
        return -1;
      }
    } else if (bv == X) {
      /* hash1 goes on longer than hash2 and thus hash1 is greater. */
      return 1;
    } else if (av < bv) {
      /* The first difference shows that hash1 is lower. */
      return -1;
    } else if (av > bv) {
      /* The first difference shows that hash1 is greater. */
      return 1;
    } else {
      a++;
      b++;
    }
  }
}
/** Helper: compare two base64-encoded identity hashes which may be of
 * different lengths. Comparison ends when the first non-base64 char is found.
 */
compare two base64-encoded identity hashes which may be of
different lengths. Comparison ends when the first non-base64 char is found.
compare two base64 - encoded identity hashes which may be of different lengths . Comparison ends when the first non - base64 char is found .
static int
base64cmp(const char *hash1, const char *hash2)
{
  if (!hash1 && !hash2) {
    return 0;
  }
  if (!hash1) {
    return -1;
  }
  if (!hash2) {
    return 1;
  }
  const unsigned char *a = (unsigned char*)hash1;
  const unsigned char *b = (unsigned char*)hash2;
  while (1) {
    uint8_t av = base64_compare_table[*a];
    uint8_t bv = base64_compare_table[*b];
    if (av == X) {
      if (bv == X) {
        return 0;
      } else {
        return -1;
      }
    } else if (bv == X) {
      return 1;
    } else if (av < bv) {
      return -1;
    } else if (av > bv) {
      return 1;
    } else {
      a++;
      b++;
    }
  }
}
static int base64cmp ( const char * hash1 , const char * hash2 ) { if ( ! hash1 && ! hash2 ) { return 0 ; } if ( ! hash1 ) { return -1 ; } if ( ! hash2 ) { return 1 ; } const unsigned char * a = ( unsigned char * ) hash1 ; const unsigned char * b = ( unsigned char * ) hash2 ; while ( 1 ) { uint8_t av = base64_compare_table [ * a ] ; uint8_t bv = base64_compare_table [ * b ] ; if ( av == X ) { if ( bv == X ) { return 0 ; } else { return -1 ; } } else if ( bv == X ) { return 1 ; } else if ( av < bv ) { return -1 ; } else if ( av > bv ) { return 1 ; } else { a ++ ; b ++ ; } } }
Helper: compare two base64-encoded identity hashes which may be of
 different lengths.
Helper : compare two base64 - encoded identity hashes which may be of different lengths .
/* NULL is always lower, useful for last_hash which starts at NULL. */ /* Don't index with a char; char may be signed. */ /* Both ended with exactly the same characters. */ /* hash2 goes on longer than hash1 and thus hash1 is lower. */ /* hash1 goes on longer than hash2 and thus hash1 is greater. */ /* The first difference shows that hash1 is lower. */ /* The first difference shows that hash1 is greater. */