From 3169390d69e41ba07f7825efc78c86284f3cb4e1 Mon Sep 17 00:00:00 2001 From: J08nY Date: Thu, 20 Mar 2025 10:01:50 +0100 Subject: Allow Mod formatting. --- pyecsca/ec/mod/base.py | 3 +++ test/ec/test_mod.py | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/pyecsca/ec/mod/base.py b/pyecsca/ec/mod/base.py index f5aab09..b7aa48a 100644 --- a/pyecsca/ec/mod/base.py +++ b/pyecsca/ec/mod/base.py @@ -262,6 +262,9 @@ class Mod: def __str__(self): return str(self.x) + def __format__(self, format_spec): + return format(int(self), format_spec) + @public class Undefined(Mod): diff --git a/test/ec/test_mod.py b/test/ec/test_mod.py index 07f5bdf..18eeeac 100644 --- a/test/ec/test_mod.py +++ b/test/ec/test_mod.py @@ -20,6 +20,7 @@ from pyecsca.ec.mod import ( jacobi, ) from pyecsca.ec.mod.gmp import has_gmp +from pyecsca.ec.mod.flint import has_flint from pyecsca.misc.cfg import getconfig, TemporaryConfig @@ -149,6 +150,7 @@ def test_other(): b = mod(3, 7) assert int(-a) == 2 assert str(a) == "5" + assert f"{a:02x}" == "05" assert 6 - a == mod(1, 7) assert a != b assert a / b == mod(4, 7) @@ -199,7 +201,7 @@ def test_undefined(): def test_implementation(): - if not has_gmp: + if not has_gmp or has_flint: pytest.skip("Only makes sense if more Mod implementations are available.") with TemporaryConfig() as cfg: cfg.ec.mod_implementation = "python" -- cgit v1.2.3-70-g09d2