20 #include <freerdp/config.h>
22 #include <winpr/crt.h>
24 #include <freerdp/crypto/der.h>
26 int _der_skip_length(
int length)
28 if (length > 0x7F && length <= 0xFF)
30 else if (length > 0xFF)
36 int der_write_length(
wStream* s,
int length)
38 if (length > 0x7F && length <= 0xFF)
40 Stream_Write_UINT8(s, 0x81);
41 Stream_Write_UINT8(s, length);
44 else if (length > 0xFF)
46 Stream_Write_UINT8(s, 0x82);
47 Stream_Write_UINT16_BE(s, length);
52 Stream_Write_UINT8(s, length);
57 int der_get_content_length(
int length)
59 if (length > 0x81 && length <= 0x102)
61 else if (length > 0x102)
67 int der_skip_contextual_tag(
int length)
69 return _der_skip_length(length) + 1;
72 int der_write_contextual_tag(
wStream* s, BYTE tag,
int length, BOOL pc)
74 Stream_Write_UINT8(s, (ER_CLASS_CTXT | ER_PC(pc)) | (ER_TAG_MASK & tag));
75 return der_write_length(s, length) + 1;
78 static void der_write_universal_tag(
wStream* s, BYTE tag, BOOL pc)
80 Stream_Write_UINT8(s, (ER_CLASS_UNIV | ER_PC(pc)) | (ER_TAG_MASK & tag));
83 int der_skip_octet_string(
int length)
85 return 1 + _der_skip_length(length) + length;
88 void der_write_octet_string(
wStream* s, BYTE* oct_str,
int length)
90 der_write_universal_tag(s, ER_TAG_OCTET_STRING, FALSE);
91 der_write_length(s, length);
92 Stream_Write(s, oct_str, length);
95 int der_skip_sequence_tag(
int length)
97 return 1 + _der_skip_length(length);
100 int der_write_sequence_tag(
wStream* s,
int length)
102 Stream_Write_UINT8(s, (ER_CLASS_UNIV | ER_CONSTRUCT) | (ER_TAG_MASK & ER_TAG_SEQUENCE));
103 return der_write_length(s, length) + 1;