summaryrefslogtreecommitdiff
path: root/xfa/fxfa/xfa_checksum.h
blob: 69adc0a023ed6cbafd1310f8d5eb8e365d3e0864 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright 2014 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com

#ifndef XFA_FXFA_XFA_CHECKSUM_H_
#define XFA_FXFA_XFA_CHECKSUM_H_

#include "xfa/fde/xml/cfx_saxreader.h"
#include "xfa/fxfa/fxfa.h"

class CXFA_SAXReaderHandler;
class CXFA_ChecksumContext;

class CXFA_SAXContext {
 public:
  CXFA_SAXContext() : m_eNode(CFX_SAXItem::Type::Unknown) {}

  CFX_ByteTextBuf m_TextBuf;
  CFX_ByteString m_bsTagName;
  CFX_SAXItem::Type m_eNode;
};

class CXFA_SAXReaderHandler {
 public:
  CXFA_SAXReaderHandler(CXFA_ChecksumContext* pContext);
  ~CXFA_SAXReaderHandler();

  CXFA_SAXContext* OnTagEnter(const CFX_ByteStringC& bsTagName,
                              CFX_SAXItem::Type eType,
                              uint32_t dwStartPos);
  void OnTagAttribute(CXFA_SAXContext* pTag,
                      const CFX_ByteStringC& bsAttri,
                      const CFX_ByteStringC& bsValue);
  void OnTagBreak(CXFA_SAXContext* pTag);
  void OnTagData(CXFA_SAXContext* pTag,
                 CFX_SAXItem::Type eType,
                 const CFX_ByteStringC& bsData,
                 uint32_t dwStartPos);
  void OnTagClose(CXFA_SAXContext* pTag, uint32_t dwEndPos);
  void OnTagEnd(CXFA_SAXContext* pTag,
                const CFX_ByteStringC& bsTagName,
                uint32_t dwEndPos);

  void OnTargetData(CXFA_SAXContext* pTag,
                    CFX_SAXItem::Type eType,
                    const CFX_ByteStringC& bsData,
                    uint32_t dwStartPos);

 protected:
  void UpdateChecksum(FX_BOOL bCheckSpace);

  CXFA_ChecksumContext* m_pContext;
  CXFA_SAXContext m_SAXContext;
};

class CXFA_ChecksumContext {
 public:
  CXFA_ChecksumContext();
  ~CXFA_ChecksumContext();

  void StartChecksum();
  void Update(const CFX_ByteStringC& bsText);
  FX_BOOL UpdateChecksum(IFX_FileRead* pSrcFile,
                         FX_FILESIZE offset = 0,
                         size_t size = 0);
  void FinishChecksum();
  CFX_ByteString GetChecksum() const;

 protected:
  CFX_SAXReader* m_pSAXReader;
  uint8_t* m_pByteContext;
  CFX_ByteString m_bsChecksum;
};

#endif  // XFA_FXFA_XFA_CHECKSUM_H_