/*
 *  Copyright (c) 1996-2007 Digi International Inc., All Rights Reserved
 *
 *  This software contains proprietary and confidential information of Digi
 *  International Inc.  By accepting transfer of this copy, Recipient agrees
 *  to retain this software in confidence, to prevent disclosure to others,
 *  and to make no use of this software other than that for which it was
 *  delivered.  This is an unpublished copyrighted work of Digi International
 *  Inc.  Except as permitted by federal law, 17 USC 117, copying is strictly
 *  prohibited.
 *
 *  Restricted Rights Legend
 *
 *  Use, duplication, or disclosure by the Government is subject to
 *  restrictions set forth in sub-paragraph (c)(1)(ii) of The Rights in
 *  Technical Data and Computer Software clause at DFARS 252.227-7031 or
 *  subparagraphs (c)(1) and (2) of the Commercial Computer Software -
 *  Restricted Rights at 48 CFR 52.227-19, as applicable.
 *
 *  Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
 *
*  File Description:
**************************************************************************/
/*
 * Definitions for Abstract Syntax Notation One, ASN.1
 * As defined in ISO/IS 8824 and ISO/IS 8825
 *
 */
/***********************************************************
    Copyright 1988, 1989 by Carnegie Mellon University

                      All Rights Reserved

Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the name of CMU not be
used in advertising or publicity pertaining to distribution of the
software without specific, written prior permission.

CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
SOFTWARE.
******************************************************************/
#include "nptypes.h"
#ifndef _ASN1_
#define _ASN1_
#ifdef __cplusplus
extern "C"
{
#endif


#ifndef OID_DEFINED
#define OID_DEFINED

#ifdef EIGHTBIT_SUBIDS
typedef u_char      oid;
#define MAX_SUBID       0xFF
#else /* EIGHTBIT_SUBIDS */
/*ad*
 * oid type
 *
 * @external
 * @category SNMP
 * @since 6.0
*ad*/
typedef u_long      oid;
#define MAX_SUBID   (u_long)0xFFFFFFFFL
#endif /* EIGHTBIT_SUBIDS */
#endif /* OID_DEFINED */

#ifndef MAX_STRING_LEN
#define MAX_STRING_LEN  256
#endif /* MAX_STRING_LEN */



#define ASN_BOOLEAN     (0x01)
#define ASN_INTEGER     (0x02)
#define ASN_BIT_STR     (0x03)
#define ASN_OCTET_STR   (0x04)
#define ASN_NULL        (0x05)
#define ASN_OBJECT_ID   (0x06)
#define ASN_SEQUENCE    (0x10)
#define ASN_SET         (0x11)

#define ASN_UNIVERSAL   (0x00)
#define ASN_APPLICATION (0x40)
#define ASN_CONTEXT     (0x80)
#define ASN_PRIVATE     (0xC0)

#define ASN_PRIMITIVE   (0x00)
#define ASN_CONSTRUCTOR (0x20)

#define ASN_LONG_LEN    (0x80)
#define ASN_EXTENSION_ID (0x1F)
#define ASN_BIT8        (0x80)

#define IS_CONSTRUCTOR(byte)    ((byte) & ASN_CONSTRUCTOR)
#define IS_EXTENSION_ID(byte)   (((byte) & ASN_EXTENSION_ID) == ASN_EXTENSION_ID)

/*ad*
 * counter64 structure
 *
 * @external
 * @category SNMP
 * @since 6.0
 *
 * @param high      High word.
 * @param low       Low word.
 *
 * @see @link u_long
*ad*/
struct counter64
{
    u_long high;
    u_long low;
};

extern  u_char *asn_build_bitstring(u_char *data, int  *datalength ,
    u_char type, u_char *string, int strlength);
extern  u_char *asn_build_header(u_char *data,
    int  *datalength, u_char type, int length);
extern  u_char *asn_build_int(u_char * data, int  * datalength,
    u_char type, long * intp, int intsize);
extern  u_char *asn_build_int_short(u_char * data,
    int  *datalength , u_char type, int *intp, int intsize);
extern  u_char *asn_build_length(u_char *data, int  *datalength,
    int length);
extern  u_char *asn_build_null(u_char *data, int  *datalength,
    u_char type);
extern  u_char *asn_build_objid(u_char *data, int  *datalength,
    u_char type, oid *objid, int objidlength);
extern u_char *asnBuildSequence(u_char *data, int *pLen, u_char type,
    int length);
extern u_char *asnBuildLength(u_char *data, int *pLen, int length);
extern  u_char *asn_build_string(u_char *data, int  *datalength,
    u_char type, u_char *string, int strlength);
extern  u_char *asn_build_unsigned_int(u_char *data,
    int  *datalength, u_char type, u_long *intp, int intsize);
extern  u_char *asn_build_unsigned_int64(u_char * data,
    int  *datalength, u_char type, struct counter64 *cp, int countersize);
extern  u_char *asn_parse_bitstring(u_char *data,
    int  *datalength, u_char  *type, u_char *string, int  *strlength);
extern  u_char *asn_parse_header(u_char *data,
    int  *datalength, u_char  *type);
extern  u_char *asn_parse_int(u_char *data, int  *datalength,
    u_char  *type, long *intp, int intsize);
extern  u_char *asn_parse_int_short(u_char *data, int  *datalength,
    u_char  *type, int *intp, int intsize);
extern  u_char *asn_parse_length(u_char *data, u_long  *length);
extern  u_char *asn_parse_null(u_char *data, int  *datalength,
    u_char  *type);
extern  u_char *asn_parse_objid(u_char *data, int  *datalength,
    u_char  *type, oid *objid, int  *objidlength);
extern  u_char *asn_parse_string(u_char *data, int  *datalength ,
    u_char  *type, u_char **string, int  *strlength);
extern  u_char *asn_parse_unsigned_int(u_char *data,
    int  *datalength, u_char  *type, u_long *intp, int intsize);
extern  u_char *asn_parse_unsigned_int64(u_char *data,
    int  *datalength, u_char  *type, struct counter64 *cp, int countersize);
#ifdef __cplusplus
}
#endif
#endif /* _ASN1_ */


