VirtualBox

source: vbox/trunk/src/VBox/RDP/client-1.8.4/asn.c@ 78352

Last change on this file since 78352 was 76779, checked in by vboxsync, 6 years ago

RDP: add client-1.8.4.
bugref:9356: Update rdesktop-vrdp to 1.8.4
client-1.8.4 is a Subversion copy of 1.8.3 with the upstream 1.8.3 to 1.8.4
patch applied and a couple of fixes and changes after review, namely:

  • Stopped disabling the new pointer data format for our build, as this is no

longer needed.

  • Adjusted some snprintf buffers to make GCC happy.
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.5 KB
Line 
1/* -*- c-basic-offset: 8 -*-
2 rdesktop: A Remote Desktop Protocol client.
3 ASN.1 utility functions
4 Copyright 2012 Henrik Andersson <[email protected]> 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/*
21 * Oracle GPL Disclaimer: For the avoidance of doubt, except that if any license choice
22 * other than GPL or LGPL is available it will apply instead, Oracle elects to use only
23 * the General Public License version 2 (GPLv2) at this time for any software where
24 * a choice of GPL license versions is made available with the language indicating
25 * that GPLv2 or any later version may be used, or where a choice of which version
26 * of the GPL is applied is otherwise unspecified.
27 */
28
29#include "rdesktop.h"
30
31
32/* Parse an ASN.1 BER header */
33RD_BOOL
34ber_parse_header(STREAM s, int tagval, uint32 *length)
35{
36 int tag, len;
37
38 if (tagval > 0xff)
39 {
40 in_uint16_be(s, tag);
41 }
42 else
43 {
44 in_uint8(s, tag);
45 }
46
47 if (tag != tagval)
48 {
49 error("expected tag %d, got %d\n", tagval, tag);
50 return False;
51 }
52
53 in_uint8(s, len);
54
55 if (len & 0x80)
56 {
57 len &= ~0x80;
58 *length = 0;
59 while (len--)
60 next_be(s, *length);
61 }
62 else
63 *length = len;
64
65 return s_check(s);
66}
67
68/* Output an ASN.1 BER header */
69void
70ber_out_header(STREAM s, int tagval, int length)
71{
72 if (tagval > 0xff)
73 {
74 out_uint16_be(s, tagval);
75 }
76 else
77 {
78 out_uint8(s, tagval);
79 }
80
81 if (length >= 0x80)
82 {
83 out_uint8(s, 0x82);
84 out_uint16_be(s, length);
85 }
86 else
87 out_uint8(s, length);
88}
89
90/* Output an ASN.1 BER integer */
91void
92ber_out_integer(STREAM s, int value)
93{
94 ber_out_header(s, BER_TAG_INTEGER, 2);
95 out_uint16_be(s, value);
96}
97
98RD_BOOL
99ber_in_header(STREAM s, int *tagval, int *decoded_len)
100{
101 in_uint8(s, *tagval);
102 in_uint8(s, *decoded_len);
103
104 if (*decoded_len < 0x80)
105 return True;
106 else if (*decoded_len == 0x81)
107 {
108 in_uint8(s, *decoded_len);
109 return True;
110 }
111 else if (*decoded_len == 0x82)
112 {
113 in_uint16_be(s, *decoded_len);
114 return True;
115 }
116
117 return False;
118}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette