Example #1
0
bool
GRecord::VerifyGRecordInFile(Path path, Error &error)
{
  // assumes FileName member is set
  // Load File into Buffer (assume name is already set)
  if (!LoadFileToBuffer(path, error))
    return false;

  // load Existing Digest "old"
  char old_g_record[DIGEST_LENGTH + 1];
  if (!ReadGRecordFromFile(path, old_g_record, ARRAY_SIZE(old_g_record), error))
    return false;

  // recalculate digest from buffer
  FinalizeBuffer();

  char new_g_record[DIGEST_LENGTH + 1];
  GetDigest(new_g_record);

  if (strcmp(old_g_record, new_g_record) != 0) {
    error.Set(grecord_domain, "Invalid G record");
    return false;
  }

  return true;
}
Example #2
0
bool
GRecord::ReadGRecordFromFile(Path path,
                             char *output, size_t max_length,
                             Error &error)
{
  FileLineReaderA reader(path, error);
  if (reader.error())
    return false;

  unsigned int digest_length = 0;
  char *data;
  while ((data = reader.ReadLine()) != nullptr) {
    if (data[0] != 'G')
      continue;

    for (const char *p = data + 1; *p != '\0'; ++p) {
      output[digest_length++] = *p;
      if (digest_length >= max_length) {
        error.Set(grecord_domain, "G record too large");
        return false;
      }
    }
  }

  output[digest_length] = '\0';
  return true;
}