1// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4//
5// A wrapper around ZLib's CRC functions to put them in the rlz_lib namespace
6// and use our types.
7
8#include "rlz/lib/assert.h"
9#include "rlz/lib/crc32.h"
10#include "rlz/lib/string_utils.h"
11#include "third_party/zlib/zlib.h"
12
13namespace rlz_lib {
14
15int Crc32(const unsigned char* buf, int length) {
16  return crc32(0L, buf, length);
17}
18
19bool Crc32(const char* text, int* crc) {
20  if (!crc) {
21    ASSERT_STRING("Crc32: crc is NULL.");
22    return false;
23  }
24
25  *crc = 0;
26  for (int i = 0; text[i]; i++) {
27    if (!IsAscii(text[i]))
28      return false;
29
30    *crc = crc32(*crc, reinterpret_cast<const unsigned char*>(text + i), 1);
31  }
32
33  return true;
34}
35
36}  // namespace rlz_lib
37