📄 dcasnparser.cpp
字号:
/****************************************************************************************
* Copyrights 2006,深圳天源迪科信息技术股份有限公司
*
* All rights reserved.
*
* Filename: DCAsnParser.cpp
* Indentifier:
* Description: Asn语法解析器附加模块
* Version: V1.0
* Author: wangbin
* Finished: 2007年6月16日
* History:
******************************************************************************************/
#include "dicasnutil/DCAsnParser.h"
namespace dicasn1p
{
/*--------------------------------------------------------------------------------------------------------*/
DCAsnValue::DCAsnValue( asn1p_value_t* value )
{
this->assign(value);
}
DCAsnValue::~DCAsnValue()
{
}
const char* DCAsnValue::getTypeName()
{
if (value == NULL)
{
return "";
}
switch(value->type)
{
case asn1p_value_s::ATV_NOVALUE:
return "NOVALUE";
case asn1p_value_s::ATV_TYPE: /* A type (as in CONTAINING Type) */
return "TYPE";
case asn1p_value_s::ATV_NULL: /* A "NULL" value of type NULL. */
return "NULL";
case asn1p_value_s::ATV_REAL: /* A constant floating-point value */
return "REAL";
case asn1p_value_s::ATV_INTEGER: /* An integer constant */
return "INTEGER";
case asn1p_value_s::ATV_MAX:
return "MAX";
case asn1p_value_s::ATV_MIN:
return "MIN";
case asn1p_value_s::ATV_TRUE:
return "TRUE";
case asn1p_value_s::ATV_FALSE:
return "FALSE";
case asn1p_value_s::ATV_TUPLE: /* { 1: 15 } */
return "TUPLE";
case asn1p_value_s::ATV_QUADRUPLE: /* { 0: 14: 0: 255 } */
return "QUADRUPLE";
case asn1p_value_s::ATV_STRING: /* "abcdef" */
return "STRING";
case asn1p_value_s::ATV_UNPARSED:
return "UNPARSED";
case asn1p_value_s::ATV_BITVECTOR:
return "BITVECTOR";
case asn1p_value_s::ATV_VALUESET: /* { 1 | 2 | 3 } */
return "VALUESET";
case asn1p_value_s::ATV_REFERENCED: /* Reference to a value defined elsewhere */
return "REFERENCED";
case asn1p_value_s::ATV_CHOICE_IDENTIFIER: /* ChoiceIdentifier value */
return "CHOICE_IDENTIFIER";
}
return "unknown type";
}
void DCAsnValue::assign( asn1p_value_t* value )
{
this->value = value;
}
const char* DCAsnValue::getValue()
{
m_retBuf[0] = 0;
if (value == NULL)
{
return "(null)";
}
strcpy(m_retBuf,"error!");
switch(value->type)
{
case asn1p_value_s::ATV_NOVALUE:
return "NOVALUE";
case asn1p_value_s::ATV_TYPE: /* A type (as in CONTAINING Type) */
return "TYPE";
case asn1p_value_s::ATV_NULL: /* A "NULL" value of type NULL. */
return "NULL";
case asn1p_value_s::ATV_REAL: /* A constant floating-point value */
return "REAL";
case asn1p_value_s::ATV_INTEGER: /* An integer constant */
sprintf(m_retBuf,"int->%ld",value->value.v_integer);
break;
case asn1p_value_s::ATV_MAX:
return "MAX";
case asn1p_value_s::ATV_MIN:
return "MIN";
case asn1p_value_s::ATV_TRUE:
return "TRUE";
case asn1p_value_s::ATV_FALSE:
return "FALSE";
case asn1p_value_s::ATV_TUPLE: /* { 1: 15 } */
return "TUPLE";
case asn1p_value_s::ATV_QUADRUPLE: /* { 0: 14: 0: 255 } */
return "QUADRUPLE";
case asn1p_value_s::ATV_STRING: /* "abcdef" */
return "STRING";
case asn1p_value_s::ATV_UNPARSED:
return "UNPARSED";
case asn1p_value_s::ATV_BITVECTOR:
return "BITVECTOR";
case asn1p_value_s::ATV_VALUESET: /* { 1 | 2 | 3 } */
return "VALUESET";
case asn1p_value_s::ATV_REFERENCED: /* Reference to a value defined elsewhere */
return "REFERENCED";
case asn1p_value_s::ATV_CHOICE_IDENTIFIER: /* ChoiceIdentifier value */
return "CHOICE_IDENTIFIER";
}
return m_retBuf;
}
/*--------------------------------------------------------------------------------------------------------*/
DCAsnExpr::DCAsnExpr( asn1p_expr_t* expr ):value(expr->value)
{
this->assign(expr);
}
DCAsnExpr::~DCAsnExpr()
{
}
void DCAsnExpr::assign( asn1p_expr_t* expr )
{
this->expr = expr;
}
const char* DCAsnExpr::getTypeName()
{
switch(expr->expr_type)
{
/* * Internal types. */ case A1TC_INVALID: /* Invalid type */
return "A1TC_INVALID";
case A1TC_REFERENCE: /* Reference to the type defined elsewhere */
return "A1TC_REFERENCE";
case A1TC_EXPORTVAR: /* We're exporting this definition */
return "A1TC_EXPORTVAR";
case A1TC_UNIVERVAL: /* A value of an ENUMERATED: INTEGER or BS */
return "A1TC_UNIVERVAL";
case A1TC_BITVECTOR: /* A plain collection of bits */
return "A1TC_BITVECTOR";
case A1TC_OPAQUE: /* Opaque data encoded as a bitvector */
return "A1TC_OPAQUE";
case A1TC_EXTENSIBLE: /* An extension marker "..." */
return "A1TC_EXTENSIBLE";
case A1TC_COMPONENTS_OF: /* COMPONENTS OF clause */
return "A1TC_COMPONENTS_OF";
case A1TC_VALUESET: /* Value set definition */
return "A1TC_VALUESET";
case A1TC_CLASSDEF: /* Information Object Class */
return "A1TC_CLASSDEF";
case A1TC_INSTANCE: /* Instance of Object Class */
return "A1TC_INSTANCE";
/*
* ASN.1 Class field types
*/
case A1TC_CLASSFIELD_TFS: /* TypeFieldSpec */
return "A1TC_CLASSFIELD_TFS";
case A1TC_CLASSFIELD_FTVFS: /* FixedTypeValueFieldSpec */
return "A1TC_CLASSFIELD_FTVFS";
case A1TC_CLASSFIELD_VTVFS: /* VariableTypeValueFieldSpec */
return "A1TC_CLASSFIELD_VTVFS";
case A1TC_CLASSFIELD_FTVSFS: /* FixedTypeValueSetFieldSpec */
return "A1TC_CLASSFIELD_FTVSFS";
case A1TC_CLASSFIELD_VTVSFS: /* VariableTypeValueSetFieldSpec */
return "A1TC_CLASSFIELD_VTVSFS";
case A1TC_CLASSFIELD_OFS: /* ObjectFieldSpec */
return "A1TC_CLASSFIELD_OFS";
case A1TC_CLASSFIELD_OSFS: /* ObjectSetFieldSpec */
return "A1TC_CLASSFIELD_OSFS";
/*
* ASN.1 Constructed types
*/
case ASN_CONSTR_SEQUENCE : /* SEQUENCE */
return "ASN_CONSTR_SEQUENCE";
case ASN_CONSTR_CHOICE: /* CHOICE */
return "ASN_CONSTR_CHOICE";
case ASN_CONSTR_SET: /* SET */
return "ASN_CONSTR_SET";
case ASN_CONSTR_SEQUENCE_OF: /* SEQUENCE OF */
return "ASN_CONSTR_SEQUENCE_OF";
case ASN_CONSTR_SET_OF: /* SET OF */
return "ASN_CONSTR_SET_OF";
/*
* ASN.1 Basic types
*/
case ASN_TYPE_ANY: /* ANY (deprecated) */
return "ASN_TYPE_ANY";
case ASN_BASIC_BOOLEAN:
return "ASN_BASIC_BOOLEAN";
case ASN_BASIC_NULL:
return "ASN_BASIC_NULL";
case ASN_BASIC_INTEGER:
return "ASN_BASIC_INTEGER";
case ASN_BASIC_REAL:
return "ASN_BASIC_REAL";
case ASN_BASIC_ENUMERATED:
return "ASN_BASIC_ENUMERATED";
case ASN_BASIC_BIT_STRING:
return "ASN_BASIC_BIT_STRING";
case ASN_BASIC_OCTET_STRING:
return "ASN_BASIC_OCTET_STRING";
case ASN_BASIC_OBJECT_IDENTIFIER:
return "ASN_BASIC_OBJECT_IDENTIFIER";
case ASN_BASIC_RELATIVE_OID:
return "ASN_BASIC_RELATIVE_OID";
case ASN_BASIC_EXTERNAL:
return "ASN_BASIC_EXTERNAL";
case ASN_BASIC_EMBEDDED_PDV:
return "ASN_BASIC_EMBEDDED_PDV";
case ASN_BASIC_CHARACTER_STRING:
return "ASN_BASIC_CHARACTER_STRING";
case ASN_BASIC_UTCTime:
return "ASN_BASIC_UTCTime";
case ASN_BASIC_GeneralizedTime:
return "ASN_BASIC_GeneralizedTime";
/*
* ASN.1 String types
*/
case ASN_STRING_IA5String:
return "ASN_STRING_IA5String";
case ASN_STRING_PrintableString:
return "ASN_STRING_PrintableString";
case ASN_STRING_VisibleString:
return "ASN_STRING_VisibleString";
case ASN_STRING_ISO646String: /* aka VisibleString */
return "ASN_STRING_ISO646String";
case ASN_STRING_NumericString:
return "ASN_STRING_NumericString";
case ASN_STRING_UniversalString:
return "ASN_STRING_UniversalString";
case ASN_STRING_BMPString:
return "ASN_STRING_BMPString";
case ASN_STRING_UTF8String:
return "ASN_STRING_UTF8String";
case ASN_STRING_GeneralString:
return "ASN_STRING_GeneralString";
case ASN_STRING_GraphicString:
return "ASN_STRING_GraphicString";
case ASN_STRING_TeletexString:
return "ASN_STRING_TeletexString";
case ASN_STRING_T61String:
return "ASN_STRING_T61String";
case ASN_STRING_VideotexString:
return "ASN_STRING_VideotexString";
case ASN_STRING_ObjectDescriptor:
return "ASN_STRING_ObjectDescriptor";
case ASN_EXPR_TYPE_MAX:
return "ASN_EXPR_TYPE_MAX";
}
return "";
}
const char* DCAsnExpr::getDesc()
{
m_retBuf[0] =0;
switch(expr->expr_type)
{
/* * Internal types. */ case A1TC_INVALID: /* Invalid type */
return "A1TC_INVALID";
case A1TC_REFERENCE: /* Reference to the type defined elsewhere */
sprintf(m_retBuf,"ref->%s",expr->reference->components->name);
break;
case A1TC_EXPORTVAR: /* We're exporting this definition */
return "A1TC_EXPORTVAR";
case A1TC_UNIVERVAL: /* A value of an ENUMERATED: INTEGER or BS */
return "A1TC_UNIVERVAL";
case A1TC_BITVECTOR: /* A plain collection of bits */
return "A1TC_BITVECTOR";
case A1TC_OPAQUE: /* Opaque data encoded as a bitvector */
return "A1TC_OPAQUE";
case A1TC_EXTENSIBLE: /* An extension marker "..." */
return "A1TC_EXTENSIBLE";
case A1TC_COMPONENTS_OF: /* COMPONENTS OF clause */
return "A1TC_COMPONENTS_OF";
case A1TC_VALUESET: /* Value set definition */
return "A1TC_VALUESET";
case A1TC_CLASSDEF: /* Information Object Class */
return "A1TC_CLASSDEF";
case A1TC_INSTANCE: /* Instance of Object Class */
return "A1TC_INSTANCE";
/*
* ASN.1 Class field types
*/
case A1TC_CLASSFIELD_TFS: /* TypeFieldSpec */
return "A1TC_CLASSFIELD_TFS";
case A1TC_CLASSFIELD_FTVFS: /* FixedTypeValueFieldSpec */
return "A1TC_CLASSFIELD_FTVFS";
case A1TC_CLASSFIELD_VTVFS: /* VariableTypeValueFieldSpec */
return "A1TC_CLASSFIELD_VTVFS";
case A1TC_CLASSFIELD_FTVSFS: /* FixedTypeValueSetFieldSpec */
return "A1TC_CLASSFIELD_FTVSFS";
case A1TC_CLASSFIELD_VTVSFS: /* VariableTypeValueSetFieldSpec */
return "A1TC_CLASSFIELD_VTVSFS";
case A1TC_CLASSFIELD_OFS: /* ObjectFieldSpec */
return "A1TC_CLASSFIELD_OFS";
case A1TC_CLASSFIELD_OSFS: /* ObjectSetFieldSpec */
return "A1TC_CLASSFIELD_OSFS";
/*
* ASN.1 Constructed types
*/
case ASN_CONSTR_SEQUENCE : /* SEQUENCE */
return "ASN_CONSTR_SEQUENCE";
case ASN_CONSTR_CHOICE: /* CHOICE */
return "ASN_CONSTR_CHOICE";
case ASN_CONSTR_SET: /* SET */
return "ASN_CONSTR_SET";
case ASN_CONSTR_SEQUENCE_OF: /* SEQUENCE OF */
return "ASN_CONSTR_SEQUENCE_OF";
case ASN_CONSTR_SET_OF: /* SET OF */
return "ASN_CONSTR_SET_OF";
/*
* ASN.1 Basic types
*/
case ASN_TYPE_ANY: /* ANY (deprecated) */
return "ASN_TYPE_ANY";
case ASN_BASIC_BOOLEAN:
return "ASN_BASIC_BOOLEAN";
case ASN_BASIC_NULL:
return "ASN_BASIC_NULL";
case ASN_BASIC_INTEGER:
return "ASN_BASIC_INTEGER";
case ASN_BASIC_REAL:
return "ASN_BASIC_REAL";
case ASN_BASIC_ENUMERATED:
return "ASN_BASIC_ENUMERATED";
case ASN_BASIC_BIT_STRING:
return "ASN_BASIC_BIT_STRING";
case ASN_BASIC_OCTET_STRING:
return "ASN_BASIC_OCTET_STRING";
case ASN_BASIC_OBJECT_IDENTIFIER:
return "ASN_BASIC_OBJECT_IDENTIFIER";
case ASN_BASIC_RELATIVE_OID:
return "ASN_BASIC_RELATIVE_OID";
case ASN_BASIC_EXTERNAL:
return "ASN_BASIC_EXTERNAL";
case ASN_BASIC_EMBEDDED_PDV:
return "ASN_BASIC_EMBEDDED_PDV";
case ASN_BASIC_CHARACTER_STRING:
return "ASN_BASIC_CHARACTER_STRING";
case ASN_BASIC_UTCTime:
return "ASN_BASIC_UTCTime";
case ASN_BASIC_GeneralizedTime:
return "ASN_BASIC_GeneralizedTime";
/*
* ASN.1 String types
*/
case ASN_STRING_IA5String:
return "ASN_STRING_IA5String";
case ASN_STRING_PrintableString:
return "ASN_STRING_PrintableString";
case ASN_STRING_VisibleString:
return "ASN_STRING_VisibleString";
case ASN_STRING_ISO646String: /* aka VisibleString */
return "ASN_STRING_ISO646String";
case ASN_STRING_NumericString:
return "ASN_STRING_NumericString";
case ASN_STRING_UniversalString:
return "ASN_STRING_UniversalString";
case ASN_STRING_BMPString:
return "ASN_STRING_BMPString";
case ASN_STRING_UTF8String:
return "ASN_STRING_UTF8String";
case ASN_STRING_GeneralString:
return "ASN_STRING_GeneralString";
case ASN_STRING_GraphicString:
return "ASN_STRING_GraphicString";
case ASN_STRING_TeletexString:
return "ASN_STRING_TeletexString";
case ASN_STRING_T61String:
return "ASN_STRING_T61String";
case ASN_STRING_VideotexString:
return "ASN_STRING_VideotexString";
case ASN_STRING_ObjectDescriptor:
return "ASN_STRING_ObjectDescriptor";
case ASN_EXPR_TYPE_MAX:
return "ASN_EXPR_TYPE_MAX";
}
return m_retBuf;
}
const char* DCAsnExpr::getValue()
{
return value.getValue();
}
const char* DCAsnExpr::getMetaType()
{
m_retBuf[0] = 0;
switch(expr->meta_type)
{
case AMT_INVALID:
return "AMT_INVALID";
case AMT_TYPE:/* Type1 ::= INTEGER */
return "AMT_TYPE";
case AMT_TYPEREF:/* Type2 ::= Type1 */
return "AMT_TYPEREF";
case AMT_VALUE:/* value1 Type1 ::= 1 */
return "AMT_VALUE";
case AMT_VALUESET:/* ValueSet Type1 ::= { value1 } */
return "AMT_VALUESET";
case AMT_OBJECT:/* object CLASS ::= {...} */
return "AMT_OBJECT";
case AMT_OBJECTCLASS: /* FUNCTION ::= CLASS {...} */
return "AMT_OBJECTCLASS";
case AMT_OBJECTFIELD:
return "AMT_OBJECTFIELD";
case AMT_EXPR_META_MAX:
return "AMT_EXPR_META_MAX";
}
}
/*--------------------------------------------------------------------------------------------------------*/
void outhexbuf( const void *buf,size_t len )
{
printf("[");
if (buf == NULL)
{
printf("NULL");
}
else
for (int i=0; i< len; ++i)
{
printf("%02X ",((unsigned char*)buf)[i]);
}
printf("]");
}
/*--------------------------------------------------------------------------------------------------------*/
} //namespace dicasn1p
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -