|
void | WinPrAsn1FreeOID (WinPrAsn1_OID *poid) |
|
void | WinPrAsn1FreeOctetString (WinPrAsn1_OctetString *octets) |
|
WinPrAsn1Encoder * | WinPrAsn1Encoder_New (WinPrAsn1EncodingRule encoding) |
|
void | WinPrAsn1Encoder_Reset (WinPrAsn1Encoder *enc) |
|
void | WinPrAsn1Encoder_Free (WinPrAsn1Encoder **penc) |
|
static Asn1Chunk * | asn1enc_get_free_chunk (WinPrAsn1Encoder *enc, size_t chunkSz, BOOL commit, size_t *id) |
|
static WinPrAsn1EncContainer * | asn1enc_get_free_container (WinPrAsn1Encoder *enc, size_t *id) |
|
static size_t | lenBytes (size_t len) |
|
static void | asn1WriteLen (wStream *s, size_t len) |
|
static WinPrAsn1EncContainer * | getAsn1Container (WinPrAsn1Encoder *enc, ContainerType ctype, WinPrAsn1_tag tag, BOOL contextual, size_t maxLen) |
|
BOOL | WinPrAsn1EncAppContainer (WinPrAsn1Encoder *enc, WinPrAsn1_tagId tagId) |
|
BOOL | WinPrAsn1EncSeqContainer (WinPrAsn1Encoder *enc) |
|
BOOL | WinPrAsn1EncSetContainer (WinPrAsn1Encoder *enc) |
|
BOOL | WinPrAsn1EncContextualSeqContainer (WinPrAsn1Encoder *enc, WinPrAsn1_tagId tagId) |
|
BOOL | WinPrAsn1EncContextualSetContainer (WinPrAsn1Encoder *enc, WinPrAsn1_tagId tagId) |
|
BOOL | WinPrAsn1EncContextualContainer (WinPrAsn1Encoder *enc, WinPrAsn1_tagId tagId) |
|
BOOL | WinPrAsn1EncOctetStringContainer (WinPrAsn1Encoder *enc) |
|
BOOL | WinPrAsn1EncContextualOctetStringContainer (WinPrAsn1Encoder *enc, WinPrAsn1_tagId tagId) |
|
size_t | WinPrAsn1EncEndContainer (WinPrAsn1Encoder *enc) |
|
static BOOL | asn1_getWriteStream (WinPrAsn1Encoder *enc, size_t len, wStream *s) |
|
size_t | WinPrAsn1EncRawContent (WinPrAsn1Encoder *enc, const WinPrAsn1_MemoryChunk *c) |
|
size_t | WinPrAsn1EncContextualRawContent (WinPrAsn1Encoder *enc, WinPrAsn1_tagId tagId, const WinPrAsn1_MemoryChunk *c) |
|
static size_t | asn1IntegerLen (WinPrAsn1_INTEGER value) |
|
static size_t | WinPrAsn1EncIntegerLike (WinPrAsn1Encoder *enc, WinPrAsn1_tag b, WinPrAsn1_INTEGER value) |
|
size_t | WinPrAsn1EncInteger (WinPrAsn1Encoder *enc, WinPrAsn1_INTEGER value) |
|
size_t | WinPrAsn1EncEnumerated (WinPrAsn1Encoder *enc, WinPrAsn1_ENUMERATED value) |
|
static size_t | WinPrAsn1EncContextualIntegerLike (WinPrAsn1Encoder *enc, WinPrAsn1_tag tag, WinPrAsn1_tagId tagId, WinPrAsn1_INTEGER value) |
|
size_t | WinPrAsn1EncContextualInteger (WinPrAsn1Encoder *enc, WinPrAsn1_tagId tagId, WinPrAsn1_INTEGER value) |
|
size_t | WinPrAsn1EncContextualEnumerated (WinPrAsn1Encoder *enc, WinPrAsn1_tagId tagId, WinPrAsn1_ENUMERATED value) |
|
size_t | WinPrAsn1EncBoolean (WinPrAsn1Encoder *enc, WinPrAsn1_BOOL b) |
|
size_t | WinPrAsn1EncContextualBoolean (WinPrAsn1Encoder *enc, WinPrAsn1_tagId tagId, WinPrAsn1_BOOL b) |
|
static size_t | WinPrAsn1EncMemoryChunk (WinPrAsn1Encoder *enc, BYTE wireType, const WinPrAsn1_MemoryChunk *mchunk) |
|
size_t | WinPrAsn1EncOID (WinPrAsn1Encoder *enc, const WinPrAsn1_OID *oid) |
|
size_t | WinPrAsn1EncOctetString (WinPrAsn1Encoder *enc, const WinPrAsn1_OctetString *octets) |
|
size_t | WinPrAsn1EncIA5String (WinPrAsn1Encoder *enc, WinPrAsn1_IA5STRING ia5) |
|
size_t | WinPrAsn1EncGeneralString (WinPrAsn1Encoder *enc, WinPrAsn1_STRING str) |
|
static size_t | WinPrAsn1EncContextualMemoryChunk (WinPrAsn1Encoder *enc, BYTE wireType, WinPrAsn1_tagId tagId, const WinPrAsn1_MemoryChunk *mchunk) |
|
size_t | WinPrAsn1EncContextualOID (WinPrAsn1Encoder *enc, WinPrAsn1_tagId tagId, const WinPrAsn1_OID *oid) |
|
size_t | WinPrAsn1EncContextualOctetString (WinPrAsn1Encoder *enc, WinPrAsn1_tagId tagId, const WinPrAsn1_OctetString *octets) |
|
size_t | WinPrAsn1EncContextualIA5String (WinPrAsn1Encoder *enc, WinPrAsn1_tagId tagId, WinPrAsn1_IA5STRING ia5) |
|
static void | write2digit (wStream *s, UINT8 v) |
|
size_t | WinPrAsn1EncUtcTime (WinPrAsn1Encoder *enc, const WinPrAsn1_UTCTIME *utc) |
|
size_t | WinPrAsn1EncContextualUtcTime (WinPrAsn1Encoder *enc, WinPrAsn1_tagId tagId, const WinPrAsn1_UTCTIME *utc) |
|
BOOL | WinPrAsn1EncStreamSize (WinPrAsn1Encoder *enc, size_t *s) |
|
BOOL | WinPrAsn1EncToStream (WinPrAsn1Encoder *enc, wStream *s) |
|
void | WinPrAsn1Decoder_Init (WinPrAsn1Decoder *decoder, WinPrAsn1EncodingRule encoding, wStream *source) |
|
void | WinPrAsn1Decoder_InitMem (WinPrAsn1Decoder *decoder, WinPrAsn1EncodingRule encoding, const BYTE *source, size_t len) |
|
BOOL | WinPrAsn1DecPeekTag (WinPrAsn1Decoder *dec, WinPrAsn1_tag *tag) |
|
static size_t | readLen (wStream *s, size_t *len, BOOL derCheck) |
|
static size_t | readTagAndLen (WinPrAsn1Decoder *dec, wStream *s, WinPrAsn1_tag *tag, size_t *len) |
|
size_t | WinPrAsn1DecReadTagAndLen (WinPrAsn1Decoder *dec, WinPrAsn1_tag *tag, size_t *len) |
|
size_t | WinPrAsn1DecPeekTagAndLen (WinPrAsn1Decoder *dec, WinPrAsn1_tag *tag, size_t *len) |
|
size_t | WinPrAsn1DecReadTagLenValue (WinPrAsn1Decoder *dec, WinPrAsn1_tag *tag, size_t *len, WinPrAsn1Decoder *value) |
|
size_t | WinPrAsn1DecReadBoolean (WinPrAsn1Decoder *dec, WinPrAsn1_BOOL *target) |
|
static size_t | WinPrAsn1DecReadIntegerLike (WinPrAsn1Decoder *dec, WinPrAsn1_tag expectedTag, WinPrAsn1_INTEGER *target) |
|
size_t | WinPrAsn1DecReadInteger (WinPrAsn1Decoder *dec, WinPrAsn1_INTEGER *target) |
|
size_t | WinPrAsn1DecReadEnumerated (WinPrAsn1Decoder *dec, WinPrAsn1_ENUMERATED *target) |
|
static size_t | WinPrAsn1DecReadMemoryChunkLike (WinPrAsn1Decoder *dec, WinPrAsn1_tag expectedTag, WinPrAsn1_MemoryChunk *target, BOOL allocate) |
|
size_t | WinPrAsn1DecReadOID (WinPrAsn1Decoder *dec, WinPrAsn1_OID *target, BOOL allocate) |
|
size_t | WinPrAsn1DecReadOctetString (WinPrAsn1Decoder *dec, WinPrAsn1_OctetString *target, BOOL allocate) |
|
size_t | WinPrAsn1DecReadIA5String (WinPrAsn1Decoder *dec, WinPrAsn1_IA5STRING *target) |
|
size_t | WinPrAsn1DecReadGeneralString (WinPrAsn1Decoder *dec, WinPrAsn1_STRING *target) |
|
static int | read2digits (wStream *s) |
|
size_t | WinPrAsn1DecReadUtcTime (WinPrAsn1Decoder *dec, WinPrAsn1_UTCTIME *target) |
|
size_t | WinPrAsn1DecReadNull (WinPrAsn1Decoder *dec) |
|
static size_t | readConstructed (WinPrAsn1Decoder *dec, wStream *s, WinPrAsn1_tag *tag, WinPrAsn1Decoder *target) |
|
size_t | WinPrAsn1DecReadApp (WinPrAsn1Decoder *dec, WinPrAsn1_tagId *tagId, WinPrAsn1Decoder *target) |
|
size_t | WinPrAsn1DecReadSequence (WinPrAsn1Decoder *dec, WinPrAsn1Decoder *target) |
|
size_t | WinPrAsn1DecReadSet (WinPrAsn1Decoder *dec, WinPrAsn1Decoder *target) |
|
static size_t | readContextualTag (WinPrAsn1Decoder *dec, wStream *s, WinPrAsn1_tagId *tagId, WinPrAsn1Decoder *ctxtDec) |
|
size_t | WinPrAsn1DecReadContextualTag (WinPrAsn1Decoder *dec, WinPrAsn1_tagId *tagId, WinPrAsn1Decoder *ctxtDec) |
|
size_t | WinPrAsn1DecPeekContextualTag (WinPrAsn1Decoder *dec, WinPrAsn1_tagId *tagId, WinPrAsn1Decoder *ctxtDec) |
|
static size_t | readContextualHeader (WinPrAsn1Decoder *dec, WinPrAsn1_tagId tagId, BOOL *error, WinPrAsn1Decoder *content) |
|
size_t | WinPrAsn1DecReadContextualBool (WinPrAsn1Decoder *dec, WinPrAsn1_tagId tagId, BOOL *error, WinPrAsn1_BOOL *target) |
|
size_t | WinPrAsn1DecReadContextualInteger (WinPrAsn1Decoder *dec, WinPrAsn1_tagId tagId, BOOL *error, WinPrAsn1_INTEGER *target) |
|
size_t | WinPrAsn1DecReadContextualOID (WinPrAsn1Decoder *dec, WinPrAsn1_tagId tagId, BOOL *error, WinPrAsn1_OID *target, BOOL allocate) |
|
size_t | WinPrAsn1DecReadContextualOctetString (WinPrAsn1Decoder *dec, WinPrAsn1_tagId tagId, BOOL *error, WinPrAsn1_OctetString *target, BOOL allocate) |
|
size_t | WinPrAsn1DecReadContextualSequence (WinPrAsn1Decoder *dec, WinPrAsn1_tagId tagId, BOOL *error, WinPrAsn1Decoder *target) |
|
wStream | WinPrAsn1DecGetStream (WinPrAsn1Decoder *dec) |
|
The encoder is implemented with the goals to:
- have an API which is convenient to use (avoid computing inner elements size)
- hide the BER/DER encoding details
- avoid multiple copies and memory moves when building the content
To achieve this, the encoder contains a big memory block (encoder->pool), and various chunks (encoder->chunks) pointing to that memory block. The idea is to reserve some space in the pool for the container headers when we start a new container element. For example when a sequence is started we reserve 6 bytes which is the maximum size: byte0 + length. Then fill the content of the sequence in further chunks. When a container is closed, we compute the inner size (by adding the size of inner chunks), we write the headers bytes, and we adjust the chunk size accordingly.
For example to encode: SEQ IASTRING(test1) INTEGER(200)
with this code:
WinPrAsn1EncSeqContainer(enc);
WinPrAsn1EncIA5String(enc, "test1");
WinPrAsn1EncInteger(enc, 200);
Memory pool and chunks would look like:
[ reserved for seq][string|5|"test1"][integer|0x81|200] (6 bytes) |--------------—||-------------------------------—| ^ ^ | | chunk0 chunk1
As we try to compact chunks as much as we can, we managed to encode the ia5string and the integer using the same chunk.
When the sequence is closed with:
WinPrAsn1EncEndContainer(enc);
The final pool and chunks will look like:
XXXXXX[seq headers][string|5|"test1"][integer|0x81|200]
|-----------||----------------------------------|
^ ^
| |
chunk0 chunk1
The generated content can be retrieved using:
WinPrAsn1EncToStream(enc, targetStream);
It will sequentially write all the chunks in the given target stream.