Esempio n. 1
0
    def _generate_hashes(self):
        algos = list(hashlib.algorithms_available)
        for a in algorithm.__subclasses__():
            algos.append(a.__name__)

        for module in algos:
            """To support validation within each algorithm's
            module, we wrap an existing implementation
            and name it with the 'hashdd_' prefix to avoid conflicts.
            We're not going to strip this prefix until the very last moment
            as common hashes like md5 may be used in a variety of places
            """
            if self._algorithms is not None and module not in self._algorithms:
                # Skip modules that are not expressly enabled
                continue

            if module.startswith('hashdd_'):
                hexdigest = None
                try:
                    hexdigest = self._runmod_algo(module)
                except (Exception) as e:
                    self._logger.warning(
                        f'Exception raised when calculating {module}, setting to None: {e}'
                    )
                    pass

                setattr(self, module[7:], hexdigest)
Esempio n. 2
0
    def test_all(self):
        algos = [ a.__name__ for a in algorithm.__subclasses__() ]

        for module in algos:
            if module.startswith('hashdd_'):
                m = getattr(hashlib, module)
                if m.sample is not None:
                    self.assertTrue(m.validate(m.sample))
Esempio n. 3
0
 def run_test_available(self, h):
     result = h.safedict()
     algos = [a.__name__ for a in algorithm.__subclasses__()]
     for module in algos:
         if module.startswith('hashdd_'):
             m = getattr(hashlib, module)
             self.assertIsNotNone(m.sample)
             self.assertEqual(result[module], m.sample)
Esempio n. 4
0
 def test_all(self):
     algos = [a.__name__ for a in algorithm.__subclasses__()]
     for module in algos:
         if module.startswith('hashdd_'):
             m = getattr(hashlib, module)
             if m.sample is not None:
                 print 'Testing {} ({})'.format(module, self.result[module])
                 self.assertTrue(self.result[module] == m.sample)
             else:
                 print 'Skipping {}'.format(module)
Esempio n. 5
0
    def algorithms_available():
        """Return a list of hashdd algorithms currently available"""
        available = []

        algos = list(hashlib.algorithms_available)
        for a in algorithm.__subclasses__():
            algos.append(a.__name__)

        for module in algos:
            if module.startswith('hashdd_'):
                available.append(module)

        return available