![]() |
Gray C++ Libraries
0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
|
#include <cASNReader.h>
Public Member Functions | |
cASNReader (const BYTE *p=nullptr, size_t nSize=0) noexcept | |
cASNReader (const cMemBlock &b) noexcept | |
void | SetBlock (const BYTE *p, size_t nSize) |
size_t | get_LenRead () const |
size_t | get_LenLeft () const |
bool | isEOF () const |
bool | isEOFX () const |
const BYTE * | get_InpCur () const noexcept |
BYTE * | get_InpUnk () const |
BYTE | get_InpByte () const |
void | AddInpCur (size_t nSize) |
void | AddInpCur (cMemBlock &r) |
void | ResetReader () |
HRESULT | ReadTagBlock (ASN_t nTagExpected, OUT cMemBlock &r) |
HRESULT | ReadTagBuf (ASN_t nTagExpected, OUT cASNBuf &r) |
HRESULT | ReadTagChild (ASN_t nTagExpected, OUT cASNReader &r) |
HRESULT | ReadTagBoolean (OUT bool &rVal) |
HRESULT | ReadTagInt (OUT int &riVal) |
HRESULT | ReadTagArrayBits (OUT cASNBuf &bs) |
HRESULT | ReadTagArrayBits0 (OUT size_t &rSizeData) |
HRESULT | ReadTagBigInt (OUT cBitArray &X) |
HRESULT | ReadTagTime (OUT cTimeUnits &time) |
HRESULT | ReadTagSequence (ASN_TYPE tag, cASNSequence &head) |
HRESULT | ReadTagSeqAlg (OUT cASNBuf &alg, OUT cASNBuf ¶ms) |
HRESULT | ReadTagSeqAlgNull (OUT cASNBuf &alg) |
HRESULT | ReadSets (OUT cASNSets &cur) |
![]() | |
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 |
Static Public Member Functions | |
static HRESULT | ReadInt (const BYTE *pData, size_t nSizeData, OUT int &riVal) |
static HRESULT | ReadTime (const char *pData, size_t nSizeData, bool bGeneral, OUT cTimeUnits &time) |
![]() | |
static COMPARE_t __stdcall | Compare (const void *pData1, size_t iLen1, const void *pData2, size_t iLen2) |
Protected Member Functions | |
HRESULT | ReadLengthCode (OUT size_t &rSize) |
HRESULT | ReadTag (ASN_t nTagExpected, OUT size_t &rSizeData) |
Static Protected Member Functions | |
static HRESULT | ReadStrUInt (const char *pData, size_t nSizeData, OUT UINT32 &ruVal) |
Protected Attributes | |
const BYTE * | m_pInpCur |
Current read position in cMemBlock. This Advances. More... | |
![]() | |
size_t | m_nSize |
size_t of m_pData in bytes. May be determined at runtime. More... | |
void * | m_pData |
Friends | |
class | cASNBuf |
class | cASNSequence |
Helper class for reading/parsing an ASN blob that has been loaded into memory. Used for DER format. Similar to cStreamStatic. Opposite of cASNWriterRev
|
inlinenoexcept |
Create reader for bytes.
|
inlinenoexcept |
Create reader for buffer.
|
inline |
Skip a whole block.
|
inline |
Advance/Seek position of m_pInpCur.
|
inline |
get BYTE at the current read position. No advance.
|
inlinenoexcept |
get current read position/cursor. This Advances via Read* or AddInpCur().
|
inline |
get read position. Special version for when i don't know if I might modify it or not.
|
inline |
How much is left to read in the buffer? bytes.
|
inline |
How much have I read? bytes.
|
inline |
is m_pInpCur at or after the end of block?
|
inline |
is m_pInpCur Exactly at end of block?
|
static |
Read packed integer value.
|
protected |
Read a variable length prefix according to ASN.1 DER decoding routines Get the length of an ASN.1 element. Updates the read pointer. opposite of WriteLengthCode();
Name ::= CHOICE { – only one possibility for now – rdnSequence RDNSequence }
RDNSequence ::= SEQUENCE OF RelativeDistinguishedName
RelativeDistinguishedName ::= SET OF AttributeTypeAndValue
AttributeTypeAndValue ::= SEQUENCE { type AttributeType, value AttributeValue }
AttributeType ::= OBJECT IDENTIFIER
AttributeValue ::= ANY DEFINED BY AttributeType
The data structure is optimized for the common case where each RDN has only one element, which is represented as a list of AttributeTypeAndValue. For the general case we still use a flat list, but we mark elements of the same set so that they are "merged" together in the functions that consume this list, eg GetDescriptionSets().
don't use recursion, we'd risk stack overflow if not optimized
|
staticprotected |
Reads string as DWORD 32 nSize = 4 .
Read the expected tag and the length code that follows. Get the tag and length of the tag. Check for the requested tag. Updates the pointer to immediately behind the tag and length.
Retrieve a ASN_ArrayBits ASN.1 tag and its value. Updates the pointer to immediately behind the full tag.
HRESULT GrayLib::cASNReader::ReadTagArrayBits0 | ( | OUT size_t & | rSizeData | ) |
Retrieve a ASN_ArrayBits ASN.1 tag without unused bits and its value.
Retrieve a MPI value from an integer ASN.1 tag. ASN_INTEGER Updates the pointer to immediately behind the full tag.
Read the ASN block and store it as cASNBuf/cASNReader
HRESULT GrayLib::cASNReader::ReadTagBoolean | ( | OUT bool & | rVal | ) |
Retrieve a ASN_BOOLEAN ASN.1 tag and its value. Updates the pointer to immediately behind the full tag.
Read the ASN block and store it as cASNBuf/cASNReader
HRESULT GrayLib::cASNReader::ReadTagChild | ( | ASN_t | nTagExpected, |
OUT cASNReader & | r | ||
) |
Read the ASN block and store it as cASNReader. skip reading it as a cASNBuf.
HRESULT GrayLib::cASNReader::ReadTagInt | ( | OUT int & | riVal | ) |
Retrieve an ASN_INTEGER ASN.1 tag and its value. Updates the pointer to immediately behind the full tag.
Parse an AlgorithmIdentifier with (optional) parameters Retrieve an AlgorithmIdentifier ASN.1 sequence. Updates the pointer to immediately behind the full AlgorithmIdentifier.
Retrieve an AlgorithmIdentifier ASN.1 sequence with nullptr or no params. (eg for signatures) Updates the pointer to immediately behind the full AlgorithmIdentifier.
HRESULT GrayLib::cASNReader::ReadTagSequence | ( | ASN_TYPE | tag, |
cASNSequence & | head | ||
) |
Parses and splits an ASN.1 "SEQUENCE OF <tag>" Updated the pointer to immediately behind the full sequence tag.
HRESULT GrayLib::cASNReader::ReadTagTime | ( | OUT cTimeUnits & | time | ) |
TIME_FORMAT_ASN Data for ASN_TimeGeneral Time ::= CHOICE { utcTime UTCTime, generalTime GeneralizedTime } e.g. "" or "" compliment of WriteTagTime()
|
static |
"YYYYMMDDhhmmss" or "YYMMDDhhmmss"
|
inline |
Seek back to start.
|
inline |
|
friend |
|
friend |
|
protected |
Current read position in cMemBlock. This Advances.