1//==- raw_sha1_ostream.h - raw_ostream that compute SHA1        --*- C++ -*-==//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10//  This file defines the raw_sha1_ostream class.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_SUPPORT_RAW_SHA1_OSTREAM_H
15#define LLVM_SUPPORT_RAW_SHA1_OSTREAM_H
16
17#include "llvm/Support/raw_ostream.h"
18#include "llvm/Support/SHA1.h"
19#include "llvm/ADT/ArrayRef.h"
20
21namespace llvm {
22
23/// A raw_ostream that hash the content using the sha1 algorithm.
24class raw_sha1_ostream : public raw_ostream {
25  SHA1 State;
26
27  /// See raw_ostream::write_impl.
28  void write_impl(const char *Ptr, size_t Size) override {
29    State.update(ArrayRef<uint8_t>((const uint8_t *)Ptr, Size));
30  }
31
32public:
33  /// Return the current SHA1 hash for the content of the stream
34  StringRef sha1() {
35    flush();
36    return State.result();
37  }
38
39  /// Reset the internal state to start over from scratch.
40  void resetHash() { State.init(); }
41
42  uint64_t current_pos() const override { return 0; }
43};
44
45} // end llvm namespace
46
47#endif
48