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
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.
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.
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/>.
23 /* Parse an ASN.1 BER header */
25 ber_parse_header(STREAM s
, int tagval
, int *length
)
40 error("expected tag %d, got %d\n", tagval
, tag
);
59 /* Output an ASN.1 BER header */
61 ber_out_header(STREAM s
, int tagval
, int length
)
65 out_uint16_be(s
, tagval
);
75 out_uint16_be(s
, length
);
81 /* Output an ASN.1 BER integer */
83 ber_out_integer(STREAM s
, int value
)
85 ber_out_header(s
, BER_TAG_INTEGER
, 2);
86 out_uint16_be(s
, value
);
90 ber_in_header(STREAM s
, int *tagval
, int *decoded_len
)
93 in_uint8(s
, *decoded_len
);
95 if (*decoded_len
< 0x80)
97 else if (*decoded_len
== 0x81)
99 in_uint8(s
, *decoded_len
);
102 else if (*decoded_len
== 0x82)
104 in_uint16_be(s
, *decoded_len
);