Пример #1
0
 def testLocalTimezone(self):
     try:
         assert encoder.encode(
             useful.UTCTime('150501120112+0200')
         )
     except PyAsn1Error:
         pass
     else:
         assert 0, 'Local timezone tolerated'
Пример #2
0
 def testMissingTimezone(self):
     try:
         assert encoder.encode(
             useful.UTCTime('150501120112')
         ) == ints2octs((23, 13, 49, 53, 48, 53, 48, 49, 49, 50, 48, 49, 49, 50, 90))
     except PyAsn1Error:
         pass
     else:
         assert 0, 'Missing timezone tolerated'
Пример #3
0
 def testFractionOfSecond(self):
     try:
         assert encoder.encode(
             useful.UTCTime('150501120112.10Z')
         )
     except PyAsn1Error:
         pass
     else:
         assert 0, 'Decimal point tolerated'
Пример #4
0
 def testDecimalCommaPoint(self):
     try:
         assert encoder.encode(
                 useful.GeneralizedTime('20150501120112,1Z')
          )
     except PyAsn1Error:
         pass
     else:
         assert 0, 'Decimal comma tolerated'
Пример #5
0
 def testMissingTimezone(self):
     try:
         assert encoder.encode(
             useful.GeneralizedTime('20150501120112.1')
         )
     except PyAsn1Error:
         pass
     else:
         assert 0, 'Missing timezone tolerated'
Пример #6
0
    def testWithUntaggedChoice(self):

        c = univ.Choice(
            componentType=namedtype.NamedTypes(
                namedtype.NamedType('premium', univ.Boolean())
            )
        )

        s = univ.Set(
            componentType=namedtype.NamedTypes(
                namedtype.NamedType('name', univ.OctetString()),
                namedtype.NamedType('customer', c)
            )
        )

        s.setComponentByName('name', 'A')
        s.getComponentByName('customer').setComponentByName('premium', True)

        assert encoder.encode(s) == ints2octs((49, 128, 1, 1, 255, 4, 1, 65, 0, 0))
Пример #7
0
    def testWithTaggedChoice(self):

        c = univ.Choice(
            componentType=namedtype.NamedTypes(
                namedtype.NamedType('premium', univ.Boolean())
            )
        ).subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 7))

        s = univ.Set(
            componentType=namedtype.NamedTypes(
                namedtype.NamedType('name', univ.OctetString()),
                namedtype.NamedType('customer', c)
            )
        )

        s.setComponentByName('name', 'A')
        s.getComponentByName('customer').setComponentByName('premium', True)

        assert encoder.encode(s) == ints2octs((49, 128, 4, 1, 65, 167, 128, 1, 1, 255, 0, 0, 0, 0))
Пример #8
0
 def testWithOptionalIndefMode(self):
     assert encoder.encode(
         self.s
     ) == ints2octs((49, 128, 2, 1, 1, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 5, 0, 0, 0))
Пример #9
0
    def testIndefMode4(self):
        self.s.clear()
        self.s.append('a')
        self.s.append('b')

        assert encoder.encode(self.s) == ints2octs((49, 128, 4, 1, 97, 4, 1, 98, 0, 0))
Пример #10
0
 def testDefMode2(self):
     s = univ.SequenceOf()
     s.append(univ.OctetString('ab'))
     s.append(univ.OctetString('a'))
     assert encoder.encode(s) == ints2octs((48, 128, 4, 2, 97, 98, 4, 1, 97, 0, 0))
Пример #11
0
 def testIndefMode(self):
     self.__init()
     assert encoder.encode(self.s) == ints2octs((49, 128, 5, 0, 0, 0))
Пример #12
0
 def testOptionalWithValue(self):
     s = self.__initOptionalWithValue()
     assert encoder.encode(s) == ints2octs((48, 128, 48, 128, 4, 4, 116, 101, 115, 116, 0, 0, 0, 0))
Пример #13
0
 def testWithSeconds(self):
     assert encoder.encode(
                 useful.GeneralizedTime('20170801120112Z')
          ) == ints2octs((24, 15, 50, 48, 49, 55, 48, 56, 48, 49, 49, 50, 48, 49, 49, 50, 90))
Пример #14
0
 def testWithMinutes(self):
     assert encoder.encode(
         useful.GeneralizedTime('201708011201Z')) == ints2octs(
             (24, 13, 50, 48, 49, 55, 48, 56, 48, 49, 49, 50, 48, 49, 90))
Пример #15
0
 def testWithSeconds(self):
     assert encoder.encode(useful.UTCTime('990801120112Z')) == ints2octs(
         (23, 13, 57, 57, 48, 56, 48, 49, 49, 50, 48, 49, 49, 50, 90))
Пример #16
0
 def testWithSubseconds(self):
     assert encoder.encode(
         useful.GeneralizedTime('20170801120112.59Z')) == ints2octs(
             (24, 18, 50, 48, 49, 55, 48, 56, 48, 49, 49, 50, 48, 49, 49,
              50, 46, 53, 57, 90))
