Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
GrayLib::cASNWriterRev Class Reference

#include <cASNWriterRev.h>

Inheritance diagram for GrayLib::cASNWriterRev:
Gray::cMemBlock

Public Member Functions

 cASNWriterRev (BYTE *pStart, size_t nLen)
 
 cASNWriterRev (cMemBlock &m)
 
size_t get_LenLeft () const
 
size_t get_LenWritten () const
 
BYTE * get_OutPtr () const
 
void AddOut (size_t nSize)
 
void WriteByteRaw (BYTE b)
 
HRESULT WriteByte (BYTE b)
 
HRESULT WriteRawData (const void *pBuffer, size_t size)
 
HRESULT WriteLengthCode (size_t len)
 
HRESULT WriteTag (ASN_t nTagExpected, size_t len)
 
HRESULT WriteTagNull ()
 
HRESULT WriteTagBlock (ASN_t nTag, const void *pBuffer, size_t nSizeBuffer)
 
HRESULT WriteTagBoolean (bool bVal)
 
HRESULT WriteTagInt (int iVal)
 
HRESULT WriteTagInt (const BYTE *pData, size_t nSize, bool bNegativeOrNA)
 
HRESULT WriteTagInt (const cBitArray &X, bool bNegativeOrNA=false)
 
HRESULT WriteTagOID (const char *oid, size_t oid_len)
 
HRESULT WriteTagStringPrintable (const char *text, StrLen_t text_len=k_StrLen_UNK)
 
HRESULT WriteTagStringIA5 (const char *text, StrLen_t text_len=k_StrLen_UNK)
 
HRESULT WriteTagArrayBits (const BYTE *pBuffer, BIT_ENUM_t bits)
 
HRESULT WriteTagArrayBytes (const BYTE *pBuffer, size_t size)
 
HRESULT WriteTagTime (const cTimeUnits &Tu)
 
HRESULT WriteTagTime (const cTimeInt &time, TZ_TYPE nTimeZoneOffset=TZ_LOCAL)
 
HRESULT WriteSet1 (const cASNSet1 &s)
 
HRESULT WriteSets (const cASNSets &rNames)
 
HRESULT WriteExtensionList1 (const cASNSet1 *ext)
 
HRESULT WriteExtensionList (const cASNSets &rExtensions)
 
HRESULT WriteTagSeqAlg (const char *oid, size_t oid_len)
 
HRESULT WriteTagSeqAlg2 (const char *oid, size_t oid_len, BYTE *pSig, size_t size)
 
- Public Member Functions inherited from Gray::cMemBlock
 cMemBlock () noexcept
 
 cMemBlock (const void *pData, size_t nSize) noexcept
 
 cMemBlock (const cMemBlock &block) noexcept
 
 cMemBlock (const cMemBlock *pBlock) noexcept
 
size_t get_DataSize () const noexcept
 
void * get_Data () const noexcept
 
BYTE * get_DataBytes () const noexcept
 
char * get_DataA () const noexcept
 
 operator const BYTE * () const noexcept
 
bool isValidPtr () const noexcept
 
bool IsValidIndex (size_t i) const noexcept
 
bool IsValidIndex2 (size_t i) const noexcept
 
bool IsValidPtr (const void *p) const noexcept
 
bool IsValidPtr2 (const void *p) const noexcept
 
bool IsZeros () const noexcept
 
bool IsEqualData (const void *pData, size_t nSize) const noexcept
 
bool IsEqualData (const cMemBlock *pData) const noexcept
 
bool IsEqualData (const cMemBlock &data) const noexcept
 
BYTE * GetOffset (size_t nOffset) const
 
const void * get_DataEnd () const noexcept
 
void put_DataPtr (void *pStart) noexcept
 
void put_Size (size_t nSize) noexcept
 
void SetBlock (void *pData, size_t nSize) noexcept
 
void SetEmptyBlock () noexcept
 
void InitZeros () noexcept
 
StrLen_t ConvertToString (char *pszDst, StrLen_t iDstSizeMax) const
 

Protected Member Functions

HRESULT WriteSetsRev (const cASNSets *pCur)
 

Protected Attributes

BYTE * m_pOutCur
 current write position. Moves down. More...
 
- Protected Attributes inherited from Gray::cMemBlock
size_t m_nSize
 size_t of m_pData in bytes. May be determined at runtime. More...
 
void * m_pData
 

Additional Inherited Members

- Static Public Member Functions inherited from Gray::cMemBlock
static COMPARE_t __stdcall Compare (const void *pData1, size_t iLen1, const void *pData2, size_t iLen2)
 

