FreeRDP
|
Data Structures | |
struct | WinPrAsn1Decoder |
struct | WinPrAsn1_MemoryChunk |
struct | WinPrAsn1_UTCTIME |
Macros | |
#define | ER_TAG_MASK 0x1F |
Typedefs | |
typedef BYTE | WinPrAsn1_tag |
typedef BYTE | WinPrAsn1_tagId |
typedef BOOL | WinPrAsn1_BOOL |
typedef INT32 | WinPrAsn1_INTEGER |
typedef INT32 | WinPrAsn1_ENUMERATED |
typedef char * | WinPrAsn1_STRING |
typedef char * | WinPrAsn1_IA5STRING |
typedef WinPrAsn1_MemoryChunk | WinPrAsn1_OID |
typedef WinPrAsn1_MemoryChunk | WinPrAsn1_OctetString |
Enumerations | |
enum | { ER_TAG_BOOLEAN = 0x01 , ER_TAG_INTEGER = 0x02 , ER_TAG_BIT_STRING = 0x03 , ER_TAG_OCTET_STRING = 0x04 , ER_TAG_NULL = 0x05 , ER_TAG_OBJECT_IDENTIFIER = 0x06 , ER_TAG_ENUMERATED = 0x0A , ER_TAG_UTF8STRING = 0x0C , ER_TAG_PRINTABLE_STRING = 0x13 , ER_TAG_IA5STRING = 0x16 , ER_TAG_UTCTIME = 0x17 , ER_TAG_GENERAL_STRING = 0x1B , ER_TAG_GENERALIZED_TIME = 0x18 , ER_TAG_APP = 0x60 , ER_TAG_SEQUENCE = 0x30 , ER_TAG_SEQUENCE_OF = 0x30 , ER_TAG_SET = 0x31 , ER_TAG_SET_OF = 0x31 , ER_TAG_CONTEXTUAL = 0xA0 } |
enum | WinPrAsn1EncodingRule { WINPR_ASN1_BER , WINPR_ASN1_DER } |
rules for encoding More... | |
#define ER_TAG_MASK 0x1F |
WinPR: Windows Portable Runtime ASN1 encoder / decoder
Copyright 2022 David Fort conta ct@h arden ing- consu ltin g.com
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
typedef BOOL WinPrAsn1_BOOL |
typedef INT32 WinPrAsn1_ENUMERATED |
typedef char* WinPrAsn1_IA5STRING |
typedef INT32 WinPrAsn1_INTEGER |
typedef WinPrAsn1_MemoryChunk WinPrAsn1_OID |
typedef char* WinPrAsn1_STRING |
typedef BYTE WinPrAsn1_tag |
typedef BYTE WinPrAsn1_tagId |
anonymous enum |
WINPR_API wStream WinPrAsn1DecGetStream | ( | WinPrAsn1Decoder * | dec | ) |
WINPR_API void WinPrAsn1Decoder_Init | ( | WinPrAsn1Decoder * | dec, |
WinPrAsn1EncodingRule | encoding, | ||
wStream * | source | ||
) |
WINPR_API void WinPrAsn1Decoder_InitMem | ( | WinPrAsn1Decoder * | dec, |
WinPrAsn1EncodingRule | encoding, | ||
const BYTE * | source, | ||
size_t | len | ||
) |
WINPR_API size_t WinPrAsn1DecPeekContextualTag | ( | WinPrAsn1Decoder * | dec, |
WinPrAsn1_tagId * | tagId, | ||
WinPrAsn1Decoder * | ctxtDec | ||
) |
WINPR_API BOOL WinPrAsn1DecPeekTag | ( | WinPrAsn1Decoder * | dec, |
WinPrAsn1_tag * | tag | ||
) |
WINPR_API size_t WinPrAsn1DecPeekTagAndLen | ( | WinPrAsn1Decoder * | dec, |
WinPrAsn1_tag * | tag, | ||
size_t * | len | ||
) |
WINPR_API size_t WinPrAsn1DecReadApp | ( | WinPrAsn1Decoder * | dec, |
WinPrAsn1_tagId * | tagId, | ||
WinPrAsn1Decoder * | setDec | ||
) |
WINPR_API size_t WinPrAsn1DecReadBoolean | ( | WinPrAsn1Decoder * | dec, |
WinPrAsn1_BOOL * | target | ||
) |
WINPR_API size_t WinPrAsn1DecReadContextualBool | ( | WinPrAsn1Decoder * | dec, |
WinPrAsn1_tagId | tagId, | ||
BOOL * | error, | ||
WinPrAsn1_BOOL * | target | ||
) |
WINPR_API size_t WinPrAsn1DecReadContextualInteger | ( | WinPrAsn1Decoder * | dec, |
WinPrAsn1_tagId | tagId, | ||
BOOL * | error, | ||
WinPrAsn1_INTEGER * | target | ||
) |
WINPR_API size_t WinPrAsn1DecReadContextualOctetString | ( | WinPrAsn1Decoder * | dec, |
WinPrAsn1_tagId | tagId, | ||
BOOL * | error, | ||
WinPrAsn1_OctetString * | target, | ||
BOOL | allocate | ||
) |
WINPR_API size_t WinPrAsn1DecReadContextualOID | ( | WinPrAsn1Decoder * | dec, |
WinPrAsn1_tagId | tagId, | ||
BOOL * | error, | ||
WinPrAsn1_OID * | target, | ||
BOOL | allocate | ||
) |
WINPR_API size_t WinPrAsn1DecReadContextualSequence | ( | WinPrAsn1Decoder * | dec, |
WinPrAsn1_tagId | tagId, | ||
BOOL * | error, | ||
WinPrAsn1Decoder * | target | ||
) |
WINPR_API size_t WinPrAsn1DecReadContextualTag | ( | WinPrAsn1Decoder * | dec, |
WinPrAsn1_tagId * | tagId, | ||
WinPrAsn1Decoder * | ctxtDec | ||
) |
WINPR_API size_t WinPrAsn1DecReadEnumerated | ( | WinPrAsn1Decoder * | dec, |
WinPrAsn1_ENUMERATED * | target | ||
) |
WINPR_API size_t WinPrAsn1DecReadGeneralString | ( | WinPrAsn1Decoder * | dec, |
WinPrAsn1_STRING * | target | ||
) |
WINPR_API size_t WinPrAsn1DecReadIA5String | ( | WinPrAsn1Decoder * | dec, |
WinPrAsn1_IA5STRING * | target | ||
) |
WINPR_API size_t WinPrAsn1DecReadInteger | ( | WinPrAsn1Decoder * | dec, |
WinPrAsn1_INTEGER * | target | ||
) |
WINPR_API size_t WinPrAsn1DecReadNull | ( | WinPrAsn1Decoder * | dec | ) |
WINPR_API size_t WinPrAsn1DecReadOctetString | ( | WinPrAsn1Decoder * | dec, |
WinPrAsn1_OctetString * | target, | ||
BOOL | allocate | ||
) |
WINPR_API size_t WinPrAsn1DecReadOID | ( | WinPrAsn1Decoder * | dec, |
WinPrAsn1_OID * | target, | ||
BOOL | allocate | ||
) |
WINPR_API size_t WinPrAsn1DecReadSequence | ( | WinPrAsn1Decoder * | dec, |
WinPrAsn1Decoder * | seqDec | ||
) |
WINPR_API size_t WinPrAsn1DecReadSet | ( | WinPrAsn1Decoder * | dec, |
WinPrAsn1Decoder * | setDec | ||
) |
WINPR_API size_t WinPrAsn1DecReadTagAndLen | ( | WinPrAsn1Decoder * | dec, |
WinPrAsn1_tag * | tag, | ||
size_t * | len | ||
) |
WINPR_API size_t WinPrAsn1DecReadTagLenValue | ( | WinPrAsn1Decoder * | dec, |
WinPrAsn1_tag * | tag, | ||
size_t * | len, | ||
WinPrAsn1Decoder * | value | ||
) |
WINPR_API size_t WinPrAsn1DecReadUtcTime | ( | WinPrAsn1Decoder * | dec, |
WinPrAsn1_UTCTIME * | target | ||
) |
WINPR_API BOOL WinPrAsn1EncAppContainer | ( | WinPrAsn1Encoder * | enc, |
WinPrAsn1_tagId | tagId | ||
) |
WINPR_API size_t WinPrAsn1EncBoolean | ( | WinPrAsn1Encoder * | enc, |
WinPrAsn1_BOOL | b | ||
) |
WINPR_API size_t WinPrAsn1EncContextualBoolean | ( | WinPrAsn1Encoder * | enc, |
WinPrAsn1_tagId | tagId, | ||
WinPrAsn1_BOOL | b | ||
) |
WINPR_API BOOL WinPrAsn1EncContextualContainer | ( | WinPrAsn1Encoder * | enc, |
WinPrAsn1_tagId | tagId | ||
) |
WINPR_API size_t WinPrAsn1EncContextualEnumerated | ( | WinPrAsn1Encoder * | enc, |
WinPrAsn1_tagId | tagId, | ||
WinPrAsn1_ENUMERATED | e | ||
) |
WINPR_API size_t WinPrAsn1EncContextualIA5String | ( | WinPrAsn1Encoder * | enc, |
WinPrAsn1_tagId | tagId, | ||
WinPrAsn1_IA5STRING | ia5 | ||
) |
WINPR_API size_t WinPrAsn1EncContextualInteger | ( | WinPrAsn1Encoder * | enc, |
WinPrAsn1_tagId | tagId, | ||
WinPrAsn1_INTEGER | integer | ||
) |
WINPR_API size_t WinPrAsn1EncContextualOctetString | ( | WinPrAsn1Encoder * | enc, |
WinPrAsn1_tagId | tagId, | ||
const WinPrAsn1_OctetString * | oid | ||
) |
WINPR_API BOOL WinPrAsn1EncContextualOctetStringContainer | ( | WinPrAsn1Encoder * | enc, |
WinPrAsn1_tagId | tagId | ||
) |
WINPR_API size_t WinPrAsn1EncContextualOID | ( | WinPrAsn1Encoder * | enc, |
WinPrAsn1_tagId | tagId, | ||
const WinPrAsn1_OID * | oid | ||
) |
WINPR_API size_t WinPrAsn1EncContextualRawContent | ( | WinPrAsn1Encoder * | enc, |
WinPrAsn1_tagId | tagId, | ||
const WinPrAsn1_MemoryChunk * | c | ||
) |
WINPR_API BOOL WinPrAsn1EncContextualSeqContainer | ( | WinPrAsn1Encoder * | enc, |
WinPrAsn1_tagId | tagId | ||
) |
WINPR_API BOOL WinPrAsn1EncContextualSetContainer | ( | WinPrAsn1Encoder * | enc, |
WinPrAsn1_tagId | tagId | ||
) |
WINPR_API size_t WinPrAsn1EncContextualUtcTime | ( | WinPrAsn1Encoder * | enc, |
WinPrAsn1_tagId | tagId, | ||
const WinPrAsn1_UTCTIME * | utc | ||
) |
WINPR_API size_t WinPrAsn1EncEndContainer | ( | WinPrAsn1Encoder * | enc | ) |
WINPR_API size_t WinPrAsn1EncEnumerated | ( | WinPrAsn1Encoder * | enc, |
WinPrAsn1_ENUMERATED | e | ||
) |
WINPR_API size_t WinPrAsn1EncGeneralString | ( | WinPrAsn1Encoder * | enc, |
WinPrAsn1_STRING | str | ||
) |
WINPR_API size_t WinPrAsn1EncIA5String | ( | WinPrAsn1Encoder * | enc, |
WinPrAsn1_IA5STRING | ia5 | ||
) |
WINPR_API size_t WinPrAsn1EncInteger | ( | WinPrAsn1Encoder * | enc, |
WinPrAsn1_INTEGER | integer | ||
) |
WINPR_API size_t WinPrAsn1EncOctetString | ( | WinPrAsn1Encoder * | enc, |
const WinPrAsn1_OctetString * | oid | ||
) |
WINPR_API BOOL WinPrAsn1EncOctetStringContainer | ( | WinPrAsn1Encoder * | enc | ) |
WINPR_API void WinPrAsn1Encoder_Free | ( | WinPrAsn1Encoder ** | penc | ) |
WINPR_API WinPrAsn1Encoder* WinPrAsn1Encoder_New | ( | WinPrAsn1EncodingRule | encoding | ) |
The encoder is implemented with the goals to:
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.
WINPR_API void WinPrAsn1Encoder_Reset | ( | WinPrAsn1Encoder * | enc | ) |
WINPR_API size_t WinPrAsn1EncOID | ( | WinPrAsn1Encoder * | enc, |
const WinPrAsn1_OID * | oid | ||
) |
WINPR_API size_t WinPrAsn1EncRawContent | ( | WinPrAsn1Encoder * | enc, |
const WinPrAsn1_MemoryChunk * | c | ||
) |
WINPR_API BOOL WinPrAsn1EncSeqContainer | ( | WinPrAsn1Encoder * | enc | ) |
WINPR_API BOOL WinPrAsn1EncSetContainer | ( | WinPrAsn1Encoder * | enc | ) |
WINPR_API BOOL WinPrAsn1EncStreamSize | ( | WinPrAsn1Encoder * | enc, |
size_t * | s | ||
) |
WINPR_API size_t WinPrAsn1EncUtcTime | ( | WinPrAsn1Encoder * | enc, |
const WinPrAsn1_UTCTIME * | utc | ||
) |
WINPR_API void WinPrAsn1FreeOctetString | ( | WinPrAsn1_OctetString * | octets | ) |
WINPR_API void WinPrAsn1FreeOID | ( | WinPrAsn1_OID * | poid | ) |