Пример #17
0
 def testWithSeconds(self):
     assert encoder.encode(
         useful.GeneralizedTime('20170801120112Z')) == ints2octs(
             (24, 15, 50, 48, 49, 55, 48, 56, 48, 49, 49, 50, 48, 49, 49,
              50, 90))
Пример #18
0
 def testWithOptionalIndefMode(self):
     self.__initWithOptional()
     assert encoder.encode(
         self.s
     ) == ints2octs((48, 128, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0))
Пример #19
0
 def testWithDefaultedIndefMode(self):
     assert encoder.encode(
         self.s
     ) == ints2octs((48, 128, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1, 0, 0))
Пример #20
0
 def testWithOptionalIndefMode(self):
     assert encoder.encode(
         self.s
     ) == ints2octs((49, 128, 2, 1, 1, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 5, 0, 0, 0))
Пример #21
0
 def testWithOptionalIndefMode(self):
     self.__initWithOptional()
     assert encoder.encode(
         self.s
     ) == ints2octs((48, 128, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0))
Пример #22
0
 def testWithMinutes(self):
     assert encoder.encode(useful.UTCTime('9908011201Z')) == ints2octs(
         (23, 11, 57, 57, 48, 56, 48, 49, 49, 50, 48, 49, 90))
Пример #23
0
 def testOptionalWithDefaultAndOptional(self):
     s = self.__initOptionalWithDefaultAndOptional()
     assert encoder.encode(s) == ints2octs((48, 128, 48, 128, 4, 4, 116, 101, 115, 116, 2, 1, 123, 0, 0, 0, 0))
Пример #24
0
 def testDefaultWithDefault(self):
     s = self.__initDefaultWithDefault()
     assert encoder.encode(s) == ints2octs(
         (48, 128, 48, 128, 4, 4, 116, 101, 115, 116, 0, 0, 0, 0))
Пример #25
0
 def testEmpty(self):
     s = univ.SequenceOf()
     assert encoder.encode(s) == ints2octs((48, 128, 0, 0))
Пример #26
0
 def testOptionalWithDefaultAndOptional(self):
     s = self.__initOptionalWithDefaultAndOptional()
     assert encoder.encode(s) == ints2octs(
         (48, 128, 48, 128, 4, 4, 116, 101, 115, 116, 2, 1, 123, 0, 0, 0,
          0))
Пример #27
0
    def testIndefMode4(self):
        self.s.clear()
        self.s.append('a')
        self.s.append('b')

        assert encoder.encode(self.s) == ints2octs((49, 128, 4, 1, 97, 4, 1, 98, 0, 0))
Пример #28
0
 def testOptionalWithDefault(self):
     s = self.__initOptionalWithDefault()
     assert encoder.encode(s) == ints2octs(
         (48, 128, 48, 128, 2, 1, 123, 0, 0, 0, 0))
Пример #29
0
 def testWithOptionalAndDefaultedIndefMode(self):
     self.__initWithOptionalAndDefaulted()
     assert encoder.encode(
         self.s
         ) == ints2octs((49, 128, 2, 1, 1, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 5, 0, 0, 0))
Пример #30
0
 def testOptionalWithValue(self):
     s = self.__initOptionalWithValue()
     assert encoder.encode(s) == ints2octs(
         (48, 128, 48, 128, 4, 4, 116, 101, 115, 116, 0, 0, 0, 0))
Пример #31
0
 def testShortMode(self):
     assert encoder.encode(
         univ.OctetString('Quick brown fox')) == ints2octs(
             (4, 15, 81, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32,
              102, 111, 120))
Пример #32
0
 def testOptional(self):
     s = self.__initOptional()
     assert encoder.encode(s) == ints2octs((48, 128, 0, 0))
Пример #33
0
 def testEmpty(self):
     self.s.clear()
     assert encoder.encode(self.s) == ints2octs((49, 128, 0, 0))
Пример #34
0
 def testLongMode(self):
     assert encoder.encode(univ.OctetString(
         'Q' * 1001)) == ints2octs((36, 128, 4, 130, 3, 232) +
                                   (81, ) * 1000 + (4, 1, 81, 0, 0))
Пример #35
0
 def testShortMode(self):
     assert encoder.encode(
         univ.BitString((1, 0) * 5)
     ) == ints2octs((3, 3, 6, 170, 128))
Пример #36
0
 def testIndefMode(self):
     self.__init()
     assert encoder.encode(self.s) == ints2octs((49, 128, 5, 0, 0, 0))
Пример #37
0
 def testWithDefaultedIndefMode(self):
     assert encoder.encode(
         self.s
     ) == ints2octs((48, 128, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1, 0, 0))
Пример #38
0
 def testWithDefaultedIndefMode(self):
     self.__initWithDefaulted()
     assert encoder.encode(self.s) == ints2octs(
         (49, 128, 2, 1, 1, 5, 0, 0, 0))
