Files
community.crypto/tests/unit/plugins/module_utils/crypto/test_math.py
Felix Fontein 82251c2d80 Revert all non-bugfixes merged since the last release.
Revert "Fix documentation. (#751)"
Revert "ACME modules: simplify code, refactor argspec handling code, move csr/csr_content to own docs fragment (#750)"
Revert "Refactor and extend argument spec helper, use for ACME modules (#749)"
Revert "Avoid exception if certificate has no AKI in acme_certificate. (#748)"
Revert "ACME: improve acme_certificate docs, include cert_id in acme_certificate_renewal_info return value (#747)"
Revert "Add acme_certificate_renewal_info module (#746)"
Revert "Refactor time code, add tests, fix bug when parsing absolute timestamps that omit seconds (#745)"
Revert "Add tests for acme_certificate_deactivate_authz module. (#744)"
Revert "Create acme_certificate_deactivate_authz module (#741)"
Revert "acme_certificate: allow to request renewal of a certificate according to ARI (#739)"
Revert "Implement basic acme_ari_info module. (#732)"
Revert "Add function for retrieval of ARI information. (#738)"
Revert "acme module utils: add functions for parsing Retry-After header values and computation of ARI certificate IDs (#737)"
Revert "Implement certificate information retrieval code in the ACME backends. (#736)"
Revert "Split up the default acme docs fragment to allow modules ot not need account data. (#735)"

This reverts commits 5e59c5261e, aa82575a78,
f3c9cb7a8a, f82b335916, 553ab45f46,
59606d48ad, 0a15be1017, 9501a28a93,
d906914737, 33d278ad8f, 6d4fc589ae,
9614b09f7a, af5f4b57f8, c6fbe58382,
and afe7f7522c.
2024-05-11 16:07:53 +02:00

103 lines
2.3 KiB
Python

# -*- coding: utf-8 -*-
# Copyright (c) 2024, Felix Fontein <felix@fontein.de>
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
from __future__ import absolute_import, division, print_function
__metaclass__ = type
import pytest
from ansible_collections.community.crypto.plugins.module_utils.crypto.math import (
binary_exp_mod,
simple_gcd,
quick_is_not_prime,
convert_int_to_bytes,
convert_int_to_hex,
)
@pytest.mark.parametrize('f, e, m, result', [
(0, 0, 5, 1),
(0, 1, 5, 0),
(2, 1, 5, 2),
(2, 2, 5, 4),
(2, 3, 5, 3),
(2, 10, 5, 4),
])
def test_binary_exp_mod(f, e, m, result):
value = binary_exp_mod(f, e, m)
print(value)
assert value == result
@pytest.mark.parametrize('a, b, result', [
(0, -123, -123),
(0, 123, 123),
(-123, 0, -123),
(123, 0, 123),
(-123, 1, 1),
(123, 1, 1),
(1, -123, -1),
(1, 123, 1),
(1024, 10, 2),
])
def test_simple_gcd(a, b, result):
value = simple_gcd(a, b)
print(value)
assert value == result
@pytest.mark.parametrize('n, result', [
(-2, True),
(0, True),
(1, True),
(2, False),
(3, False),
(4, True),
(5, False),
(6, True),
(7, False),
(8, True),
(9, True),
(10, True),
(211, False), # the smallest prime number >= 200
])
def test_quick_is_not_prime(n, result):
value = quick_is_not_prime(n)
print(value)
assert value == result
@pytest.mark.parametrize('no, count, result', [
(0, None, b''),
(0, 1, b'\x00'),
(0, 2, b'\x00\x00'),
(1, None, b'\x01'),
(1, 2, b'\x00\x01'),
(255, None, b'\xff'),
(256, None, b'\x01\x00'),
])
def test_convert_int_to_bytes(no, count, result):
value = convert_int_to_bytes(no, count=count)
print(value)
assert value == result
@pytest.mark.parametrize('no, digits, result', [
(0, None, '0'),
(1, None, '1'),
(16, None, '10'),
(1, 3, '001'),
(255, None, 'ff'),
(256, None, '100'),
(256, 2, '100'),
(256, 3, '100'),
(256, 4, '0100'),
])
def test_convert_int_to_hex(no, digits, result):
value = convert_int_to_hex(no, digits=digits)
print(value)
assert value == result