Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cASNWriterRev.h
Go to the documentation of this file.
1 //
5 
6 #ifndef _INC_cASNWriterRev_H
7 #define _INC_cASNWriterRev_H
8 #ifndef NO_PRAGMA_ONCE
9 #pragma once
10 #endif
11 
12 #include "cASNReader.h"
13 #include "GrayCore/include/cBits.h"
15 
16 namespace GrayLib
17 {
18  class cASNSet1;
19  class cASNSets;
20 
22  {
30 
31  protected:
32  BYTE* m_pOutCur;
33 
34  protected:
35  HRESULT WriteSetsRev(const cASNSets* pCur);
36 
37  public:
38  cASNWriterRev(BYTE* pStart, size_t nLen)
39  : cMemBlock(pStart, nLen)
40  , m_pOutCur(pStart + nLen) // End to start.
41  {}
43  : cMemBlock(m)
44  , m_pOutCur(const_cast<BYTE*>((BYTE*)m.get_DataEnd())) // End to start.
45  {}
46 
47  size_t get_LenLeft() const
48  {
50  ASSERT(this->IsValidPtr2(this->m_pOutCur));
51  return (size_t)cMem::Diff(this->m_pOutCur, this->get_DataBytes());
52  }
53  size_t get_LenWritten() const
54  {
56  ASSERT(this->IsValidPtr2(this->m_pOutCur));
57  return (size_t)cMem::Diff(this->get_DataEnd(), m_pOutCur);
58  }
59 
60  BYTE* get_OutPtr() const
61  {
63  return m_pOutCur; // Current write position. This Advances backwards via AddOut(x) or Write*().
64  }
65 
66  void AddOut(size_t nSize)
67  {
68  m_pOutCur -= nSize;
69  ASSERT(m_pOutCur >= get_DataBytes());
70  }
71 
72  void WriteByteRaw(BYTE b)
73  {
74  m_pOutCur--;
75  m_pOutCur[0] = b;
76  ASSERT(this->IsValidPtr(this->m_pOutCur));
77  }
78 
79  HRESULT WriteByte(BYTE b);
80 
81  HRESULT WriteRawData(const void* pBuffer, size_t size);
82 
83  HRESULT WriteLengthCode(size_t len);
84 
85  HRESULT WriteTag(ASN_t nTagExpected, size_t len);
86 
87  HRESULT WriteTagNull();
88 
89  HRESULT WriteTagBlock(ASN_t nTag, const void* pBuffer, size_t nSizeBuffer);
90 
91  HRESULT WriteTagBoolean(bool bVal);
92 
93  HRESULT WriteTagInt(int iVal);
94  HRESULT WriteTagInt(const BYTE* pData, size_t nSize, bool bNegativeOrNA);
95  HRESULT WriteTagInt(const cBitArray& X, bool bNegativeOrNA = false);
96 
97  HRESULT WriteTagOID(const char* oid, size_t oid_len);
98 
99  HRESULT WriteTagStringPrintable(const char* text, StrLen_t text_len= k_StrLen_UNK);
100 
101  HRESULT WriteTagStringIA5(const char* text, StrLen_t text_len = k_StrLen_UNK);
102 
103  HRESULT WriteTagArrayBits(const BYTE* pBuffer, BIT_ENUM_t bits);
104 
105  HRESULT WriteTagArrayBytes(const BYTE* pBuffer, size_t size);
106 
107  HRESULT WriteTagTime(const cTimeUnits& Tu);
108  HRESULT WriteTagTime(const cTimeInt& time, TZ_TYPE nTimeZoneOffset= TZ_LOCAL);
109 
110  HRESULT WriteSet1(const cASNSet1& s);
111  HRESULT WriteSets(const cASNSets& rNames);
112 
113  HRESULT WriteExtensionList1(const cASNSet1* ext);
114  HRESULT WriteExtensionList(const cASNSets& rExtensions);
115 
116  HRESULT WriteTagSeqAlg(const char* oid, size_t oid_len);
117  HRESULT WriteTagSeqAlg2(const char* oid, size_t oid_len, BYTE* pSig, size_t size);
118  };
119 }
120 
121 #endif // _INC_cASNWriterRev_H
#define GRAYLIB_LINK
Definition: GrayLibBase.h:35
INT32 HRESULT
_WIN32 style error codes. INT32
Definition: SysTypes.h:465
#define ASSERT(exp)
Definition: cDebugAssert.h:87
Definition: cASNSets.h:20
Definition: cASNSets.h:58
Definition: cASNWriterRev.h:22
cASNWriterRev(BYTE *pStart, size_t nLen)
Definition: cASNWriterRev.h:38
cASNWriterRev(cMemBlock &m)
Definition: cASNWriterRev.h:42
size_t get_LenLeft() const
Definition: cASNWriterRev.h:47
BYTE * m_pOutCur
current write position. Moves down.
Definition: cASNWriterRev.h:32
void WriteByteRaw(BYTE b)
Definition: cASNWriterRev.h:72
size_t get_LenWritten() const
Definition: cASNWriterRev.h:53
void AddOut(size_t nSize)
Definition: cASNWriterRev.h:66
BYTE * get_OutPtr() const
Definition: cASNWriterRev.h:60
Definition: cBitArray.h:416
Definition: cMem.h:311
< similar to the MFC CTime and cTimeSpan, not as accurate or large ranged as COleDateTime
Definition: cTimeInt.h:101
Definition: cTimeUnits.h:146
Definition: cMesh.h:22
BYTE ASN_t
Definition: cASN.h:75
TZ_TYPE
Definition: cTimeUnits.h:29
@ TZ_LOCAL
just use local time zone. might include DST ??
Definition: cTimeUnits.h:44
const StrLen_t k_StrLen_UNK
use the default/current length of the string argument.
Definition: StrConst.h:34
int StrLen_t
the length of a string in chars (bytes for UTF8, wchar_t for UNICODE). or offset in characters....
Definition: StrConst.h:32
unsigned int BIT_ENUM_t
Enumerate number of bits or address a single bit in some array of bits.
Definition: cBits.h:20
static ptrdiff_t Diff(const void *pEnd, const void *pStart) noexcept
Definition: cMem.h:34