Reference implementations of PQC
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 

64 lignes
2.2 KiB

  1. """
  2. Checks that files duplicated across schemes/implementations are consistent.
  3. """
  4. import os
  5. import yaml
  6. import helpers
  7. import pqclean
  8. def pytest_generate_tests(metafunc):
  9. ids = []
  10. argvalues = []
  11. for scheme in pqclean.Scheme.all_schemes():
  12. for implementation in scheme.implementations:
  13. if os.path.isfile(
  14. os.path.join(
  15. 'duplicate_consistency',
  16. '{}_{}.yml'.format(scheme.name, implementation.name))):
  17. metafile = os.path.join(
  18. 'duplicate_consistency',
  19. '{}_{}.yml'.format(scheme.name, implementation.name))
  20. with open(metafile, encoding='utf-8') as f:
  21. metadata = yaml.safe_load(f.read())
  22. for group in metadata['consistency_checks']:
  23. source = pqclean.Implementation.by_name(
  24. group['source']['scheme'],
  25. group['source']['implementation'])
  26. for file in group['files']:
  27. argvalues.append((implementation, source, file))
  28. ids.append(
  29. "{scheme.name}-{source.scheme.name}: {file}"
  30. .format(scheme=scheme, source=source,
  31. file=file))
  32. metafunc.parametrize(('implementation', 'source', 'file'),
  33. argvalues,
  34. ids=ids)
  35. def file_get_contents(filename):
  36. with open(filename) as f:
  37. return f.read()
  38. @helpers.skip_windows()
  39. @helpers.filtered_test
  40. def test_duplicate_consistency(implementation, source, file):
  41. transformed_src = helpers.run_subprocess(
  42. ['sed', '-e', 's/{}/{}/g'.format(source.namespace_prefix(),
  43. implementation.namespace_prefix()), os.path.join(source.path(), file)]
  44. )
  45. this_src = file_get_contents(os.path.join(implementation.path(), file))
  46. print(os.path.join(implementation.path(), file))
  47. print(this_src)
  48. assert(transformed_src == this_src)
  49. if __name__ == '__main__':
  50. import pytest
  51. import sys
  52. pytest.main(sys.argv)