LLVM 20.0.0git
raw_sha1_ostream.h
Go to the documentation of this file.
1//==- raw_sha1_ostream.h - raw_ostream that compute SHA1 --*- C++ -*-==//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines the raw_sha1_ostream class.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_SUPPORT_RAW_SHA1_OSTREAM_H
14#define LLVM_SUPPORT_RAW_SHA1_OSTREAM_H
15
16#include "llvm/ADT/ArrayRef.h"
17#include "llvm/Support/SHA1.h"
19
20namespace llvm {
21
22/// A raw_ostream that hash the content using the sha1 algorithm.
24 SHA1 State;
25
26 /// See raw_ostream::write_impl.
27 void write_impl(const char *Ptr, size_t Size) override {
28 State.update(ArrayRef<uint8_t>((const uint8_t *)Ptr, Size));
29 }
30
31public:
32 /// Return the current SHA1 hash for the content of the stream
33 std::array<uint8_t, 20> sha1() {
34 flush();
35 return State.result();
36 }
37
38 /// Reset the internal state to start over from scratch.
39 void resetHash() { State.init(); }
40
41 uint64_t current_pos() const override { return 0; }
42};
43
44} // end llvm namespace
45
46#endif
uint64_t Size
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
A class that wrap the SHA1 algorithm.
Definition: SHA1.h:26
void update(ArrayRef< uint8_t > Data)
Digest more data.
Definition: SHA1.cpp:208
std::array< uint8_t, 20 > result()
Return the current raw 160-bits SHA1 for the digested data since the last call to init().
Definition: SHA1.cpp:288
void init()
Reinitialize the internal state.
Definition: SHA1.cpp:81
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
A raw_ostream that hash the content using the sha1 algorithm.
void resetHash()
Reset the internal state to start over from scratch.
uint64_t current_pos() const override
Return the current position within the stream, not counting the bytes currently in the buffer.
std::array< uint8_t, 20 > sha1()
Return the current SHA1 hash for the content of the stream.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18