/* -*- c-basic-offset: 8 -*- FreeRDP: A Remote Desktop Protocol client. ASN.1 Encoding and Decoding Copyright (C) Marc-Andre Moreau 2009 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef __ASN1_H #define __ASN1_H #include "frdp.h" #include "iso.h" #include "mcs.h" #include "chan.h" #include "secure.h" #include "rdp.h" #include "mem.h" #include "asn1.h" /* Parse an ASN.1 BER header */ RD_BOOL ber_parse_header(rdpMcs * mcs, STREAM s, int tagval, int *length) { int tag, len; if (tagval > 0xff) { in_uint16_be(s, tag); } else { in_uint8(s, tag); } if (tag != tagval) { ui_error(mcs->sec->rdp->inst, "expected tag %d, got %d\n", tagval, tag); return False; } in_uint8(s, len); if (len & 0x80) { len &= ~0x80; *length = 0; while (len--) next_be(s, *length); } else *length = len; return s_check(s); } /* Output an ASN.1 BER header */ void ber_out_header(STREAM s, int tagval, int length) { if (tagval > 0xff) { out_uint16_be(s, tagval); } else { out_uint8(s, tagval); } if (length >= 0x80) { out_uint8(s, 0x82); out_uint16_be(s, length); } else out_uint8(s, length); } /* Output an ASN.1 BER integer */ void ber_out_integer(STREAM s, int value) { ber_out_header(s, BER_TAG_INTEGER, 2); out_uint16_be(s, value); } #endif /* __ASN1_H */