Detailed Description

Helper class for writing an ASN blob in memory. Used for DER format. Similar to cStreamStatic Write BACKWARDS so we can prefix with calculated lengths. Weird. But since the length code itself is variable length I can't just leave an empty spot for it! similar to StrBuilder but backwards. Opposite to cASNReader Buffer ownership and delete responsibility is external.

Constructor & Destructor Documentation

◆ cASNWriterRev() [1/2]

GrayLib::cASNWriterRev::cASNWriterRev ( BYTE *  pStart,
size_t  nLen 
)
inline

◆ cASNWriterRev() [2/2]

GrayLib::cASNWriterRev::cASNWriterRev ( cMemBlock m)
inline

Member Function Documentation

◆ AddOut()

void GrayLib::cASNWriterRev::AddOut ( size_t  nSize)
inline

◆ get_LenLeft()

size_t GrayLib::cASNWriterRev::get_LenLeft ( ) const
inline

Space left. intentionally backwards.

◆ get_LenWritten()

size_t GrayLib::cASNWriterRev::get_LenWritten ( ) const
inline

How much data written so far ? intentionally backwards.

◆ get_OutPtr()

BYTE* GrayLib::cASNWriterRev::get_OutPtr ( ) const
inline

get write position.

◆ WriteByte()

HRESULT GrayLib::cASNWriterRev::WriteByte ( BYTE  b)

Write a ASN.1 tag in ASN.1 format

  • b = some byte to write.
    Returns
    the length written or <0 = error

◆ WriteByteRaw()

void GrayLib::cASNWriterRev::WriteByteRaw ( BYTE  b)
inline

◆ WriteExtensionList()

HRESULT GrayLib::cASNWriterRev::WriteExtensionList ( const cASNSets rExtensions)

– contains the DER encoding of an ASN.1 value – corresponding to the extension type identified – by extnID

◆ WriteExtensionList1()

HRESULT GrayLib::cASNWriterRev::WriteExtensionList1 ( const cASNSet1 ext)

◆ WriteLengthCode()

HRESULT GrayLib::cASNWriterRev::WriteLengthCode ( size_t  len)

Write a variable length, length field in ASN.1 format Write encoded length backwards since it is variable length itself. Opposite of ReadLengthCode()

Returns
the length written (1,2, or 3) or <0 = error

◆ WriteRawData()

HRESULT GrayLib::cASNWriterRev::WriteRawData ( const void *  pBuffer,
size_t  size 
)

Write raw buffer data

Note
function works backwards in data buffer
  • pBuffer = data buffer to write
  • size = length of the data buffer
Returns
the length written or <0 = error

◆ WriteSet1()

HRESULT GrayLib::cASNWriterRev::WriteSet1 ( const cASNSet1 s)

RelativeDistinguishedName ::= SET OF AttributeTypeAndValue

AttributeTypeAndValue ::= SEQUENCE { type AttributeType, value AttributeValue }

AttributeType ::= OBJECT IDENTIFIER

AttributeValue ::= ANY DEFINED BY AttributeType

◆ WriteSets()

HRESULT GrayLib::cASNWriterRev::WriteSets ( const cASNSets rNames)

◆ WriteSetsRev()

HRESULT GrayLib::cASNWriterRev::WriteSetsRev ( const cASNSets pCur)
protected

Write in REVERSE

◆ WriteTag()

HRESULT GrayLib::cASNWriterRev::WriteTag ( ASN_t  nTagExpected,
size_t  len 
)

Opposite of ReadTag()

  • nTag = ASN_t

◆ WriteTagArrayBits()

HRESULT GrayLib::cASNWriterRev::WriteTagArrayBits ( const BYTE *  pBuffer,
BIT_ENUM_t  bits 
)

Write a ASN_ArrayBits and value in ASN.1 format

Note
function works backwards in data buffer
  • pBuffer = the bitstring
  • bits = the total number of bits in the bitstring
Returns
the length written or <0 = error

◆ WriteTagArrayBytes()

HRESULT GrayLib::cASNWriterRev::WriteTagArrayBytes ( const BYTE *  pBuffer,
size_t  size 
)

Write an octet string tag (ASN_ArrayBytes) and value in ASN.1 format

Note
function works backwards in data buffer
  • pBuffer = data buffer to write
  • size = length of the data buffer
Returns
the length written or <0 = error

◆ WriteTagBlock()

HRESULT GrayLib::cASNWriterRev::WriteTagBlock ( ASN_t  nTag,
const void *  pBuffer,
size_t  nSizeBuffer 
)

