~paulliu/ubuntu/quantal/freerdp/fixext

« back to all changes in this revision

Viewing changes to libfreerdp/asn1.c

  • Committer: Package Import Robot
  • Author(s): Martin Pitt
  • Date: 2012-01-31 10:02:14 UTC
  • mto: This revision was merged to the branch mainline in revision 11.
  • Revision ID: package-import@ubuntu.com-20120131100214-zvig71djj2sqgq22
Tags: upstream-1.0.0
ImportĀ upstreamĀ versionĀ 1.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- c-basic-offset: 8 -*-
2
 
   FreeRDP: A Remote Desktop Protocol client.
3
 
   ASN.1 Encoding and Decoding
4
 
 
5
 
   Copyright (C) Marc-Andre Moreau <marcandre.moreau@gmail.com> 2009
6
 
 
7
 
   This program is free software; you can redistribute it and/or modify
8
 
   it under the terms of the GNU General Public License as published by
9
 
   the Free Software Foundation; either version 2 of the License, or
10
 
   (at your option) any later version.
11
 
 
12
 
   This program is distributed in the hope that it will be useful,
13
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 
   GNU General Public License for more details.
16
 
 
17
 
   You should have received a copy of the GNU General Public License
18
 
   along with this program; if not, write to the Free Software
19
 
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
 
*/
21
 
 
22
 
#ifndef __ASN1_H
23
 
#define __ASN1_H
24
 
 
25
 
#include "frdp.h"
26
 
#include "iso.h"
27
 
#include "mcs.h"
28
 
#include "chan.h"
29
 
#include "secure.h"
30
 
#include "rdp.h"
31
 
#include "mem.h"
32
 
#include "asn1.h"
33
 
 
34
 
/* Parse an ASN.1 BER header */
35
 
RD_BOOL
36
 
ber_parse_header(rdpMcs * mcs, STREAM s, int tagval, int *length)
37
 
{
38
 
        int tag, len;
39
 
 
40
 
        if (tagval > 0xff)
41
 
        {
42
 
                in_uint16_be(s, tag);
43
 
        }
44
 
        else
45
 
        {
46
 
                in_uint8(s, tag);
47
 
        }
48
 
 
49
 
        if (tag != tagval)
50
 
        {
51
 
                ui_error(mcs->sec->rdp->inst, "expected tag %d, got %d\n", tagval, tag);
52
 
                return False;
53
 
        }
54
 
 
55
 
        in_uint8(s, len);
56
 
 
57
 
        if (len & 0x80)
58
 
        {
59
 
                len &= ~0x80;
60
 
                *length = 0;
61
 
                while (len--)
62
 
                        next_be(s, *length);
63
 
        }
64
 
        else
65
 
                *length = len;
66
 
 
67
 
        return s_check(s);
68
 
}
69
 
 
70
 
/* Output an ASN.1 BER header */
71
 
void
72
 
ber_out_header(STREAM s, int tagval, int length)
73
 
{
74
 
        if (tagval > 0xff)
75
 
        {
76
 
                out_uint16_be(s, tagval);
77
 
        }
78
 
        else
79
 
        {
80
 
                out_uint8(s, tagval);
81
 
        }
82
 
 
83
 
        if (length >= 0x80)
84
 
        {
85
 
                out_uint8(s, 0x82);
86
 
                out_uint16_be(s, length);
87
 
        }
88
 
        else
89
 
                out_uint8(s, length);
90
 
}
91
 
 
92
 
/* Output an ASN.1 BER integer */
93
 
void
94
 
ber_out_integer(STREAM s, int value)
95
 
{
96
 
        ber_out_header(s, BER_TAG_INTEGER, 2);
97
 
        out_uint16_be(s, value);
98
 
}
99
 
 
100
 
#endif /* __ASN1_H */
101