Пример #39
0
 def testDefaultWithDefault(self):
     s = self.__initDefaultWithDefault()
     assert encoder.encode(s) == ints2octs((48, 128, 48, 128, 4, 4, 116, 101, 115, 116, 0, 0, 0, 0))
Пример #40
0
 def testDefMode4(self):
     s = univ.SetOf()
     s.append(univ.OctetString('a'))
     s.append(univ.OctetString('b'))
     assert encoder.encode(s) == ints2octs((49, 128, 4, 1, 97, 4, 1, 98, 0, 0))
Пример #41
0
 def testOptionalWithDefault(self):
     s = self.__initOptionalWithDefault()
     assert encoder.encode(s) == ints2octs((48, 128, 48, 128, 2, 1, 123, 0, 0, 0, 0))
Пример #42
0
 def testEmpty(self):
     s = univ.SetOf()
     s.clear()
     assert encoder.encode(s) == ints2octs((49, 128, 0, 0))
Пример #43
0
 def testOptional(self):
     s = self.__initOptional()
     assert encoder.encode(s) == ints2octs((48, 128, 0, 0))
Пример #44
0
 def testFalse(self):
     assert encoder.encode(univ.Boolean(0)) == ints2octs((1, 1, 0))
Пример #45
0
 def testWithSubseconds(self):
     assert encoder.encode(
                 useful.GeneralizedTime('20170801120112.59Z')
          ) == ints2octs((24, 18, 50, 48, 49, 55, 48, 56, 48, 49, 49, 50, 48, 49, 49, 50, 46, 53, 57, 90))
Пример #46
0
 def testShortMode(self):
     assert encoder.encode(
         univ.OctetString('Quick brown fox')
         ) == ints2octs((4, 15, 81, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120))
Пример #47
0
 def testWithOptionalAndDefaultedIndefMode(self):
     self.__initWithOptionalAndDefaulted()
     assert encoder.encode(self.s) == ints2octs(
         (49, 128, 2, 1, 1, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111,
          119, 110, 5, 0, 0, 0))
Пример #48
0
 def testEmpty(self):
     self.s.clear()
     assert encoder.encode(self.s) == ints2octs((49, 128, 0, 0))
Пример #49
0
 def testMissingTimezone(self):
     assert encoder.encode(
         useful.UTCTime('150501120112')
     ) == ints2octs((23, 13, 49, 53, 48, 53, 48, 49, 49, 50, 48, 49, 49, 50, 90)), 'Missing timezone not added'
Пример #50
0
 def testIndefMode(self):
     self.s.setComponentByPosition(0)
     self.s.setComponentByName('status')
     self.s.getComponentByName('status').setComponentByPosition(0, 1)
     assert encoder.encode(self.s) == ints2octs(
         (49, 128, 1, 1, 255, 5, 0, 0, 0))
Пример #51
0
 def testTrue(self):
     assert encoder.encode(univ.Boolean(1)) == ints2octs((1, 1, 255))
Пример #52
0
 def testMissingTimezone(self):
     assert encoder.encode(useful.UTCTime('150501120112')) == ints2octs(
         (23, 13, 49, 53, 48, 53, 48, 49, 49, 50, 48, 49, 49, 50,
          90)), 'Missing timezone not added'
Пример #53
0
 def testLongMode(self):
     assert encoder.encode(
         univ.BitString((1,0)*501)
         ) == ints2octs((3, 127, 6) + (170,) * 125 + (128,))
Пример #54
0
 def testTrue(self):
     assert encoder.encode(univ.Boolean(1)) == ints2octs((1, 1, 255))
Пример #55
0
 def testLongMode(self):
     assert encoder.encode(
         univ.OctetString('Q'*1001)
         ) == ints2octs((36, 128, 4, 130, 3, 232) + (81,)*1000 + (4, 1, 81, 0, 0))
Пример #56
0
 def testFalse(self):
     assert encoder.encode(univ.Boolean(0)) == ints2octs((1, 1, 0))
Пример #57
0
 def testWithDefaultedIndefMode(self):
     self.__initWithDefaulted()
     assert encoder.encode(
         self.s
         ) == ints2octs((49, 128, 2, 1, 1, 5, 0, 0, 0))
Пример #58
0
 def testShortMode(self):
     assert encoder.encode(univ.BitString((1, 0) * 5)) == ints2octs(
         (3, 3, 6, 170, 128))
Пример #59
0
 def testIndefMode(self):
     self.s.setComponentByPosition(0)
     self.s.setComponentByName('status')
     self.s.getComponentByName('status').setComponentByPosition(0, 1)
     assert encoder.encode(self.s) == ints2octs((49, 128, 1, 1, 255, 5, 0, 0, 0))
Пример #60
0
 def testLongMode(self):
     assert encoder.encode(univ.BitString(
         (1, 0) * 501)) == ints2octs((3, 127, 6) + (170, ) * 125 + (128, ))