- add sources.
[platform/framework/web/crosswalk.git] / src / third_party / cacheinvalidation / overrides / google / cacheinvalidation / deps / sha1-digest-function.h
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 // Interface to SHA1 digest computation.
6
7 #ifndef GOOGLE_CACHEINVALIDATION_DEPS_SHA1_DIGEST_FUNCTION_H_
8 #define GOOGLE_CACHEINVALIDATION_DEPS_SHA1_DIGEST_FUNCTION_H_
9
10 #include <string>
11
12 #include "base/sha1.h"
13 #include "google/cacheinvalidation/deps/digest-function.h"
14 #include "google/cacheinvalidation/deps/stl-namespace.h"
15
16 namespace invalidation {
17
18 using ::INVALIDATION_STL_NAMESPACE::string;
19
20 class Sha1DigestFunction : public DigestFunction {
21  public:
22   Sha1DigestFunction() : reset_needed_(false) {}
23
24   virtual void Reset() {
25     reset_needed_ = false;
26     buffer_.clear();
27   }
28
29   virtual void Update(const string& s) {
30     CHECK(!reset_needed_);
31     buffer_.append(s);
32   }
33
34   virtual string GetDigest() {
35     CHECK(!reset_needed_);
36     reset_needed_ = true;
37     return base::SHA1HashString(buffer_);
38   }
39
40  private:
41   string buffer_;
42   bool reset_needed_;
43 };
44
45 }  // namespace invalidation
46
47 #endif  // GOOGLE_CACHEINVALIDATION_DEPS_SHA1_DIGEST_FUNCTION_H_