tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

HashCalc.h (2864B)


      1 // HashCalc.h
      2 
      3 #ifndef __HASH_CALC_H
      4 #define __HASH_CALC_H
      5 
      6 #include "../../../Common/Wildcard.h"
      7 
      8 #include "../../Common/CreateCoder.h"
      9 #include "../../Common/MethodProps.h"
     10 
     11 #include "DirItem.h"
     12 
     13 const unsigned k_HashCalc_DigestSize_Max = 64;
     14 
     15 const unsigned k_HashCalc_NumGroups = 4;
     16 
     17 enum
     18 {
     19  k_HashCalc_Index_Current,
     20  k_HashCalc_Index_DataSum,
     21  k_HashCalc_Index_NamesSum,
     22  k_HashCalc_Index_StreamsSum
     23 };
     24 
     25 struct CHasherState
     26 {
     27  CMyComPtr<IHasher> Hasher;
     28  AString Name;
     29  UInt32 DigestSize;
     30  Byte Digests[k_HashCalc_NumGroups][k_HashCalc_DigestSize_Max];
     31 };
     32 
     33 struct IHashCalc
     34 {
     35  virtual void InitForNewFile() = 0;
     36  virtual void Update(const void *data, UInt32 size) = 0;
     37  virtual void SetSize(UInt64 size) = 0;
     38  virtual void Final(bool isDir, bool isAltStream, const UString &path) = 0;
     39 };
     40 
     41 struct CHashBundle: public IHashCalc
     42 {
     43  CObjectVector<CHasherState> Hashers;
     44 
     45  UInt64 NumDirs;
     46  UInt64 NumFiles;
     47  UInt64 NumAltStreams;
     48  UInt64 FilesSize;
     49  UInt64 AltStreamsSize;
     50  UInt64 NumErrors;
     51 
     52  UInt64 CurSize;
     53 
     54  HRESULT SetMethods(DECL_EXTERNAL_CODECS_LOC_VARS const UStringVector &methods);
     55  
     56  void Init()
     57  {
     58    NumDirs = NumFiles = NumAltStreams = FilesSize = AltStreamsSize = NumErrors = 0;
     59  }
     60 
     61  void InitForNewFile();
     62  void Update(const void *data, UInt32 size);
     63  void SetSize(UInt64 size);
     64  void Final(bool isDir, bool isAltStream, const UString &path);
     65 };
     66 
     67 #define INTERFACE_IHashCallbackUI(x) \
     68  INTERFACE_IDirItemsCallback(x) \
     69  virtual HRESULT StartScanning() x; \
     70  virtual HRESULT FinishScanning(const CDirItemsStat &st) x; \
     71  virtual HRESULT SetNumFiles(UInt64 numFiles) x; \
     72  virtual HRESULT SetTotal(UInt64 size) x; \
     73  virtual HRESULT SetCompleted(const UInt64 *completeValue) x; \
     74  virtual HRESULT CheckBreak() x; \
     75  virtual HRESULT BeforeFirstFile(const CHashBundle &hb) x; \
     76  virtual HRESULT GetStream(const wchar_t *name, bool isFolder) x; \
     77  virtual HRESULT OpenFileError(const FString &path, DWORD systemError) x; \
     78  virtual HRESULT SetOperationResult(UInt64 fileSize, const CHashBundle &hb, bool showHash) x; \
     79  virtual HRESULT AfterLastFile(const CHashBundle &hb) x; \
     80 
     81 struct IHashCallbackUI: public IDirItemsCallback
     82 {
     83  INTERFACE_IHashCallbackUI(=0)
     84 };
     85 
     86 struct CHashOptions
     87 {
     88  UStringVector Methods;
     89  bool OpenShareForWrite;
     90  bool StdInMode;
     91  bool AltStreamsMode;
     92  NWildcard::ECensorPathMode PathMode;
     93 
     94  CHashOptions(): StdInMode(false), OpenShareForWrite(false), AltStreamsMode(false), PathMode(NWildcard::k_RelatPath) {};
     95 };
     96 
     97 HRESULT HashCalc(
     98    DECL_EXTERNAL_CODECS_LOC_VARS
     99    const NWildcard::CCensor &censor,
    100    const CHashOptions &options,
    101    AString &errorInfo,
    102    IHashCallbackUI *callback);
    103 
    104 void AddHashHexToString(char *dest, const Byte *data, UInt32 size);
    105 
    106 #endif