Esempio n. 1
0
 def testFromBERNullKnownValues(self):
     """BERNull(encoded="...") should give known result with known input"""
     encoded=[0x05, 0x00]
     m=MutableString(apply(s,encoded))
     m.append('foo')
     result = pureber.BERNull(encoded=m, berdecoder=pureber.BERDecoderContext())
     assert m=='foo'
     assert 0x05==result.tag
Esempio n. 2
0
 def testFromBERIntegerKnownValues(self):
     """BERInteger(encoded="...") should give known result with known input"""
     for integer, encoded in self.knownValues:
         m=MutableString(apply(s,encoded))
         m.append('foo')
         result = pureber.BERInteger(encoded=m, berdecoder=pureber.BERDecoderContext())
         assert m=='foo'
         result = result.value
         assert integer==result
Esempio n. 3
0
 def testSanity(self):
     """BEROctetString(encoded=BEROctetString(n*'x')).value==n*'x' for some values of n"""
     for n in 0,1,2,3,4,5,6,100,126,127,128,129,1000,2000:
         encoded = MutableString(pureber.BEROctetString(n*'x'))
         encoded.append('foo')
         result = pureber.BEROctetString(encoded=encoded, berdecoder=pureber.BERDecoderContext())
         result = result.value
         assert encoded=='foo'
         assert n*'x'==result
Esempio n. 4
0
 def testSanity(self):
     """BEREnumerated(encoded=BEREnumerated(n)).value==n for -1000..1000"""
     for n in range(-1000, 1001, 10):
         encoded = MutableString(pureber.BEREnumerated(n))
         encoded.append('foo')
         result = pureber.BEREnumerated(encoded=encoded,
                                     berdecoder=pureber.BERDecoderContext())
         result = result.value
         assert encoded=='foo'
         assert n==result
Esempio n. 5
0
 def testFromBEROctetStringKnownValues(self):
     """BEROctetString(encoded="...") should give known result with known input"""
     for st, encoded in self.knownValues:
         m=MutableString(apply(s,encoded))
         m.append('foo')
         result = pureber.BEROctetString(encoded=m, berdecoder=pureber.BERDecoderContext())
         assert m=='foo'
         result = str(result)
         result = map(ord, result)
         assert encoded==result
Esempio n. 6
0
 def testFromBERSequenceKnownValues(self):
     """BERSequence(encoded="...") should give known result with known input"""
     for content, encoded in self.knownValues:
         m=MutableString(apply(s,encoded))
         m.append('foo')
         result = pureber.BERSequence(encoded=m, berdecoder=pureber.BERDecoderContext())
         assert m=='foo'
         result = result.data
         assert len(content)==len(result)
         for i in xrange(len(content)):
             assert content[i]==result[i]
         assert content==result
Esempio n. 7
0
 def testPartialBERSequenceEncodings(self):
     """BERSequence(encoded="...") with too short input should throw BERExceptionInsufficientData"""
     m=str(pureber.BERSequence([pureber.BERInteger(2)]))
     assert len(m)==5
     self.assertRaises(pureber.BERExceptionInsufficientData, pureber.BERSequence, encoded=m[:4], berdecoder=pureber.BERDecoderContext())
     self.assertRaises(pureber.BERExceptionInsufficientData, pureber.BERSequence, encoded=m[:3], berdecoder=pureber.BERDecoderContext())
     self.assertRaises(pureber.BERExceptionInsufficientData, pureber.BERSequence, encoded=m[:2], berdecoder=pureber.BERDecoderContext())
     self.assertRaises(pureber.BERExceptionInsufficientData, pureber.BERSequence, encoded=m[:1], berdecoder=pureber.BERDecoderContext())
     self.assertRaises(pureber.BERExceptionInsufficientData, pureber.BERSequence, encoded=MutableString(""), berdecoder=pureber.BERDecoderContext())
Esempio n. 8
0
 def testPartialBEREnumeratedEncodings(self):
     """BEREnumerated(encoded="...") with too short input should throw BERExceptionInsufficientData"""
     m=str(pureber.BEREnumerated(42))
     assert len(m)==3
     self.assertRaises(pureber.BERExceptionInsufficientData, pureber.BEREnumerated, encoded=m[:2], berdecoder=pureber.BERDecoderContext())
     self.assertRaises(pureber.BERExceptionInsufficientData, pureber.BEREnumerated, encoded=m[:1], berdecoder=pureber.BERDecoderContext())
     self.assertRaises(pureber.BERExceptionInsufficientData, pureber.BEREnumerated, encoded=MutableString(""), berdecoder=pureber.BERDecoderContext())