22 #include <winpr/crt.h>
23 #include <winpr/assert.h>
24 #include <winpr/endian.h>
25 #include <winpr/asn1.h>
26 #include <winpr/stream.h>
33 WinPrAsn1Encoder* enc = NULL;
44 Data_Write_UINT16_BE(tok_id_buf, tok_id);
46 enc = WinPrAsn1Encoder_New(WINPR_ASN1_DER);
51 if (!WinPrAsn1EncAppContainer(enc, 0))
55 if (!WinPrAsn1EncOID(enc, oid))
59 if (!WinPrAsn1EncRawContent(enc, &mc))
63 mc.data = (BYTE*)token->data;
64 mc.len = token->length;
65 if (!WinPrAsn1EncRawContent(enc, &mc))
68 if (!WinPrAsn1EncEndContainer(enc))
71 if (!WinPrAsn1EncStreamSize(enc, &len) || len > buf->cbBuffer)
74 Stream_StaticInit(&s, buf->pvBuffer, len);
75 if (WinPrAsn1EncToStream(enc, &s))
77 buf->cbBuffer = (UINT32)len;
82 WinPrAsn1Encoder_Free(&enc);
91 WinPrAsn1_tagId tag = 0;
99 WinPrAsn1Decoder_InitMem(&dec, WINPR_ASN1_DER, buf->pvBuffer, buf->cbBuffer);
101 if (!WinPrAsn1DecReadApp(&dec, &tag, &dec2) || tag != 0)
104 if (!WinPrAsn1DecReadOID(&dec2, oid, FALSE))
107 sbuffer = WinPrAsn1DecGetStream(&dec2);
110 if (Stream_Length(s) < 2)
114 Stream_Read_INT16_BE(s, *tok_id);
116 token->data = Stream_Pointer(s);
117 token->length = (UINT)Stream_GetRemainingLength(s);