2 * FreeRDP: A Remote Desktop Protocol Client
3 * ASN.1 Basic Encoding Rules (BER)
5 * Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
23 #include <freerdp/types.h>
24 #include <freerdp/utils/stream.h>
28 /* Class - bits 8 and 7 */
29 #define BER_CLASS_MASK 0xC0
30 #define BER_CLASS_UNIV 0x00 /* 0 0 */
31 #define BER_CLASS_APPL 0x40 /* 0 1 */
32 #define BER_CLASS_CTXT 0x80 /* 1 0 */
33 #define BER_CLASS_PRIV 0xC0 /* 1 1 */
36 #define BER_PC_MASK 0x20
37 #define BER_PRIMITIVE 0x00 /* 0 */
38 #define BER_CONSTRUCT 0x20 /* 1 */
40 /* Tag - bits 5 to 1 */
41 #define BER_TAG_MASK 0x1F
42 #define BER_TAG_BOOLEAN 0x01
43 #define BER_TAG_INTEGER 0x02
44 #define BER_TAG_BIT_STRING 0x03
45 #define BER_TAG_OCTET_STRING 0x04
46 #define BER_TAG_OBJECT_IDENFIER 0x06
47 #define BER_TAG_ENUMERATED 0x0A
48 #define BER_TAG_SEQUENCE 0x10
49 #define BER_TAG_SEQUENCE_OF 0x10
51 #define BER_PC(_pc) (_pc ? BER_CONSTRUCT : BER_PRIMITIVE)
53 void ber_read_length(STREAM* s, int* length);
54 int ber_write_length(STREAM* s, int length);
55 int _ber_skip_length(int length);
56 int ber_get_content_length(int length);
57 boolean ber_read_universal_tag(STREAM* s, uint8 tag, boolean pc);
58 void ber_write_universal_tag(STREAM* s, uint8 tag, boolean pc);
59 boolean ber_read_application_tag(STREAM* s, uint8 tag, int* length);
60 void ber_write_application_tag(STREAM* s, uint8 tag, int length);
61 boolean ber_read_application_tag(STREAM* s, uint8 tag, int* length);
62 boolean ber_read_enumerated(STREAM* s, uint8* enumerated, uint8 count);
63 void ber_write_enumerated(STREAM* s, uint8 enumerated, uint8 count);
64 boolean ber_read_contextual_tag(STREAM* s, uint8 tag, int* length, boolean pc);
65 int ber_write_contextual_tag(STREAM* s, uint8 tag, int length, boolean pc);
66 int ber_skip_contextual_tag(int length);
67 boolean ber_read_sequence_tag(STREAM* s, int* length);
68 int ber_write_sequence_tag(STREAM* s, int length);
69 int ber_skip_sequence(int length);
70 int ber_skip_sequence_tag(int length);
71 boolean ber_read_bit_string(STREAM* s, int* length, uint8* padding);
72 boolean ber_read_octet_string(STREAM* s, int* length);
73 void ber_write_octet_string(STREAM* s, const uint8* oct_str, int length);
74 int ber_write_octet_string_tag(STREAM* s, int length);
75 int ber_skip_octet_string(int length);
76 boolean ber_read_boolean(STREAM* s, boolean* value);
77 void ber_write_boolean(STREAM* s, boolean value);
78 boolean ber_read_integer(STREAM* s, uint32* value);
79 int ber_write_integer(STREAM* s, uint32 value);
80 boolean ber_read_integer_length(STREAM* s, int* length);
81 int ber_skip_integer(uint32 value);