Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:44:33

0001 //==- raw_sha1_ostream.h - raw_ostream that compute SHA1        --*- C++ -*-==//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 //  This file defines the raw_sha1_ostream class.
0010 //
0011 //===----------------------------------------------------------------------===//
0012 
0013 #ifndef LLVM_SUPPORT_RAW_SHA1_OSTREAM_H
0014 #define LLVM_SUPPORT_RAW_SHA1_OSTREAM_H
0015 
0016 #include "llvm/ADT/ArrayRef.h"
0017 #include "llvm/Support/SHA1.h"
0018 #include "llvm/Support/raw_ostream.h"
0019 
0020 namespace llvm {
0021 
0022 /// A raw_ostream that hash the content using the sha1 algorithm.
0023 class raw_sha1_ostream : public raw_ostream {
0024   SHA1 State;
0025 
0026   /// See raw_ostream::write_impl.
0027   void write_impl(const char *Ptr, size_t Size) override {
0028     State.update(ArrayRef<uint8_t>((const uint8_t *)Ptr, Size));
0029   }
0030 
0031 public:
0032   /// Return the current SHA1 hash for the content of the stream
0033   std::array<uint8_t, 20> sha1() {
0034     flush();
0035     return State.result();
0036   }
0037 
0038   /// Reset the internal state to start over from scratch.
0039   void resetHash() { State.init(); }
0040 
0041   uint64_t current_pos() const override { return 0; }
0042 };
0043 
0044 } // end llvm namespace
0045 
0046 #endif