Ejemplo n.º 1
0
 def testDecodeFunction(self):
     self.assertEqual(tools.DecodeAttr('string', six.b('string')),
                      six.u('string'))
     self.assertEqual(tools.EncodeAttr('octets', six.b('string')),
                      six.b('string'))
     self.assertEqual(tools.DecodeAttr('ipaddr', six.b('\xc0\xa8\x00\xff')),
                      '192.168.0.255')
     self.assertEqual(
         tools.DecodeAttr('integer', six.b('\x01\x02\x03\x04')), 0x01020304)
     self.assertEqual(tools.DecodeAttr('integer64', six.b('\xff' * 8)),
                      0xFFFFFFFFFFFFFFFF)
     self.assertEqual(tools.DecodeAttr('date', six.b('\x01\x02\x03\x04')),
                      0x01020304)
Ejemplo n.º 2
0
    def _DecodeValue(self, attr, value):

        if attr.encrypt == 2:
            #salt decrypt attribute
            value = self.SaltDecrypt(value)

        if attr.values.HasBackward(value):
            return attr.values.GetBackward(value)
        else:
            return tools.DecodeAttr(attr.type, value)
Ejemplo n.º 3
0
 def _DecodeValue(self, attr, value):
     if attr.has_tag:
         # Remove tag prefix if present
         tag, value = tools.DecodeTaggedAttr(attr.type, value)
     if attr.values.HasBackward(value):
         decoded_value = attr.values.GetBackward(value)
     elif attr.encrypt == 1 or attr.encrypt == 2:
         if self.auto_crypt:
             decoded_value = self._DecodeEncryptedValue(attr, value)
         else:
             decoded_value = tools.DecodeOctets(value)
     else:
         decoded_value = tools.DecodeAttr(attr.type, value)
     if attr.has_tag:
         return (tag, decoded_value)
     else:
         return decoded_value
Ejemplo n.º 4
0
 def _DecodeValue(self, attr, value):
     if attr.values.HasBackward(value):
         return attr.values.GetBackward(value)
     else:
         return tools.DecodeAttr(attr.type, value)
Ejemplo n.º 5
0
 def testDecodeFunctionIP(self):
     self.assertEqual(
         tools.DecodeAttr('ipv6prefix',
                          six.b('\x00\x30\x20\x01\x0d\xb8\x12\x34')),
         ipaddress.IPv6Network(six.u('2001:db8:1234::/48')))