Ejemplo n.º 1
0
def revcheck(request):
    payload = request.params["payload"]
    checksum = request.params["checksum"]
    payload_format = request.params.get("payload_format", "guess")

    # Attempt parsing payload
    parsed_payload = _attempt_parse_payload(payload, payload_format)
    parsed_checksum = _attempt_parse_checksum(checksum)

    # Attempt parsing provided checksum
    predefined_classifier = PredefinedCRCAlgorithClassifier()
    match = predefined_classifier.find_match(parsed_payload, parsed_checksum)
    if match is None:
        return {
            "result": "no_algorithm_found",
            "message": "Data was valid but not matching checksum algorithm was found"
        }
    else:
        return {
            "result": "success",
            "algoriths": [
                {"type": "predefined",
                 "key": match}
            ]
        }
Ejemplo n.º 2
0
class TestPredefinedCRCAlgorithmClassifer(unittest.TestCase):

    def setUp(self):
        self.classifier = PredefinedCRCAlgorithClassifier()

    def test_crcmod_crc16(self):
        crcfun = mkPredefinedCrcFun("crc-16")
        self.assertEqual(crcfun('123456789'), 0xBB3D)

    def test_classify_crc16(self):
        classification = self.classifier.find_match('123456789', 0xBB3D)
        self.assertEqual(classification, 'crc-16')
Ejemplo n.º 3
0
 def setUp(self):
     self.classifier = PredefinedCRCAlgorithClassifier()