MCPcopy
hub / github.com/pyca/cryptography / generate

Method generate

src/cryptography/hazmat/primitives/twofactor/hotp.py:70–76  ·  view source on GitHub ↗
(self, counter: int)

Source from the content-addressed store, hash-verified

68 self._algorithm = algorithm
69
70 def generate(self, counter: int) -> bytes:
71 if not isinstance(counter, int):
72 raise TypeError("Counter parameter must be an integer type.")
73
74 truncated_value = self._dynamic_truncate(counter)
75 hotp = truncated_value % (10**self._length)
76 return "{0:0{1}}".format(hotp, self._length).encode()
77
78 def verify(self, hotp: bytes, counter: int) -> None:
79 if not constant_time.bytes_eq(self.generate(counter), hotp):

Callers 15

verifyMethod · 0.95
test_generateMethod · 0.95
test_buffer_protocolMethod · 0.95
test_invalid_counterMethod · 0.95
test_roundtripMethod · 0.45
test_wrong_key_x25519Method · 0.45
test_wrong_key_p256Method · 0.45
test_wrong_key_p384Method · 0.45
test_wrong_key_p521Method · 0.45
test_wrong_aad_failsMethod · 0.45

Calls 1

_dynamic_truncateMethod · 0.95

Tested by 15

test_generateMethod · 0.76
test_buffer_protocolMethod · 0.76
test_invalid_counterMethod · 0.76
test_roundtripMethod · 0.36
test_wrong_key_x25519Method · 0.36
test_wrong_key_p256Method · 0.36
test_wrong_key_p384Method · 0.36
test_wrong_key_p521Method · 0.36
test_wrong_aad_failsMethod · 0.36