ReactOS 0.4.16-dev-136-g52192f1
asn.c
Go to the documentation of this file.
1/* -*- c-basic-offset: 8 -*-
2 rdesktop: A Remote Desktop Protocol client.
3 ASN.1 utility functions
4 Copyright 2012 Henrik Andersson <hean01@cendio.se> for Cendio AB
5
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#include "precomp.h"
21
22
23/* Parse an ASN.1 BER header */
25ber_parse_header(STREAM s, int tagval, int *length)
26{
27 int tag, len;
28
29 if (tagval > 0xff)
30 {
32 }
33 else
34 {
35 in_uint8(s, tag);
36 }
37
38 if (tag != tagval)
39 {
40 error("expected tag %d, got %d\n", tagval, tag);
41 return False;
42 }
43
44 in_uint8(s, len);
45
46 if (len & 0x80)
47 {
48 len &= ~0x80;
49 *length = 0;
50 while (len--)
51 next_be(s, *length);
52 }
53 else
54 *length = len;
55
56 return s_check(s);
57}
58
59/* Output an ASN.1 BER header */
60void
61ber_out_header(STREAM s, int tagval, int length)
62{
63 if (tagval > 0xff)
64 {
65 out_uint16_be(s, tagval);
66 }
67 else
68 {
69 out_uint8(s, tagval);
70 }
71
72 if (length >= 0x80)
73 {
74 out_uint8(s, 0x82);
76 }
77 else
79}
80
81/* Output an ASN.1 BER integer */
82void
84{
87}
88
90ber_in_header(STREAM s, int *tagval, int *decoded_len)
91{
92 in_uint8(s, *tagval);
93 in_uint8(s, *decoded_len);
94
95 if (*decoded_len < 0x80)
96 return True;
97 else if (*decoded_len == 0x81)
98 {
99 in_uint8(s, *decoded_len);
100 return True;
101 }
102 else if (*decoded_len == 0x82)
103 {
104 in_uint16_be(s, *decoded_len);
105 return True;
106 }
107
108 return False;
109}
RD_BOOL ber_in_header(STREAM s, int *tagval, int *decoded_len)
Definition: asn.c:90
RD_BOOL ber_parse_header(STREAM s, int tagval, int *length)
Definition: asn.c:25
void ber_out_header(STREAM s, int tagval, int length)
Definition: asn.c:61
void ber_out_integer(STREAM s, int value)
Definition: asn.c:83
#define BER_TAG_INTEGER
Definition: constants.h:78
#define s_check(s)
Definition: parse.h:42
#define out_uint8(s, v)
Definition: parse.h:92
#define out_uint16_be(s, v)
Definition: parse.h:77
#define next_be(s, v)
Definition: parse.h:97
#define in_uint8(s, v)
Definition: parse.h:88
#define in_uint16_be(s, v)
Definition: parse.h:75
#define False
Definition: types.h:25
int RD_BOOL
Definition: types.h:21
#define True
Definition: types.h:24
GLdouble s
Definition: gl.h:2039
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
GLenum GLsizei len
Definition: glext.h:6722
#define error(str)
Definition: mkdosfs.c:1605
Definition: parse.h:23
Definition: ecma_167.h:138
Definition: pdh_main.c:94