def test_map(): # MapAsn.sendRoutingInfoForSM result AddressString = asn1.OCTSTRING ISDN_AddressString = AddressString TBCD_STRING = asn1.OCTSTRING IMSI = TBCD_STRING LMSI = asn1.OCTSTRING ExtensionContainer = asn1.SEQUENCE([], seq_name='ExtensionContainer') LocationInfoWithLMSI = asn1.SEQUENCE( [('networkNode_Number', None, asn1.TYPE(asn1.EXPLICIT(1, cls=asn1.CONTEXT_FLAG), ISDN_AddressString), 0), ('lmsi', None, LMSI, 1), ('extensionContainer', None, ExtensionContainer, 1)], seq_name='LocationInfoWithLMSI') RoutingInfoForSM_Res = asn1.SEQUENCE( [('imsi', None, IMSI, 0), ('locationInfoWithLMSI', None, asn1.TYPE(asn1.EXPLICIT(0, cls=asn1.CONTEXT_FLAG), LocationInfoWithLMSI), 0), ('extensionContainer', None, asn1.TYPE(asn1.EXPLICIT(4, cls=asn1.CONTEXT_FLAG), ExtensionContainer), 1)], seq_name='RoutingInfoForSM_Res') for encoded, pdu in [ # ("301a 040491103254 a012 3010 a108 0406 912222222222 0404 01020304", MapAsn.RoutingInfoForSM_Res), ("62644804000227846b3e283c060700118605010101a031602fa109060704000001001302be222820060704000001010101a015a01380099622123008016901f98106a807000000016c1ca11a02010102013b301204010f0405a3986c36028006a80700000001", TcapAsn.TCMessage), # ("626a48042f3b46026b3a2838060700118605010101a02d602b80020780a109060704000001001302be1a2818060704000001010101a00da00b80099656051124006913f66c26a12402010102013b301c04010f040eaa180da682dd6c31192d36bbdd468007917267415827f2", TcapAsn.TCMessage), ]: encoded = o(encoded) print("Decoding...") decoded = asn1.decode(pdu, encoded) print() print("Decoded:") print(repr(decoded)) print() print("Re-encoding...") reencoded = asn1.encode(pdu, decoded) print() print("Re-encoded:") print(oo(reencoded)) print("Original:") print(oo(encoded)) # The reencoded is probably different from the original due to construct and length forms variants, so we can't compare them print() print("Re-decoding...") redecoded = asn1.decode(pdu, reencoded) print() print("Redecoded:") print(repr(redecoded)) assert (redecoded == decoded) print("Re-re-encoding...") rereencoded = asn1.encode(pdu, redecoded) print() print("Re-re-encoded:") print(oo(rereencoded)) print("Previous iteration:") print(oo(reencoded)) assert (rereencoded == reencoded)
def test_sample(): # Samples from X.690-0207 Name=asn1.TYPE(asn1.IMPLICIT(1,cls=asn1.APPLICATION_FLAG), asn1.SEQUENCE([('givenName', None, asn1.VisibleString, 0), ('initial', None, asn1.VisibleString, 0), ('familyName', None, asn1.VisibleString, 0)], seq_name = 'Name')) EmployeeNumber=asn1.TYPE(asn1.IMPLICIT(2,cls=asn1.APPLICATION_FLAG), asn1.INTEGER_class([],0,2147483647)) Date=asn1.TYPE(asn1.IMPLICIT(3,cls=asn1.APPLICATION_FLAG), asn1.VisibleString) ChildInformation=asn1.SEQUENCE([('name',None,Name,0),('dateOfBirth',asn1.EXPLICIT(0,cls=asn1.CONTEXT_FLAG),Date,0)], seq_name = 'ChildInformation') PersonnelRecord=asn1.TYPE(asn1.IMPLICIT(0,cls=asn1.APPLICATION_FLAG), asn1.SEQUENCE([ ('name',None,Name,0), ('title',None,asn1.TYPE(asn1.EXPLICIT(0,cls=asn1.CONTEXT_FLAG),asn1.VisibleString),0), ('number',None,EmployeeNumber,1), ('dateOfHire',None,asn1.TYPE(asn1.EXPLICIT(1,cls=asn1.CONTEXT_FLAG),Date),0), ('nameOfSpouse',None,asn1.TYPE(asn1.EXPLICIT(2,cls=asn1.CONTEXT_FLAG),Name),0), ('children',None,asn1.TYPE(asn1.EXPLICIT(3,cls=asn1.CONTEXT_FLAG),asn1.SEQUENCE_OF(ChildInformation)),0), ], seq_name = 'PersonnelRecord')) decoded = { 'name': { 'givenName': 'John', 'initial': 'P', 'familyName': 'Smith' }, 'title': 'Director', 'number': 51, 'dateOfHire': '19710917', 'nameOfSpouse': { 'givenName': 'Mary', 'initial': 'T', 'familyName': 'Smith' }, 'children': [ { 'name': { 'givenName': 'Ralph', 'initial': 'T', 'familyName': 'Smith' }, 'dateOfBirth': '19571111' }, { 'name': { 'givenName': 'Susan', 'initial': 'B', 'familyName': 'Jones' }, 'dateOfBirth': '19590717' }, ]} pdu = PersonnelRecord print "Encoded:" encoded = asn1.encode(pdu, decoded) print oo(encoded) print "Decoded:" redecoded = asn1.decode(pdu, encoded) print repr(redecoded) assert(redecoded == decoded) print "Re-encoded:" reencoded = asn1.encode(pdu, redecoded) print oo(reencoded) print "Original:" print oo(encoded) assert(encoded == reencoded)
# Auto-generated at Thu, 09 Sep 2010 13:15:00 +0000 # with the following command line: # ./py_output.py --implicit asn/tcap.asn import Yapasn1 as asn1 #module TCAPMessages None P_AbortCause = asn1.TYPE( asn1.IMPLICIT(10, cls=asn1.APPLICATION_FLAG), asn1.INTEGER_class([('unrecognizedMessageType', 0), ('unrecognizedTransactionID', 1), ('badlyFormattedTransactionPortion', 2), ('incorrectTransactionPortion', 3), ('resourceLimitation', 4)], 0, 127)) InvokeIdType = asn1.INTEGER_class([], -128, 127) ERROR = asn1.CHOICE([('localValue', None, asn1.INTEGER_class([], None, None)), ('globalValue', None, asn1.OBJECT_IDENTIFIER)]) ReturnResultProblem = asn1.INTEGER_class([('unrecognizedInvokeID', 0), ('returnResultUnexpected', 1), ('mistypedParameter', 2)], None, None) Parameter = asn1.ANY ReturnError = asn1.SEQUENCE([('invokeID', None, InvokeIdType, 0, None), ('errorCode', None, ERROR, 0, None), ('parameter', None, Parameter, 1, None)], seq_name='ReturnError') ReturnErrorProblem = asn1.INTEGER_class([('unrecognizedInvokeID', 0), ('returnErrorUnexpected', 1), ('unrecognizedError', 2), ('unexpectedError', 3), ('mistypedParameter', 4)], None, None) InvokeProblem = asn1.INTEGER_class([('duplicateInvokeID', 0), ('unrecognizedOperation', 1),
# Auto-generated at Mon, 08 Oct 2012 15:05:58 +0000 # with the following command line: # ./py_output.py --explicit asn/RFC2578-SMIv2.asn import Yapasn1 as asn1 #module COMMUNITY-BASED-SNMPv2 None Opaque = asn1.TYPE(asn1.IMPLICIT(4, cls=asn1.APPLICATION_FLAG), asn1.OCTSTRING) TimeTicks = asn1.TYPE(asn1.IMPLICIT(3, cls=asn1.APPLICATION_FLAG), asn1.INTEGER_class([], 0, 4294967295)) NotificationName = asn1.OBJECT_IDENTIFIER IpAddress = asn1.TYPE(asn1.IMPLICIT(0, cls=asn1.APPLICATION_FLAG), asn1.OCTSTRING) Counter64 = asn1.TYPE(asn1.IMPLICIT(6, cls=asn1.APPLICATION_FLAG), asn1.INTEGER_class([], 0, 18446744073709551615)) Unsigned32 = asn1.TYPE(asn1.IMPLICIT(2, cls=asn1.APPLICATION_FLAG), asn1.INTEGER_class([], 0, 4294967295)) Gauge32 = asn1.TYPE(asn1.IMPLICIT(2, cls=asn1.APPLICATION_FLAG), asn1.INTEGER_class([], 0, 4294967295)) Integer32 = asn1.INTEGER_class([], -2147483648, 2147483647) ObjectName = asn1.OBJECT_IDENTIFIER SimpleSyntax = asn1.CHOICE([('integer-value', None, asn1.INTEGER_class([], -2147483648, 2147483647)), ('string-value', None, asn1.OCTSTRING), ('objectID-value', None, asn1.OBJECT_IDENTIFIER)]) Counter32 = asn1.TYPE(asn1.IMPLICIT(1, cls=asn1.APPLICATION_FLAG), asn1.INTEGER_class([], 0, 4294967295)) ApplicationSyntax = asn1.CHOICE([('ipAddress-value', None, IpAddress), ('counter-value', None, Counter32), ('timeticks-value', None, TimeTicks), ('arbitrary-value', None, Opaque), ('big-counter-value', None, Counter64), ('unsigned-integer-value', None, Unsigned32)])
# Auto-generated at Mon, 30 Mar 2009 14:52:02 +0000 # with the following command line: # ./py_output.py --explicit asn/DialoguePDUs.asn import Yapasn1 as asn1 #module DialoguePDUs None Associate_source_diagnostic = asn1.CHOICE([ ('dialogue-service-user', None, asn1.TYPE( asn1.EXPLICIT(1, cls=asn1.CONTEXT_FLAG), asn1.INTEGER_class([('null', 0), ('no-reason-given', 1), ('application-context-name-not-supported', 2)], None, None))), ('dialogue-service-provider', None, asn1.TYPE( asn1.EXPLICIT(2, cls=asn1.CONTEXT_FLAG), asn1.INTEGER_class([('null', 0), ('no-reason-given', 1), ('no-common-dialogue-portion', 2)], None, None))) ]) Associate_result = asn1.INTEGER_class([('accepted', 0), ('reject-permanent', 1)], None, None) Release_request_reason = asn1.INTEGER_class([('normal', 0), ('urgent', 1), ('user-defined', 30)], None, None) Release_response_reason = asn1.INTEGER_class([('normal', 0), ('not-finished', 1), ('user-defined', 30)], None, None) AARQ_apdu = asn1.TYPE( asn1.IMPLICIT(0, cls=asn1.APPLICATION_FLAG), asn1.SEQUENCE( [('protocol-version', None, asn1.TYPE(asn1.IMPLICIT(0, cls=asn1.CONTEXT_FLAG),
# Auto-generated at Mon, 08 Oct 2012 15:04:21 +0000 # with the following command line: # ./py_output.py --explicit asn/RFC1157-SMI.asn import Yapasn1 as asn1 #module RFC1157-SNMP None Counter=asn1.TYPE(asn1.IMPLICIT(1,cls=asn1.APPLICATION_FLAG),asn1.INTEGER_class ([],0,4294967295)) ObjectName=asn1.OBJECT_IDENTIFIER Opaque=asn1.TYPE(asn1.IMPLICIT(4,cls=asn1.APPLICATION_FLAG),asn1.OCTSTRING) TimeTicks=asn1.TYPE(asn1.IMPLICIT(3,cls=asn1.APPLICATION_FLAG),asn1.INTEGER_class ([],0,4294967295)) SimpleSyntax=asn1.CHOICE ([('number',None,asn1.INTEGER_class ([],None,None)), ('string',None,asn1.OCTSTRING), ('object',None,asn1.OBJECT_IDENTIFIER), ('empty',None,asn1.NULL)]) Gauge=asn1.TYPE(asn1.IMPLICIT(2,cls=asn1.APPLICATION_FLAG),asn1.INTEGER_class ([],0,4294967295)) IpAddress=asn1.TYPE(asn1.IMPLICIT(0,cls=asn1.APPLICATION_FLAG),asn1.OCTSTRING) NetworkAddress=asn1.CHOICE ([('internet',None,IpAddress)]) ApplicationSyntax=asn1.CHOICE ([('address',None,NetworkAddress), ('counter',None,Counter), ('gauge',None,Gauge), ('ticks',None,TimeTicks), ('arbitrary',None,Opaque)]) ObjectSyntax=asn1.CHOICE ([('simple',None,SimpleSyntax), ('application-wide',None,ApplicationSyntax)]) VarBind=asn1.SEQUENCE ([('name',None,ObjectName,0,None), ('value',None,ObjectSyntax,0,None)], seq_name = 'VarBind') VarBindList=asn1.SEQUENCE_OF (VarBind) PDU=asn1.SEQUENCE ([('request-id',None,asn1.INTEGER_class ([],None,None),0,None), ('error-status',None,asn1.INTEGER_class ([('noError',0),('tooBig',1),('noSuchName',2),('badValue',3),('readOnly',4),('genErr',5)],None,None),0,None), ('error-index',None,asn1.INTEGER_class ([],None,None),0,None), ('variable-bindings',None,VarBindList,0,None)], seq_name = 'PDU') GetRequest_PDU=asn1.TYPE(asn1.IMPLICIT(0,cls=asn1.CONTEXT_FLAG),PDU)