Write ASN Tag and data in ASN.1 format

Note
function works backwards in data buffer opposite of ReadTagBlock()
  • pBuffer = the data to write
  • nSizeBuffer = length of the data
Returns
the length written or <0 = error

◆ WriteTagBoolean()

HRESULT GrayLib::cASNWriterRev::WriteTagBoolean ( bool  bVal)

Write a boolean tag (ASN_BOOLEAN) and value in ASN.1 format opposite of ReadTagBoolean()

◆ WriteTagInt() [1/3]

HRESULT GrayLib::cASNWriterRev::WriteTagInt ( const BYTE *  pData,
size_t  nSize,
bool  bNegativeOrNA 
)

DER format assumes 2s complement for numbers, the leftmost bit should be 0 for positive numbers and 1 for negative numbers.

  • bNegativeOrNA = true for unsigned or ignore sign.

◆ WriteTagInt() [2/3]

HRESULT GrayLib::cASNWriterRev::WriteTagInt ( const cBitArray X,
bool  bNegativeOrNA = false 
)

Write a big number (ASN_INTEGER) in ASN.1 format

Note
function works backwards in data buffer
  • X = the MPI to write
Returns
the length written or <0 = error

◆ WriteTagInt() [3/3]

HRESULT GrayLib::cASNWriterRev::WriteTagInt ( int  iVal)

Write an int tag (ASN_INTEGER) and value in ASN.1 format. Variable length.

Note
function works backwards in data buffer
  • iVal = the integer value
Returns
the length written or <0 = error opposite of ReadTagInt()
Todo:
FIXME negative values DER format assumes 2s complement for numbers, so the leftmost bit should be 0 for positive numbers and 1 for negative numbers.

◆ WriteTagNull()

HRESULT GrayLib::cASNWriterRev::WriteTagNull ( )

Write a ASN_NULL tag with zero data in ASN.1 format

Note
function works backwards in data buffer
Returns
the length written or <0 = error

◆ WriteTagOID()

HRESULT GrayLib::cASNWriterRev::WriteTagOID ( const char *  oid,
size_t  oid_len 
)

Write an OID tag (ASN_OID) and data in ASN.1 format

Note
function works backwards in data buffer
  • oid = the OID to write
  • oid_len = length of the OID
Returns
the length written or <0 = error

◆ WriteTagSeqAlg()

HRESULT GrayLib::cASNWriterRev::WriteTagSeqAlg ( const char *  oid,
size_t  oid_len 
)

Write an AlgorithmIdentifier sequence in ASN.1 format

Note
function works backwards in data buffer
  • oid = the OID of the algorithm
  • oid_len = length of the OID If 0, nullptr parameters are added
Returns
the length written or <0 = error

◆ WriteTagSeqAlg2()

HRESULT GrayLib::cASNWriterRev::WriteTagSeqAlg2 ( const char *  oid,
size_t  oid_len,
BYTE *  pSig,
size_t  size 
)

◆ WriteTagStringIA5()

HRESULT GrayLib::cASNWriterRev::WriteTagStringIA5 ( const char *  text,
StrLen_t  text_len = k_StrLen_UNK 
)

Write an IA5 string tag (ASN_StringIA5) and value in ASN.1 format

Note
function works backwards in data buffer
  • text = the text to write
  • text_len = length of the text
Returns
the length written or <0 = error

◆ WriteTagStringPrintable()

HRESULT GrayLib::cASNWriterRev::WriteTagStringPrintable ( const char *  text,
StrLen_t  text_len = k_StrLen_UNK 
)

Write a ASN_StringPrintable tag and value in ASN.1 format

Note
function works backwards in data buffer
  • text = the text to write
  • text_len = length of the text
Returns
the length written or <0 = error

◆ WriteTagTime() [1/2]

HRESULT GrayLib::cASNWriterRev::WriteTagTime ( const cTimeInt time,
TZ_TYPE  nTimeZoneOffset = TZ_LOCAL 
)

Write ASN_TimeUTC or ASN_TimeGeneral Compliment of ReadTagTime()

◆ WriteTagTime() [2/2]

HRESULT GrayLib::cASNWriterRev::WriteTagTime ( const cTimeUnits Tu)

Write ASN_TimeUTC or ASN_TimeGeneral Compliment of ReadTagTime() e.g. "20131231235959" for December 31st 2013 at 23:59:59

Member Data Documentation

◆ m_pOutCur

BYTE* GrayLib::cASNWriterRev::m_pOutCur
protected

current write position. Moves down.


The documentation for this class was generated from the following files: