Exemple #1
0
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)
Exemple #2
0
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)
Exemple #3
0
    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),
                                    ('mistypedParameter', 2),
                                    ('resourceLimitation', 3),
                                    ('initiatingRelease', 4),
                                    ('unrecognizedLinkedID', 5),
                                    ('linkedResponseUnexpected', 6),
                                    ('unexpectedLinkedOperation', 7)], None,
                                   None)
Exemple #4
0
                      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)])
ObjectSyntax = asn1.CHOICE([('simple', None, SimpleSyntax),
                            ('application-wide', None, ApplicationSyntax)])
VarBind = asn1.SEQUENCE(
    [('name', None, ObjectName, 0, None),
     ('choice', None,
      asn1.CHOICE([
          ('value', None, ObjectSyntax), ('unSpecified', None, asn1.NULL),
          ('noSuchObject', None,
           asn1.TYPE(asn1.IMPLICIT(0, cls=asn1.CONTEXT_FLAG), asn1.NULL)),
          ('noSuchInstance', None,
           asn1.TYPE(asn1.IMPLICIT(1, cls=asn1.CONTEXT_FLAG), asn1.NULL)),
          ('endOfMibView', None,
           asn1.TYPE(asn1.IMPLICIT(2, cls=asn1.CONTEXT_FLAG), asn1.NULL))
      ]), 0, None)],
    seq_name='VarBind')
VarBindList = asn1.SEQUENCE_OF(VarBind)
PDU = asn1.SEQUENCE(
    [('request-id', None, Integer32, 0, None),
     ('error-status', None,
      asn1.INTEGER_class([('noError', 0), ('tooBig', 1), ('noSuchName', 2),
                          ('badValue', 3), ('readOnly', 4), ('genErr', 5),
                          ('noAccess', 6),
                          ('wrongType', 7), ('wrongLength', 8),
                          ('wrongEncoding', 9), ('wrongValue', 10),
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),
                    asn1.BITSTRING_class([('version1', 0)], None,
                                         None)), 1, 'version1'),
         ('application-context-name', None,
          asn1.TYPE(asn1.EXPLICIT(1, cls=asn1.CONTEXT_FLAG),
                    asn1.OBJECT_IDENTIFIER), 0, None),
         ('user-information', None,
          asn1.TYPE(asn1.IMPLICIT(30, cls=asn1.CONTEXT_FLAG),
                    asn1.SEQUENCE_OF(asn1.EXTERNAL)), 1, None)],
        seq_name='AARQ-apdu'))
ABRT_source = asn1.INTEGER_class([('dialogue-service-user', 0),
                                  ('dialogue-service-provider', 1)], None,
                                 None)
RLRQ_apdu = asn1.TYPE(
    asn1.IMPLICIT(2, cls=asn1.APPLICATION_FLAG),
    asn1.SEQUENCE([('reason', None,
                    asn1.TYPE(asn1.IMPLICIT(0, cls=asn1.CONTEXT_FLAG),
                              Release_request_reason), 1, None),
                   ('user-information', None,
                    asn1.TYPE(asn1.IMPLICIT(30, cls=asn1.CONTEXT_FLAG),
Exemple #6
0
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)
GetResponse_PDU=asn1.TYPE(asn1.IMPLICIT(2,cls=asn1.CONTEXT_FLAG),PDU)
GetNextRequest_PDU=asn1.TYPE(asn1.IMPLICIT(1,cls=asn1.CONTEXT_FLAG),PDU)
Trap_PDU=asn1.TYPE(asn1.IMPLICIT(4,cls=asn1.CONTEXT_FLAG),asn1.SEQUENCE ([('enterprise',None,asn1.OBJECT_IDENTIFIER,0,None),
    ('agent-addr',None,NetworkAddress,0,None),
    ('generic-trap',None,asn1.INTEGER_class ([('coldStart',0),('warmStart',1),('linkDown',2),('linkUp',3),('authenticationFailure',4),('egpNeighborLoss',5),('enterpriseSpecific',6)],None,None),0,None),
    ('specific-trap',None,asn1.INTEGER_class ([],None,None),0,None),
    ('time-stamp',None,TimeTicks,0,None),
    ('variable-bindings',None,VarBindList,0,None)], seq_name = 'Trap-PDU'))
SetRequest_PDU=asn1.TYPE(asn1.IMPLICIT(3,cls=asn1.CONTEXT_FLAG),PDU)