Skip to content

back to Claude Sonnet 3.5 - Fill-in summary

Claude Sonnet 3.5 - Fill-in: python-rsa

Pytest Summary for test tests

status count
error 14
passed 27
failed 46
total 87
collected 87

Failed pytests:

test_cli.py::KeygenTest::test_keygen_no_args

test_cli.py::KeygenTest::test_keygen_no_args
cls = 

    @classmethod
    def setUpClass(cls):
        # Ensure there is a key to use
>       cls.pub_key, cls.priv_key = rsa.newkeys(512)

tests/test_cli.py:85: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
rsa/key.py:634: in newkeys
    (p, q, e, d) = gen_keys(nbits, accurate=accurate, exponent=exponent,
rsa/key.py:597: in gen_keys
    p, q = find_p_q(nbits // 2, getprime_func, accurate)
rsa/key.py:512: in find_p_q
    p = getprime_func(pbits)
rsa/prime.py:127: in getprime
    if is_prime(integer):
rsa/prime.py:102: in is_prime
    return miller_rabin_primality_testing(number, get_primality_testing_rounds(number))
rsa/prime.py:72: in miller_rabin_primality_testing
    a = rsa.randnum.read_random_odd_int(n - 3) + 2
rsa/randnum.py:37: in read_random_odd_int
    return read_random_int(nbits) | 1
rsa/randnum.py:28: in read_random_int
    return transform.bytes2int(read_random_bits(nbits))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

nbits = 743751405158786252...2836173314102210566

    def read_random_bits(nbits: int) ->bytes:
        """Reads 'nbits' random bits.

        If nbits isn't a whole number of bytes, an extra byte will be appended with
        only the lower bits set.
        """
        nbytes, rbits = divmod(nbits, 8)

        # Get the specified number of bytes
>       bytes_data = os.urandom(nbytes)
E       OverflowError: Python int too large to convert to C ssize_t

rsa/randnum.py:16: OverflowError

test_cli.py::KeygenTest::test_keygen_priv_out_der

test_cli.py::KeygenTest::test_keygen_priv_out_der
cls = 

    @classmethod
    def setUpClass(cls):
        # Ensure there is a key to use
>       cls.pub_key, cls.priv_key = rsa.newkeys(512)

tests/test_cli.py:85: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
rsa/key.py:634: in newkeys
    (p, q, e, d) = gen_keys(nbits, accurate=accurate, exponent=exponent,
rsa/key.py:597: in gen_keys
    p, q = find_p_q(nbits // 2, getprime_func, accurate)
rsa/key.py:512: in find_p_q
    p = getprime_func(pbits)
rsa/prime.py:127: in getprime
    if is_prime(integer):
rsa/prime.py:102: in is_prime
    return miller_rabin_primality_testing(number, get_primality_testing_rounds(number))
rsa/prime.py:72: in miller_rabin_primality_testing
    a = rsa.randnum.read_random_odd_int(n - 3) + 2
rsa/randnum.py:37: in read_random_odd_int
    return read_random_int(nbits) | 1
rsa/randnum.py:28: in read_random_int
    return transform.bytes2int(read_random_bits(nbits))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

nbits = 743751405158786252...2836173314102210566

    def read_random_bits(nbits: int) ->bytes:
        """Reads 'nbits' random bits.

        If nbits isn't a whole number of bytes, an extra byte will be appended with
        only the lower bits set.
        """
        nbytes, rbits = divmod(nbits, 8)

        # Get the specified number of bytes
>       bytes_data = os.urandom(nbytes)
E       OverflowError: Python int too large to convert to C ssize_t

rsa/randnum.py:16: OverflowError

test_cli.py::KeygenTest::test_keygen_priv_out_pem

test_cli.py::KeygenTest::test_keygen_priv_out_pem
cls = 

    @classmethod
    def setUpClass(cls):
        # Ensure there is a key to use
>       cls.pub_key, cls.priv_key = rsa.newkeys(512)

tests/test_cli.py:85: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
rsa/key.py:634: in newkeys
    (p, q, e, d) = gen_keys(nbits, accurate=accurate, exponent=exponent,
rsa/key.py:597: in gen_keys
    p, q = find_p_q(nbits // 2, getprime_func, accurate)
rsa/key.py:512: in find_p_q
    p = getprime_func(pbits)
rsa/prime.py:127: in getprime
    if is_prime(integer):
rsa/prime.py:102: in is_prime
    return miller_rabin_primality_testing(number, get_primality_testing_rounds(number))
rsa/prime.py:72: in miller_rabin_primality_testing
    a = rsa.randnum.read_random_odd_int(n - 3) + 2
rsa/randnum.py:37: in read_random_odd_int
    return read_random_int(nbits) | 1
rsa/randnum.py:28: in read_random_int
    return transform.bytes2int(read_random_bits(nbits))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

nbits = 743751405158786252...2836173314102210566

    def read_random_bits(nbits: int) ->bytes:
        """Reads 'nbits' random bits.

        If nbits isn't a whole number of bytes, an extra byte will be appended with
        only the lower bits set.
        """
        nbytes, rbits = divmod(nbits, 8)

        # Get the specified number of bytes
>       bytes_data = os.urandom(nbytes)
E       OverflowError: Python int too large to convert to C ssize_t

rsa/randnum.py:16: OverflowError

test_cli.py::KeygenTest::test_keygen_priv_stdout

test_cli.py::KeygenTest::test_keygen_priv_stdout
cls = 

    @classmethod
    def setUpClass(cls):
        # Ensure there is a key to use
>       cls.pub_key, cls.priv_key = rsa.newkeys(512)

tests/test_cli.py:85: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
rsa/key.py:634: in newkeys
    (p, q, e, d) = gen_keys(nbits, accurate=accurate, exponent=exponent,
rsa/key.py:597: in gen_keys
    p, q = find_p_q(nbits // 2, getprime_func, accurate)
rsa/key.py:512: in find_p_q
    p = getprime_func(pbits)
rsa/prime.py:127: in getprime
    if is_prime(integer):
rsa/prime.py:102: in is_prime
    return miller_rabin_primality_testing(number, get_primality_testing_rounds(number))
rsa/prime.py:72: in miller_rabin_primality_testing
    a = rsa.randnum.read_random_odd_int(n - 3) + 2
rsa/randnum.py:37: in read_random_odd_int
    return read_random_int(nbits) | 1
rsa/randnum.py:28: in read_random_int
    return transform.bytes2int(read_random_bits(nbits))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

nbits = 743751405158786252...2836173314102210566

    def read_random_bits(nbits: int) ->bytes:
        """Reads 'nbits' random bits.

        If nbits isn't a whole number of bytes, an extra byte will be appended with
        only the lower bits set.
        """
        nbytes, rbits = divmod(nbits, 8)

        # Get the specified number of bytes
>       bytes_data = os.urandom(nbytes)
E       OverflowError: Python int too large to convert to C ssize_t

rsa/randnum.py:16: OverflowError

test_cli.py::KeygenTest::test_keygen_pub_out_pem

test_cli.py::KeygenTest::test_keygen_pub_out_pem
cls = 

    @classmethod
    def setUpClass(cls):
        # Ensure there is a key to use
>       cls.pub_key, cls.priv_key = rsa.newkeys(512)

tests/test_cli.py:85: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
rsa/key.py:634: in newkeys
    (p, q, e, d) = gen_keys(nbits, accurate=accurate, exponent=exponent,
rsa/key.py:597: in gen_keys
    p, q = find_p_q(nbits // 2, getprime_func, accurate)
rsa/key.py:512: in find_p_q
    p = getprime_func(pbits)
rsa/prime.py:127: in getprime
    if is_prime(integer):
rsa/prime.py:102: in is_prime
    return miller_rabin_primality_testing(number, get_primality_testing_rounds(number))
rsa/prime.py:72: in miller_rabin_primality_testing
    a = rsa.randnum.read_random_odd_int(n - 3) + 2
rsa/randnum.py:37: in read_random_odd_int
    return read_random_int(nbits) | 1
rsa/randnum.py:28: in read_random_int
    return transform.bytes2int(read_random_bits(nbits))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

nbits = 743751405158786252...2836173314102210566

    def read_random_bits(nbits: int) ->bytes:
        """Reads 'nbits' random bits.

        If nbits isn't a whole number of bytes, an extra byte will be appended with
        only the lower bits set.
        """
        nbytes, rbits = divmod(nbits, 8)

        # Get the specified number of bytes
>       bytes_data = os.urandom(nbytes)
E       OverflowError: Python int too large to convert to C ssize_t

rsa/randnum.py:16: OverflowError

test_cli.py::EncryptDecryptTest::test_empty_decrypt

test_cli.py::EncryptDecryptTest::test_empty_decrypt
cls = 

    @classmethod
    def setUpClass(cls):
        # Ensure there is a key to use
>       cls.pub_key, cls.priv_key = rsa.newkeys(512)

tests/test_cli.py:85: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
rsa/key.py:634: in newkeys
    (p, q, e, d) = gen_keys(nbits, accurate=accurate, exponent=exponent,
rsa/key.py:597: in gen_keys
    p, q = find_p_q(nbits // 2, getprime_func, accurate)
rsa/key.py:512: in find_p_q
    p = getprime_func(pbits)
rsa/prime.py:127: in getprime
    if is_prime(integer):
rsa/prime.py:102: in is_prime
    return miller_rabin_primality_testing(number, get_primality_testing_rounds(number))
rsa/prime.py:72: in miller_rabin_primality_testing
    a = rsa.randnum.read_random_odd_int(n - 3) + 2
rsa/randnum.py:37: in read_random_odd_int
    return read_random_int(nbits) | 1
rsa/randnum.py:28: in read_random_int
    return transform.bytes2int(read_random_bits(nbits))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

nbits = 811199013963414042...1891549032260233556

    def read_random_bits(nbits: int) ->bytes:
        """Reads 'nbits' random bits.

        If nbits isn't a whole number of bytes, an extra byte will be appended with
        only the lower bits set.
        """
        nbytes, rbits = divmod(nbits, 8)

        # Get the specified number of bytes
>       bytes_data = os.urandom(nbytes)
E       OverflowError: Python int too large to convert to C ssize_t

rsa/randnum.py:16: OverflowError

test_cli.py::EncryptDecryptTest::test_empty_encrypt

test_cli.py::EncryptDecryptTest::test_empty_encrypt
cls = 

    @classmethod
    def setUpClass(cls):
        # Ensure there is a key to use
>       cls.pub_key, cls.priv_key = rsa.newkeys(512)

tests/test_cli.py:85: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
rsa/key.py:634: in newkeys
    (p, q, e, d) = gen_keys(nbits, accurate=accurate, exponent=exponent,
rsa/key.py:597: in gen_keys
    p, q = find_p_q(nbits // 2, getprime_func, accurate)
rsa/key.py:512: in find_p_q
    p = getprime_func(pbits)
rsa/prime.py:127: in getprime
    if is_prime(integer):
rsa/prime.py:102: in is_prime
    return miller_rabin_primality_testing(number, get_primality_testing_rounds(number))
rsa/prime.py:72: in miller_rabin_primality_testing
    a = rsa.randnum.read_random_odd_int(n - 3) + 2
rsa/randnum.py:37: in read_random_odd_int
    return read_random_int(nbits) | 1
rsa/randnum.py:28: in read_random_int
    return transform.bytes2int(read_random_bits(nbits))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

nbits = 811199013963414042...1891549032260233556

    def read_random_bits(nbits: int) ->bytes:
        """Reads 'nbits' random bits.

        If nbits isn't a whole number of bytes, an extra byte will be appended with
        only the lower bits set.
        """
        nbytes, rbits = divmod(nbits, 8)

        # Get the specified number of bytes
>       bytes_data = os.urandom(nbytes)
E       OverflowError: Python int too large to convert to C ssize_t

rsa/randnum.py:16: OverflowError

test_cli.py::EncryptDecryptTest::test_encrypt_decrypt

test_cli.py::EncryptDecryptTest::test_encrypt_decrypt
cls = 

    @classmethod
    def setUpClass(cls):
        # Ensure there is a key to use
>       cls.pub_key, cls.priv_key = rsa.newkeys(512)

tests/test_cli.py:85: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
rsa/key.py:634: in newkeys
    (p, q, e, d) = gen_keys(nbits, accurate=accurate, exponent=exponent,
rsa/key.py:597: in gen_keys
    p, q = find_p_q(nbits // 2, getprime_func, accurate)
rsa/key.py:512: in find_p_q
    p = getprime_func(pbits)
rsa/prime.py:127: in getprime
    if is_prime(integer):
rsa/prime.py:102: in is_prime
    return miller_rabin_primality_testing(number, get_primality_testing_rounds(number))
rsa/prime.py:72: in miller_rabin_primality_testing
    a = rsa.randnum.read_random_odd_int(n - 3) + 2
rsa/randnum.py:37: in read_random_odd_int
    return read_random_int(nbits) | 1
rsa/randnum.py:28: in read_random_int
    return transform.bytes2int(read_random_bits(nbits))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

nbits = 811199013963414042...1891549032260233556

    def read_random_bits(nbits: int) ->bytes:
        """Reads 'nbits' random bits.

        If nbits isn't a whole number of bytes, an extra byte will be appended with
        only the lower bits set.
        """
        nbytes, rbits = divmod(nbits, 8)

        # Get the specified number of bytes
>       bytes_data = os.urandom(nbytes)
E       OverflowError: Python int too large to convert to C ssize_t

rsa/randnum.py:16: OverflowError

test_cli.py::EncryptDecryptTest::test_encrypt_decrypt_unhappy

test_cli.py::EncryptDecryptTest::test_encrypt_decrypt_unhappy
cls = 

    @classmethod
    def setUpClass(cls):
        # Ensure there is a key to use
>       cls.pub_key, cls.priv_key = rsa.newkeys(512)

tests/test_cli.py:85: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
rsa/key.py:634: in newkeys
    (p, q, e, d) = gen_keys(nbits, accurate=accurate, exponent=exponent,
rsa/key.py:597: in gen_keys
    p, q = find_p_q(nbits // 2, getprime_func, accurate)
rsa/key.py:512: in find_p_q
    p = getprime_func(pbits)
rsa/prime.py:127: in getprime
    if is_prime(integer):
rsa/prime.py:102: in is_prime
    return miller_rabin_primality_testing(number, get_primality_testing_rounds(number))
rsa/prime.py:72: in miller_rabin_primality_testing
    a = rsa.randnum.read_random_odd_int(n - 3) + 2
rsa/randnum.py:37: in read_random_odd_int
    return read_random_int(nbits) | 1
rsa/randnum.py:28: in read_random_int
    return transform.bytes2int(read_random_bits(nbits))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

nbits = 811199013963414042...1891549032260233556

    def read_random_bits(nbits: int) ->bytes:
        """Reads 'nbits' random bits.

        If nbits isn't a whole number of bytes, an extra byte will be appended with
        only the lower bits set.
        """
        nbytes, rbits = divmod(nbits, 8)

        # Get the specified number of bytes
>       bytes_data = os.urandom(nbytes)
E       OverflowError: Python int too large to convert to C ssize_t

rsa/randnum.py:16: OverflowError

test_cli.py::SignVerifyTest::test_empty_sign

test_cli.py::SignVerifyTest::test_empty_sign
cls = 

    @classmethod
    def setUpClass(cls):
        # Ensure there is a key to use
>       cls.pub_key, cls.priv_key = rsa.newkeys(512)

tests/test_cli.py:85: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
rsa/key.py:634: in newkeys
    (p, q, e, d) = gen_keys(nbits, accurate=accurate, exponent=exponent,
rsa/key.py:597: in gen_keys
    p, q = find_p_q(nbits // 2, getprime_func, accurate)
rsa/key.py:512: in find_p_q
    p = getprime_func(pbits)
rsa/prime.py:127: in getprime
    if is_prime(integer):
rsa/prime.py:102: in is_prime
    return miller_rabin_primality_testing(number, get_primality_testing_rounds(number))
rsa/prime.py:72: in miller_rabin_primality_testing
    a = rsa.randnum.read_random_odd_int(n - 3) + 2
rsa/randnum.py:37: in read_random_odd_int
    return read_random_int(nbits) | 1
rsa/randnum.py:28: in read_random_int
    return transform.bytes2int(read_random_bits(nbits))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

nbits = 827351877812086722...6328161396155403886

    def read_random_bits(nbits: int) ->bytes:
        """Reads 'nbits' random bits.

        If nbits isn't a whole number of bytes, an extra byte will be appended with
        only the lower bits set.
        """
        nbytes, rbits = divmod(nbits, 8)

        # Get the specified number of bytes
>       bytes_data = os.urandom(nbytes)
E       OverflowError: Python int too large to convert to C ssize_t

rsa/randnum.py:16: OverflowError

test_cli.py::SignVerifyTest::test_empty_verify

test_cli.py::SignVerifyTest::test_empty_verify
cls = 

    @classmethod
    def setUpClass(cls):
        # Ensure there is a key to use
>       cls.pub_key, cls.priv_key = rsa.newkeys(512)

tests/test_cli.py:85: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
rsa/key.py:634: in newkeys
    (p, q, e, d) = gen_keys(nbits, accurate=accurate, exponent=exponent,
rsa/key.py:597: in gen_keys
    p, q = find_p_q(nbits // 2, getprime_func, accurate)
rsa/key.py:512: in find_p_q
    p = getprime_func(pbits)
rsa/prime.py:127: in getprime
    if is_prime(integer):
rsa/prime.py:102: in is_prime
    return miller_rabin_primality_testing(number, get_primality_testing_rounds(number))
rsa/prime.py:72: in miller_rabin_primality_testing
    a = rsa.randnum.read_random_odd_int(n - 3) + 2
rsa/randnum.py:37: in read_random_odd_int
    return read_random_int(nbits) | 1
rsa/randnum.py:28: in read_random_int
    return transform.bytes2int(read_random_bits(nbits))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

nbits = 827351877812086722...6328161396155403886

    def read_random_bits(nbits: int) ->bytes:
        """Reads 'nbits' random bits.

        If nbits isn't a whole number of bytes, an extra byte will be appended with
        only the lower bits set.
        """
        nbytes, rbits = divmod(nbits, 8)

        # Get the specified number of bytes
>       bytes_data = os.urandom(nbytes)
E       OverflowError: Python int too large to convert to C ssize_t

rsa/randnum.py:16: OverflowError

test_cli.py::SignVerifyTest::test_sign_verify

test_cli.py::SignVerifyTest::test_sign_verify
cls = 

    @classmethod
    def setUpClass(cls):
        # Ensure there is a key to use
>       cls.pub_key, cls.priv_key = rsa.newkeys(512)

tests/test_cli.py:85: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
rsa/key.py:634: in newkeys
    (p, q, e, d) = gen_keys(nbits, accurate=accurate, exponent=exponent,
rsa/key.py:597: in gen_keys
    p, q = find_p_q(nbits // 2, getprime_func, accurate)
rsa/key.py:512: in find_p_q
    p = getprime_func(pbits)
rsa/prime.py:127: in getprime
    if is_prime(integer):
rsa/prime.py:102: in is_prime
    return miller_rabin_primality_testing(number, get_primality_testing_rounds(number))
rsa/prime.py:72: in miller_rabin_primality_testing
    a = rsa.randnum.read_random_odd_int(n - 3) + 2
rsa/randnum.py:37: in read_random_odd_int
    return read_random_int(nbits) | 1
rsa/randnum.py:28: in read_random_int
    return transform.bytes2int(read_random_bits(nbits))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

nbits = 827351877812086722...6328161396155403886

    def read_random_bits(nbits: int) ->bytes:
        """Reads 'nbits' random bits.

        If nbits isn't a whole number of bytes, an extra byte will be appended with
        only the lower bits set.
        """
        nbytes, rbits = divmod(nbits, 8)

        # Get the specified number of bytes
>       bytes_data = os.urandom(nbytes)
E       OverflowError: Python int too large to convert to C ssize_t

rsa/randnum.py:16: OverflowError

test_cli.py::SignVerifyTest::test_sign_verify_unhappy

test_cli.py::SignVerifyTest::test_sign_verify_unhappy
cls = 

    @classmethod
    def setUpClass(cls):
        # Ensure there is a key to use
>       cls.pub_key, cls.priv_key = rsa.newkeys(512)

tests/test_cli.py:85: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
rsa/key.py:634: in newkeys
    (p, q, e, d) = gen_keys(nbits, accurate=accurate, exponent=exponent,
rsa/key.py:597: in gen_keys
    p, q = find_p_q(nbits // 2, getprime_func, accurate)
rsa/key.py:512: in find_p_q
    p = getprime_func(pbits)
rsa/prime.py:127: in getprime
    if is_prime(integer):
rsa/prime.py:102: in is_prime
    return miller_rabin_primality_testing(number, get_primality_testing_rounds(number))
rsa/prime.py:72: in miller_rabin_primality_testing
    a = rsa.randnum.read_random_odd_int(n - 3) + 2
rsa/randnum.py:37: in read_random_odd_int
    return read_random_int(nbits) | 1
rsa/randnum.py:28: in read_random_int
    return transform.bytes2int(read_random_bits(nbits))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

nbits = 827351877812086722...6328161396155403886

    def read_random_bits(nbits: int) ->bytes:
        """Reads 'nbits' random bits.

        If nbits isn't a whole number of bytes, an extra byte will be appended with
        only the lower bits set.
        """
        nbytes, rbits = divmod(nbits, 8)

        # Get the specified number of bytes
>       bytes_data = os.urandom(nbytes)
E       OverflowError: Python int too large to convert to C ssize_t

rsa/randnum.py:16: OverflowError

test_cli.py::PrivatePublicTest::test_private_to_public

test_cli.py::PrivatePublicTest::test_private_to_public
cls = 

    @classmethod
    def setUpClass(cls):
        # Ensure there is a key to use
>       cls.pub_key, cls.priv_key = rsa.newkeys(512)

tests/test_cli.py:85: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
rsa/key.py:634: in newkeys
    (p, q, e, d) = gen_keys(nbits, accurate=accurate, exponent=exponent,
rsa/key.py:597: in gen_keys
    p, q = find_p_q(nbits // 2, getprime_func, accurate)
rsa/key.py:512: in find_p_q
    p = getprime_func(pbits)
rsa/prime.py:127: in getprime
    if is_prime(integer):
rsa/prime.py:102: in is_prime
    return miller_rabin_primality_testing(number, get_primality_testing_rounds(number))
rsa/prime.py:72: in miller_rabin_primality_testing
    a = rsa.randnum.read_random_odd_int(n - 3) + 2
rsa/randnum.py:37: in read_random_odd_int
    return read_random_int(nbits) | 1
rsa/randnum.py:28: in read_random_int
    return transform.bytes2int(read_random_bits(nbits))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

nbits = 977397274916830518...1552735140431588956

    def read_random_bits(nbits: int) ->bytes:
        """Reads 'nbits' random bits.

        If nbits isn't a whole number of bytes, an extra byte will be appended with
        only the lower bits set.
        """
        nbytes, rbits = divmod(nbits, 8)

        # Get the specified number of bytes
>       bytes_data = os.urandom(nbytes)
E       OverflowError: Python int too large to convert to C ssize_t

rsa/randnum.py:16: OverflowError

test_common.py::TestByteSize::test_zero

test_common.py::TestByteSize::test_zero
self = 

    def test_zero(self):
>       self.assertEqual(byte_size(0), 1)
E       AssertionError: 0 != 1

tests/test_common.py:37: AssertionError

test_common.py::TestBitSize::test_bad_type

test_common.py::TestBitSize::test_bad_type
self = 

    def test_bad_type(self):
        self.assertRaises(TypeError, bit_size, [])
        self.assertRaises(TypeError, bit_size, ())
        self.assertRaises(TypeError, bit_size, dict())
        self.assertRaises(TypeError, bit_size, "")
        self.assertRaises(TypeError, bit_size, None)
>       self.assertRaises(TypeError, bit_size, 0.0)
E       AssertionError: TypeError not raised by bit_size

tests/test_common.py:73: AssertionError

test_key.py::BlindingTest::test_blinding

test_key.py::BlindingTest::test_blinding
self = 

    def test_blinding(self):
        """Test blinding and unblinding.

        This is basically the doctest of the PrivateKey.blind method, but then
        implemented as unittest to allow running on different Python versions.
        """

        pk = rsa.key.PrivateKey(3727264081, 65537, 3349121513, 65063, 57287)

        message = 12345
        encrypted = rsa.core.encrypt_int(message, pk.e, pk.n)

        blinded_1, unblind_1 = pk.blind(encrypted)  # blind before decrypting
        decrypted = rsa.core.decrypt_int(blinded_1, pk.d, pk.n)
        unblinded_1 = pk.unblind(decrypted, unblind_1)

>       self.assertEqual(unblinded_1, message)
E       AssertionError: 167378821 != 12345

tests/test_key.py:28: AssertionError

test_key.py::KeyGenTest::test_custom_exponent

test_key.py::KeyGenTest::test_custom_exponent
p = 241, q = 149, exponent = 3

    def calculate_keys_custom_exponent(p: int, q: int, exponent: int
        ) ->typing.Tuple[int, int]:
        """Calculates an encryption and a decryption key given p, q and an exponent,
        and returns them as a tuple (e, d)

        :param p: the first large prime
        :param q: the second large prime
        :param exponent: the exponent for the key; only change this if you know
            what you're doing, as the exponent influences how difficult your
            private key can be cracked. A very common choice for e is 65537.
        :type exponent: int

        """
        phi_n = (p - 1) * (q - 1)

        try:
>           d = rsa.common.inverse(exponent, phi_n)

rsa/key.py:559: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

x = 3, n = 35520

    def inverse(x: int, n: int) ->int:
        """Returns the inverse of x % n under multiplication, a.k.a x^-1 (mod n)

        >>> inverse(7, 4)
        3
        >>> (inverse(143, 4) * 143) % 4
        1
        """
        gcd, a, _ = extended_gcd(x, n)
        if gcd != 1:
>           raise NotRelativePrimeError(x, n, gcd)
E           rsa.common.NotRelativePrimeError: 3 and 35520 are not relatively prime, divider=3

rsa/common.py:107: NotRelativePrimeError

During handling of the above exception, another exception occurred:

self = 

    def test_custom_exponent(self):
>       pub, priv = rsa.key.newkeys(16, exponent=3)

tests/test_key.py:42: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
rsa/key.py:634: in newkeys
    (p, q, e, d) = gen_keys(nbits, accurate=accurate, exponent=exponent,
rsa/key.py:598: in gen_keys
    e, d = calculate_keys_custom_exponent(p, q, exponent)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

p = 241, q = 149, exponent = 3

    def calculate_keys_custom_exponent(p: int, q: int, exponent: int
        ) ->typing.Tuple[int, int]:
        """Calculates an encryption and a decryption key given p, q and an exponent,
        and returns them as a tuple (e, d)

        :param p: the first large prime
        :param q: the second large prime
        :param exponent: the exponent for the key; only change this if you know
            what you're doing, as the exponent influences how difficult your
            private key can be cracked. A very common choice for e is 65537.
        :type exponent: int

        """
        phi_n = (p - 1) * (q - 1)

        try:
            d = rsa.common.inverse(exponent, phi_n)
        except ValueError:
>           raise ValueError("e and phi_n are not relatively prime")
E           ValueError: e and phi_n are not relatively prime

rsa/key.py:561: ValueError

test_key.py::KeyGenTest::test_custom_getprime_func

test_key.py::KeyGenTest::test_custom_getprime_func
p = 64123, q = 50957, exponent = 136407

    def calculate_keys_custom_exponent(p: int, q: int, exponent: int
        ) ->typing.Tuple[int, int]:
        """Calculates an encryption and a decryption key given p, q and an exponent,
        and returns them as a tuple (e, d)

        :param p: the first large prime
        :param q: the second large prime
        :param exponent: the exponent for the key; only change this if you know
            what you're doing, as the exponent influences how difficult your
            private key can be cracked. A very common choice for e is 65537.
        :type exponent: int

        """
        phi_n = (p - 1) * (q - 1)

        try:
>           d = rsa.common.inverse(exponent, phi_n)

rsa/key.py:559: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

x = 136407, n = 3267400632

    def inverse(x: int, n: int) ->int:
        """Returns the inverse of x % n under multiplication, a.k.a x^-1 (mod n)

        >>> inverse(7, 4)
        3
        >>> (inverse(143, 4) * 143) % 4
        1
        """
        gcd, a, _ = extended_gcd(x, n)
        if gcd != 1:
>           raise NotRelativePrimeError(x, n, gcd)
E           rsa.common.NotRelativePrimeError: 136407 and 3267400632 are not relatively prime, divider=3

rsa/common.py:107: NotRelativePrimeError

During handling of the above exception, another exception occurred:

self = 

    def test_custom_getprime_func(self):
        # List of primes to test with, in order [p, q, p, q, ....]
        # By starting with two of the same primes, we test that this is
        # properly rejected.
        primes = [64123, 64123, 64123, 50957, 39317, 33107]

        def getprime(_):
            return primes.pop(0)

        # This exponent will cause two other primes to be generated.
        exponent = 136407

>       (p, q, e, d) = rsa.key.gen_keys(
            64, accurate=False, getprime_func=getprime, exponent=exponent
        )

tests/test_key.py:72: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
rsa/key.py:598: in gen_keys
    e, d = calculate_keys_custom_exponent(p, q, exponent)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

p = 64123, q = 50957, exponent = 136407

    def calculate_keys_custom_exponent(p: int, q: int, exponent: int
        ) ->typing.Tuple[int, int]:
        """Calculates an encryption and a decryption key given p, q and an exponent,
        and returns them as a tuple (e, d)

        :param p: the first large prime
        :param q: the second large prime
        :param exponent: the exponent for the key; only change this if you know
            what you're doing, as the exponent influences how difficult your
            private key can be cracked. A very common choice for e is 65537.
        :type exponent: int

        """
        phi_n = (p - 1) * (q - 1)

        try:
            d = rsa.common.inverse(exponent, phi_n)
        except ValueError:
>           raise ValueError("e and phi_n are not relatively prime")
E           ValueError: e and phi_n are not relatively prime

rsa/key.py:561: ValueError

test_load_save_keys.py::DerTest::test_load_malformed_private_key

test_load_save_keys.py::DerTest::test_load_malformed_private_key
self = 
der_decode = 

    @mock.patch("pyasn1.codec.der.decoder.decode")
    def test_load_malformed_private_key(self, der_decode):
        """Test loading malformed private DER keys."""

        # Decode returns an invalid exp2 value.
        der_decode.return_value = (
            [0, 3727264081, 65537, 3349121513, 65063, 57287, 55063, 0, 50797],
            0,
        )

        with warnings.catch_warnings(record=True) as w:
            # Always print warnings
            warnings.simplefilter("always")

            # Load 3 keys
            for _ in range(3):
                key = rsa.key.PrivateKey.load_pkcs1(PRIVATE_DER, "DER")

            # Check that 3 warnings were generated.
>           self.assertEqual(3, len(w))
E           AssertionError: 3 != 0

tests/test_load_save_keys.py:122: AssertionError

test_load_save_keys.py::DerTest::test_load_private_key

test_load_save_keys.py::DerTest::test_load_private_key
self = 

    def test_load_private_key(self):
        """Test loading private DER keys."""

        key = rsa.key.PrivateKey.load_pkcs1(PRIVATE_DER, "DER")
        expected = rsa.key.PrivateKey(3727264081, 65537, 3349121513, 65063, 57287)

>       self.assertEqual(expected, key)
E       AssertionError: PrivateKey(3727264081, 65537, 3349121513, 65063, 57287) != None

tests/test_load_save_keys.py:98: AssertionError

test_load_save_keys.py::DerTest::test_load_public_key

test_load_save_keys.py::DerTest::test_load_public_key
self = 

    def test_load_public_key(self):
        """Test loading public DER keys."""

        key = rsa.key.PublicKey.load_pkcs1(PUBLIC_DER, "DER")
        expected = rsa.key.PublicKey(3727264081, 65537)

>       self.assertEqual(expected, key)
E       AssertionError: PublicKey(3727264081, 65537) != None

tests/test_load_save_keys.py:148: AssertionError

test_load_save_keys.py::DerTest::test_save_private_key

test_load_save_keys.py::DerTest::test_save_private_key
self = 

    def test_save_private_key(self):
        """Test saving private DER keys."""

        key = rsa.key.PrivateKey(3727264081, 65537, 3349121513, 65063, 57287)
        der = key.save_pkcs1("DER")

>       self.assertIsInstance(der, bytes)
E       AssertionError: None is not an instance of 

tests/test_load_save_keys.py:139: AssertionError

test_load_save_keys.py::DerTest::test_save_public_key

test_load_save_keys.py::DerTest::test_save_public_key
self = 

    def test_save_public_key(self):
        """Test saving public DER keys."""

        key = rsa.key.PublicKey(3727264081, 65537)
        der = key.save_pkcs1("DER")

>       self.assertIsInstance(der, bytes)
E       AssertionError: None is not an instance of 

tests/test_load_save_keys.py:156: AssertionError

test_load_save_keys.py::PemTest::test_load_from_disk

test_load_save_keys.py::PemTest::test_load_from_disk
self = 

    def test_load_from_disk(self):
        """Test loading a PEM file from disk."""

        fname = os.path.join(os.path.dirname(__file__), "private.pem")
        with open(fname, mode="rb") as privatefile:
            keydata = privatefile.read()
        privkey = rsa.key.PrivateKey.load_pkcs1(keydata)

>       self.assertEqual(15945948582725241569, privkey.p)
E       AttributeError: 'NoneType' object has no attribute 'p'

tests/test_load_save_keys.py:208: AttributeError

test_load_save_keys.py::PemTest::test_load_private_key

test_load_save_keys.py::PemTest::test_load_private_key
self = 

    def test_load_private_key(self):
        """Test loading private PEM files."""

        key = rsa.key.PrivateKey.load_pkcs1(PRIVATE_PEM, "PEM")
        expected = rsa.key.PrivateKey(3727264081, 65537, 3349121513, 65063, 57287)

>       self.assertEqual(expected, key)
E       AssertionError: PrivateKey(3727264081, 65537, 3349121513, 65063, 57287) != None

tests/test_load_save_keys.py:169: AssertionError

test_load_save_keys.py::PemTest::test_load_public_key

test_load_save_keys.py::PemTest::test_load_public_key
self = 

    def test_load_public_key(self):
        """Test loading public PEM files."""

        key = rsa.key.PublicKey.load_pkcs1(PUBLIC_PEM, "PEM")
        expected = rsa.key.PublicKey(3727264081, 65537)

>       self.assertEqual(expected, key)
E       AssertionError: PublicKey(3727264081, 65537) != None

tests/test_load_save_keys.py:189: AssertionError

test_load_save_keys.py::PemTest::test_save_private_key

test_load_save_keys.py::PemTest::test_save_private_key
self = 

    def test_save_private_key(self):
        """Test saving private PEM files."""

        key = rsa.key.PrivateKey(3727264081, 65537, 3349121513, 65063, 57287)
        pem = key.save_pkcs1("PEM")

>       self.assertIsInstance(pem, bytes)
E       AssertionError: None is not an instance of 

tests/test_load_save_keys.py:180: AssertionError

test_load_save_keys.py::PemTest::test_save_public_key

test_load_save_keys.py::PemTest::test_save_public_key
self = 

    def test_save_public_key(self):
        """Test saving public PEM files."""

        key = rsa.key.PublicKey(3727264081, 65537)
        pem = key.save_pkcs1("PEM")

>       self.assertIsInstance(pem, bytes)
E       AssertionError: None is not an instance of 

tests/test_load_save_keys.py:197: AssertionError

test_mypy.py::MypyRunnerTest::test_run_mypy

test_mypy.py::MypyRunnerTest::test_run_mypy
self = 

    def test_run_mypy(self):
        proj_root = pathlib.Path(__file__).parent.parent
        args = [
            "--incremental",
            "--ignore-missing-imports",
            f"--python-version={sys.version_info.major}.{sys.version_info.minor}",
        ] + [str(proj_root / dirname) for dirname in test_modules]

        result = mypy.api.run(args)

        stdout, stderr, status = result

        messages = []
        if stderr:
            messages.append(stderr)
        if stdout:
            messages.append(stdout)
        if status:
            messages.append("Mypy failed with status %d" % status)
        if messages and not all("Success" in message for message in messages):
>           self.fail("\n".join(["Mypy errors:"] + messages))
E           AssertionError: Mypy errors:
E           setup.cfg: [mypy]: python_version: Python 3.7 is not supported (must be 3.8 or higher)
E           
E           rsa/pem.py:52: error: If x = b'abc' then "%s" % x produces "b'abc'", not "abc". If this is desired behavior use "%r" % x. Otherwise, decode the bytes  [str-bytes-safe]
E           rsa/key.py:245: error: Missing return statement  [empty-body]
E           rsa/key.py:266: error: Missing return statement  [empty-body]
E           rsa/key.py:275: error: Missing return statement  [empty-body]
E           rsa/key.py:287: error: Missing return statement  [empty-body]
E           rsa/key.py:296: error: Missing return statement  [empty-body]
E           rsa/key.py:313: error: Missing return statement  [empty-body]
E           rsa/key.py:420: error: Missing return statement  [empty-body]
E           rsa/key.py:442: error: Missing return statement  [empty-body]
E           rsa/key.py:451: error: Missing return statement  [empty-body]
E           rsa/key.py:464: error: Missing return statement  [empty-body]
E           rsa/key.py:631: error: Module has no attribute "compute_keys"  [attr-defined]
E           rsa/pkcs1.py:88: error: Name "random" is not defined  [name-defined]
E           rsa/pkcs1.py:335: error: Missing return statement  [empty-body]
E           rsa/pkcs1.py:346: error: Missing return statement  [empty-body]
E           rsa/pkcs1.py:360: error: Missing return statement  [empty-body]
E           rsa/cli.py:159: error: Argument 2 to "encrypt" has incompatible type "AbstractKey"; expected "PublicKey"  [arg-type]
E           rsa/cli.py:171: error: Incompatible types in assignment (expression has type "type[PrivateKey]", base class "CryptoOperation" defined the type as "type[PublicKey]")  [assignment]
E           rsa/cli.py:176: error: Argument 2 to "decrypt" has incompatible type "AbstractKey"; expected "PrivateKey"  [arg-type]
E           rsa/cli.py:189: error: Incompatible types in assignment (expression has type "type[PrivateKey]", base class "CryptoOperation" defined the type as "type[PublicKey]")  [assignment]
E           rsa/cli.py:202: error: Argument 2 to "sign" has incompatible type "AbstractKey"; expected "PrivateKey"  [arg-type]
E           rsa/cli.py:227: error: Argument 3 to "verify" has incompatible type "AbstractKey"; expected "PublicKey"  [arg-type]
E           Found 22 errors in 4 files (checked 28 source files)
E           
E           Mypy failed with status 1

tests/test_mypy.py:31: AssertionError

test_parallel.py::ParallelTest::test_parallel_primegen

test_parallel.py::ParallelTest::test_parallel_primegen
self = 

    def test_parallel_primegen(self):
>       p = rsa.parallel.getprime(1024, 3)

tests/test_parallel.py:14: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
rsa/parallel.py:50: in getprime
    result = pipes[0].recv()
/root/.local/share/uv/python/cpython-3.12.6-linux-x86_64-gnu/lib/python3.12/multiprocessing/connection.py:250: in recv
    buf = self._recv_bytes()
/root/.local/share/uv/python/cpython-3.12.6-linux-x86_64-gnu/lib/python3.12/multiprocessing/connection.py:430: in _recv_bytes
    buf = self._recv(4)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = 
size = 4, read = 

    def _recv(self, size, read=_read):
        buf = io.BytesIO()
        handle = self._handle
        remaining = size
        while remaining > 0:
            chunk = read(handle, remaining)
            n = len(chunk)
            if n == 0:
                if remaining == size:
>                   raise EOFError
E                   EOFError

/root/.local/share/uv/python/cpython-3.12.6-linux-x86_64-gnu/lib/python3.12/multiprocessing/connection.py:399: EOFError

test_pem.py::TestBytesAndStrings::test_bytes_private

test_pem.py::TestBytesAndStrings::test_bytes_private
self = 

    def test_bytes_private(self):
        key = rsa.key.PrivateKey.load_pkcs1(private_key_pem.encode("ascii"))
>       self.assertEqual(prime1, key.p)
E       AttributeError: 'NoneType' object has no attribute 'p'

tests/test_pem.py:71: AttributeError

test_pem.py::TestBytesAndStrings::test_bytes_public

test_pem.py::TestBytesAndStrings::test_bytes_public
self = 

    def test_bytes_public(self):
        key = rsa.key.PublicKey.load_pkcs1_openssl_pem(public_key_pem.encode("ascii"))
>       self.assertEqual(prime1 * prime2, key.n)
E       AttributeError: 'NoneType' object has no attribute 'n'

tests/test_pem.py:63: AttributeError

test_pem.py::TestBytesAndStrings::test_unicode_private

test_pem.py::TestBytesAndStrings::test_unicode_private
self = 

    def test_unicode_private(self):
        key = rsa.key.PrivateKey.load_pkcs1(private_key_pem)
>       self.assertEqual(prime1 * prime2, key.n)
E       AttributeError: 'NoneType' object has no attribute 'n'

tests/test_pem.py:67: AttributeError

test_pem.py::TestBytesAndStrings::test_unicode_public

test_pem.py::TestBytesAndStrings::test_unicode_public
self = 

    def test_unicode_public(self):
        key = rsa.key.PublicKey.load_pkcs1_openssl_pem(public_key_pem)
>       self.assertEqual(prime1 * prime2, key.n)
E       AttributeError: 'NoneType' object has no attribute 'n'

tests/test_pem.py:59: AttributeError

test_pem.py::TestByteOutput::test_bytes_private

test_pem.py::TestByteOutput::test_bytes_private
self = 

    def test_bytes_private(self):
        key = rsa.key.PrivateKey.load_pkcs1(private_key_pem)
>       self.assertIsInstance(key.save_pkcs1(format="DER"), bytes)
E       AttributeError: 'NoneType' object has no attribute 'save_pkcs1'

tests/test_pem.py:85: AttributeError

test_pem.py::TestByteOutput::test_bytes_public

test_pem.py::TestByteOutput::test_bytes_public
self = 

    def test_bytes_public(self):
        key = rsa.key.PublicKey.load_pkcs1_openssl_pem(public_key_pem)
>       self.assertIsInstance(key.save_pkcs1(format="DER"), bytes)
E       AttributeError: 'NoneType' object has no attribute 'save_pkcs1'

tests/test_pem.py:80: AttributeError

test_pem.py::TestByteInput::test_bytes_private

test_pem.py::TestByteInput::test_bytes_private
self = 

    def test_bytes_private(self):
        key = rsa.key.PrivateKey.load_pkcs1(private_key_pem.encode("ascii"))
>       self.assertIsInstance(key.save_pkcs1(format="DER"), bytes)
E       AttributeError: 'NoneType' object has no attribute 'save_pkcs1'

tests/test_pem.py:99: AttributeError

test_pem.py::TestByteInput::test_bytes_public

test_pem.py::TestByteInput::test_bytes_public
self = 

    def test_bytes_public(self):
        key = rsa.key.PublicKey.load_pkcs1_openssl_pem(public_key_pem.encode("ascii"))
>       self.assertIsInstance(key.save_pkcs1(format="DER"), bytes)
E       AttributeError: 'NoneType' object has no attribute 'save_pkcs1'

tests/test_pem.py:94: AttributeError

test_pkcs1.py::BinaryTest::test_decoding_failure

test_pkcs1.py::BinaryTest::test_decoding_failure
self = 

    def setUp(self):
>       (self.pub, self.priv) = rsa.newkeys(256)

tests/test_pkcs1.py:27: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
rsa/key.py:634: in newkeys
    (p, q, e, d) = gen_keys(nbits, accurate=accurate, exponent=exponent,
rsa/key.py:597: in gen_keys
    p, q = find_p_q(nbits // 2, getprime_func, accurate)
rsa/key.py:512: in find_p_q
    p = getprime_func(pbits)
rsa/prime.py:127: in getprime
    if is_prime(integer):
rsa/prime.py:102: in is_prime
    return miller_rabin_primality_testing(number, get_primality_testing_rounds(number))
rsa/prime.py:72: in miller_rabin_primality_testing
    a = rsa.randnum.read_random_odd_int(n - 3) + 2
rsa/randnum.py:37: in read_random_odd_int
    return read_random_int(nbits) | 1
rsa/randnum.py:28: in read_random_int
    return transform.bytes2int(read_random_bits(nbits))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

nbits = 217543575880766607873451677415243526716

    def read_random_bits(nbits: int) ->bytes:
        """Reads 'nbits' random bits.

        If nbits isn't a whole number of bytes, an extra byte will be appended with
        only the lower bits set.
        """
        nbytes, rbits = divmod(nbits, 8)

        # Get the specified number of bytes
>       bytes_data = os.urandom(nbytes)
E       OverflowError: Python int too large to convert to C ssize_t

rsa/randnum.py:16: OverflowError

test_pkcs1.py::BinaryTest::test_enc_dec

test_pkcs1.py::BinaryTest::test_enc_dec
self = 

    def setUp(self):
>       (self.pub, self.priv) = rsa.newkeys(256)

tests/test_pkcs1.py:27: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
rsa/key.py:634: in newkeys
    (p, q, e, d) = gen_keys(nbits, accurate=accurate, exponent=exponent,
rsa/key.py:597: in gen_keys
    p, q = find_p_q(nbits // 2, getprime_func, accurate)
rsa/key.py:512: in find_p_q
    p = getprime_func(pbits)
rsa/prime.py:127: in getprime
    if is_prime(integer):
rsa/prime.py:102: in is_prime
    return miller_rabin_primality_testing(number, get_primality_testing_rounds(number))
rsa/prime.py:72: in miller_rabin_primality_testing
    a = rsa.randnum.read_random_odd_int(n - 3) + 2
rsa/randnum.py:37: in read_random_odd_int
    return read_random_int(nbits) | 1
rsa/randnum.py:28: in read_random_int
    return transform.bytes2int(read_random_bits(nbits))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

nbits = 297471905199644666354355871622901925482

    def read_random_bits(nbits: int) ->bytes:
        """Reads 'nbits' random bits.

        If nbits isn't a whole number of bytes, an extra byte will be appended with
        only the lower bits set.
        """
        nbytes, rbits = divmod(nbits, 8)

        # Get the specified number of bytes
>       bytes_data = os.urandom(nbytes)
E       OverflowError: Python int too large to convert to C ssize_t

rsa/randnum.py:16: OverflowError

test_pkcs1.py::BinaryTest::test_randomness

test_pkcs1.py::BinaryTest::test_randomness
self = 

    def setUp(self):
>       (self.pub, self.priv) = rsa.newkeys(256)

tests/test_pkcs1.py:27: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
rsa/key.py:634: in newkeys
    (p, q, e, d) = gen_keys(nbits, accurate=accurate, exponent=exponent,
rsa/key.py:597: in gen_keys
    p, q = find_p_q(nbits // 2, getprime_func, accurate)
rsa/key.py:512: in find_p_q
    p = getprime_func(pbits)
rsa/prime.py:127: in getprime
    if is_prime(integer):
rsa/prime.py:102: in is_prime
    return miller_rabin_primality_testing(number, get_primality_testing_rounds(number))
rsa/prime.py:72: in miller_rabin_primality_testing
    a = rsa.randnum.read_random_odd_int(n - 3) + 2
rsa/randnum.py:37: in read_random_odd_int
    return read_random_int(nbits) | 1
rsa/randnum.py:28: in read_random_int
    return transform.bytes2int(read_random_bits(nbits))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

nbits = 236249539998308572994955745299317853480

    def read_random_bits(nbits: int) ->bytes:
        """Reads 'nbits' random bits.

        If nbits isn't a whole number of bytes, an extra byte will be appended with
        only the lower bits set.
        """
        nbytes, rbits = divmod(nbits, 8)

        # Get the specified number of bytes
>       bytes_data = os.urandom(nbytes)
E       OverflowError: Python int too large to convert to C ssize_t

rsa/randnum.py:16: OverflowError

test_pkcs1.py::ExtraZeroesTest::test_append_zeroes

test_pkcs1.py::ExtraZeroesTest::test_append_zeroes
self = 

    def test_append_zeroes(self):
        cyphertext = self.cyphertext + bytes.fromhex("0000")
        with self.assertRaises(rsa.DecryptionError):
>           rsa.decrypt(cyphertext, self.private_key)

tests/test_pkcs1.py:90: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

    def decrypt(crypto: bytes, priv_key: key.PrivateKey) ->bytes:
        """Decrypts the given message using PKCS#1 v1.5

        The decryption is considered 'failed' when the resulting cleartext doesn't
        start with the bytes 00 02, or when the 00 byte between the padding and
        the message cannot be found.

        :param crypto: the crypto text as returned by :py:func:`rsa.encrypt`
        :param priv_key: the :py:class:`rsa.PrivateKey` to decrypt with.
        :raise DecryptionError: when the decryption fails. No details are given as
            to why the code thinks the decryption fails, as this would leak
            information about the private key.


        >>> import rsa
        >>> (pub_key, priv_key) = rsa.newkeys(256)

        It works with strings:

        >>> crypto = encrypt(b'hello', pub_key)
        >>> decrypt(crypto, priv_key)
        b'hello'

        And with binary data:

        >>> crypto = encrypt(b'\\x00\\x00\\x00\\x00\\x01', pub_key)
        >>> decrypt(crypto, priv_key)
        b'\\x00\\x00\\x00\\x00\\x01'

        Altering the encrypted information will *likely* cause a
        :py:class:`rsa.pkcs1.DecryptionError`. If you want to be *sure*, use
        :py:func:`rsa.sign`.


        .. warning::

            Never display the stack trace of a
            :py:class:`rsa.pkcs1.DecryptionError` exception. It shows where in the
            code the exception occurred, and thus leaks information about the key.
            It's only a tiny bit of information, but every bit makes cracking the
            keys easier.

        >>> crypto = encrypt(b'hello', pub_key)
        >>> crypto = crypto[0:5] + b'X' + crypto[6:] # change a byte
        >>> decrypt(crypto, priv_key)
        Traceback (most recent call last):
        ...
        rsa.pkcs1.DecryptionError: Decryption failed

        """
>       blocksize = common.byte_size(priv_key.n)
E       AttributeError: 'NoneType' object has no attribute 'n'

rsa/pkcs1.py:211: AttributeError

test_pkcs1.py::ExtraZeroesTest::test_prepend_zeroes

test_pkcs1.py::ExtraZeroesTest::test_prepend_zeroes
self = 

    def test_prepend_zeroes(self):
        cyphertext = bytes.fromhex("0000") + self.cyphertext
        with self.assertRaises(rsa.DecryptionError):
>           rsa.decrypt(cyphertext, self.private_key)

tests/test_pkcs1.py:85: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

    def decrypt(crypto: bytes, priv_key: key.PrivateKey) ->bytes:
        """Decrypts the given message using PKCS#1 v1.5

        The decryption is considered 'failed' when the resulting cleartext doesn't
        start with the bytes 00 02, or when the 00 byte between the padding and
        the message cannot be found.

        :param crypto: the crypto text as returned by :py:func:`rsa.encrypt`
        :param priv_key: the :py:class:`rsa.PrivateKey` to decrypt with.
        :raise DecryptionError: when the decryption fails. No details are given as
            to why the code thinks the decryption fails, as this would leak
            information about the private key.


        >>> import rsa
        >>> (pub_key, priv_key) = rsa.newkeys(256)

        It works with strings:

        >>> crypto = encrypt(b'hello', pub_key)
        >>> decrypt(crypto, priv_key)
        b'hello'

        And with binary data:

        >>> crypto = encrypt(b'\\x00\\x00\\x00\\x00\\x01', pub_key)
        >>> decrypt(crypto, priv_key)
        b'\\x00\\x00\\x00\\x00\\x01'

        Altering the encrypted information will *likely* cause a
        :py:class:`rsa.pkcs1.DecryptionError`. If you want to be *sure*, use
        :py:func:`rsa.sign`.


        .. warning::

            Never display the stack trace of a
            :py:class:`rsa.pkcs1.DecryptionError` exception. It shows where in the
            code the exception occurred, and thus leaks information about the key.
            It's only a tiny bit of information, but every bit makes cracking the
            keys easier.

        >>> crypto = encrypt(b'hello', pub_key)
        >>> crypto = crypto[0:5] + b'X' + crypto[6:] # change a byte
        >>> decrypt(crypto, priv_key)
        Traceback (most recent call last):
        ...
        rsa.pkcs1.DecryptionError: Decryption failed

        """
>       blocksize = common.byte_size(priv_key.n)
E       AttributeError: 'NoneType' object has no attribute 'n'

rsa/pkcs1.py:211: AttributeError

test_pkcs1.py::ExtraZeroesTest::test_unmodified

test_pkcs1.py::ExtraZeroesTest::test_unmodified
self = 

    def test_unmodified(self):
>       message = rsa.decrypt(self.cyphertext, self.private_key)

tests/test_pkcs1.py:79: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

crypto = b'E\x01\xb4\xd6i\xe0\x1b\x9e\xf2\xdc\x80\n\xa1\xb0mI\x19oZ\t\xfe\x8f\xbc\xd072<`\xea\xf0\'\xbf\xb9\x842\xbeNJ&\xc5g\xf...x86\x1e\x81\x02\x1be\n\x1d\xe5\x10\x02\xc3\x15\xf1\xe7\xc1-\xeb\xe4\xdc\xeb\xf7\x90\xca\xaaT\xa2\xf2k\x14\x9c\xf9\xe7}'
priv_key = None

    def decrypt(crypto: bytes, priv_key: key.PrivateKey) ->bytes:
        """Decrypts the given message using PKCS#1 v1.5

        The decryption is considered 'failed' when the resulting cleartext doesn't
        start with the bytes 00 02, or when the 00 byte between the padding and
        the message cannot be found.

        :param crypto: the crypto text as returned by :py:func:`rsa.encrypt`
        :param priv_key: the :py:class:`rsa.PrivateKey` to decrypt with.
        :raise DecryptionError: when the decryption fails. No details are given as
            to why the code thinks the decryption fails, as this would leak
            information about the private key.


        >>> import rsa
        >>> (pub_key, priv_key) = rsa.newkeys(256)

        It works with strings:

        >>> crypto = encrypt(b'hello', pub_key)
        >>> decrypt(crypto, priv_key)
        b'hello'

        And with binary data:

        >>> crypto = encrypt(b'\\x00\\x00\\x00\\x00\\x01', pub_key)
        >>> decrypt(crypto, priv_key)
        b'\\x00\\x00\\x00\\x00\\x01'

        Altering the encrypted information will *likely* cause a
        :py:class:`rsa.pkcs1.DecryptionError`. If you want to be *sure*, use
        :py:func:`rsa.sign`.


        .. warning::

            Never display the stack trace of a
            :py:class:`rsa.pkcs1.DecryptionError` exception. It shows where in the
            code the exception occurred, and thus leaks information about the key.
            It's only a tiny bit of information, but every bit makes cracking the
            keys easier.

        >>> crypto = encrypt(b'hello', pub_key)
        >>> crypto = crypto[0:5] + b'X' + crypto[6:] # change a byte
        >>> decrypt(crypto, priv_key)
        Traceback (most recent call last):
        ...
        rsa.pkcs1.DecryptionError: Decryption failed

        """
>       blocksize = common.byte_size(priv_key.n)
E       AttributeError: 'NoneType' object has no attribute 'n'

rsa/pkcs1.py:211: AttributeError

test_pkcs1.py::SignatureTest::test_alter_message

test_pkcs1.py::SignatureTest::test_alter_message
self = 

    def setUp(self):
>       (self.pub, self.priv) = rsa.newkeys(512)

tests/test_pkcs1.py:95: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
rsa/key.py:634: in newkeys
    (p, q, e, d) = gen_keys(nbits, accurate=accurate, exponent=exponent,
rsa/key.py:597: in gen_keys
    p, q = find_p_q(nbits // 2, getprime_func, accurate)
rsa/key.py:512: in find_p_q
    p = getprime_func(pbits)
rsa/prime.py:127: in getprime
    if is_prime(integer):
rsa/prime.py:102: in is_prime
    return miller_rabin_primality_testing(number, get_primality_testing_rounds(number))
rsa/prime.py:72: in miller_rabin_primality_testing
    a = rsa.randnum.read_random_odd_int(n - 3) + 2
rsa/randnum.py:37: in read_random_odd_int
    return read_random_int(nbits) | 1
rsa/randnum.py:28: in read_random_int
    return transform.bytes2int(read_random_bits(nbits))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

nbits = 602609714065794359...8821252561879435800

    def read_random_bits(nbits: int) ->bytes:
        """Reads 'nbits' random bits.

        If nbits isn't a whole number of bytes, an extra byte will be appended with
        only the lower bits set.
        """
        nbytes, rbits = divmod(nbits, 8)

        # Get the specified number of bytes
>       bytes_data = os.urandom(nbytes)
E       OverflowError: Python int too large to convert to C ssize_t

rsa/randnum.py:16: OverflowError

test_pkcs1.py::SignatureTest::test_apppend_zeroes

test_pkcs1.py::SignatureTest::test_apppend_zeroes
self = 

    def setUp(self):
>       (self.pub, self.priv) = rsa.newkeys(512)

tests/test_pkcs1.py:95: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
rsa/key.py:634: in newkeys
    (p, q, e, d) = gen_keys(nbits, accurate=accurate, exponent=exponent,
rsa/key.py:597: in gen_keys
    p, q = find_p_q(nbits // 2, getprime_func, accurate)
rsa/key.py:512: in find_p_q
    p = getprime_func(pbits)
rsa/prime.py:127: in getprime
    if is_prime(integer):
rsa/prime.py:102: in is_prime
    return miller_rabin_primality_testing(number, get_primality_testing_rounds(number))
rsa/prime.py:72: in miller_rabin_primality_testing
    a = rsa.randnum.read_random_odd_int(n - 3) + 2
rsa/randnum.py:37: in read_random_odd_int
    return read_random_int(nbits) | 1
rsa/randnum.py:28: in read_random_int
    return transform.bytes2int(read_random_bits(nbits))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

nbits = 106273639344971542...7556299210634644474

    def read_random_bits(nbits: int) ->bytes:
        """Reads 'nbits' random bits.

        If nbits isn't a whole number of bytes, an extra byte will be appended with
        only the lower bits set.
        """
        nbytes, rbits = divmod(nbits, 8)

        # Get the specified number of bytes
>       bytes_data = os.urandom(nbytes)
E       OverflowError: Python int too large to convert to C ssize_t

rsa/randnum.py:16: OverflowError

test_pkcs1.py::SignatureTest::test_find_signature_hash

test_pkcs1.py::SignatureTest::test_find_signature_hash
self = 

    def setUp(self):
>       (self.pub, self.priv) = rsa.newkeys(512)

tests/test_pkcs1.py:95: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
rsa/key.py:634: in newkeys
    (p, q, e, d) = gen_keys(nbits, accurate=accurate, exponent=exponent,
rsa/key.py:597: in gen_keys
    p, q = find_p_q(nbits // 2, getprime_func, accurate)
rsa/key.py:512: in find_p_q
    p = getprime_func(pbits)
rsa/prime.py:127: in getprime
    if is_prime(integer):
rsa/prime.py:102: in is_prime
    return miller_rabin_primality_testing(number, get_primality_testing_rounds(number))
rsa/prime.py:72: in miller_rabin_primality_testing
    a = rsa.randnum.read_random_odd_int(n - 3) + 2
rsa/randnum.py:37: in read_random_odd_int
    return read_random_int(nbits) | 1
rsa/randnum.py:28: in read_random_int
    return transform.bytes2int(read_random_bits(nbits))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

nbits = 111622925666369620...6170230004757105564

    def read_random_bits(nbits: int) ->bytes:
        """Reads 'nbits' random bits.

        If nbits isn't a whole number of bytes, an extra byte will be appended with
        only the lower bits set.
        """
        nbytes, rbits = divmod(nbits, 8)

        # Get the specified number of bytes
>       bytes_data = os.urandom(nbytes)
E       OverflowError: Python int too large to convert to C ssize_t

rsa/randnum.py:16: OverflowError

test_pkcs1.py::SignatureTest::test_hash_sign_verify

test_pkcs1.py::SignatureTest::test_hash_sign_verify
self = 

    def setUp(self):
>       (self.pub, self.priv) = rsa.newkeys(512)

tests/test_pkcs1.py:95: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
rsa/key.py:634: in newkeys
    (p, q, e, d) = gen_keys(nbits, accurate=accurate, exponent=exponent,
rsa/key.py:597: in gen_keys
    p, q = find_p_q(nbits // 2, getprime_func, accurate)
rsa/key.py:512: in find_p_q
    p = getprime_func(pbits)
rsa/prime.py:127: in getprime
    if is_prime(integer):
rsa/prime.py:102: in is_prime
    return miller_rabin_primality_testing(number, get_primality_testing_rounds(number))
rsa/prime.py:72: in miller_rabin_primality_testing
    a = rsa.randnum.read_random_odd_int(n - 3) + 2
rsa/randnum.py:37: in read_random_odd_int
    return read_random_int(nbits) | 1
rsa/randnum.py:28: in read_random_int
    return transform.bytes2int(read_random_bits(nbits))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

nbits = 102228403044058578...6394079414229567576

    def read_random_bits(nbits: int) ->bytes:
        """Reads 'nbits' random bits.

        If nbits isn't a whole number of bytes, an extra byte will be appended with
        only the lower bits set.
        """
        nbytes, rbits = divmod(nbits, 8)

        # Get the specified number of bytes
>       bytes_data = os.urandom(nbytes)
E       OverflowError: Python int too large to convert to C ssize_t

rsa/randnum.py:16: OverflowError

test_pkcs1.py::SignatureTest::test_multiple_signings

test_pkcs1.py::SignatureTest::test_multiple_signings
self = 

    def setUp(self):
>       (self.pub, self.priv) = rsa.newkeys(512)

tests/test_pkcs1.py:95: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
rsa/key.py:634: in newkeys
    (p, q, e, d) = gen_keys(nbits, accurate=accurate, exponent=exponent,
rsa/key.py:597: in gen_keys
    p, q = find_p_q(nbits // 2, getprime_func, accurate)
rsa/key.py:512: in find_p_q
    p = getprime_func(pbits)
rsa/prime.py:127: in getprime
    if is_prime(integer):
rsa/prime.py:102: in is_prime
    return miller_rabin_primality_testing(number, get_primality_testing_rounds(number))
rsa/prime.py:72: in miller_rabin_primality_testing
    a = rsa.randnum.read_random_odd_int(n - 3) + 2
rsa/randnum.py:37: in read_random_odd_int
    return read_random_int(nbits) | 1
rsa/randnum.py:28: in read_random_int
    return transform.bytes2int(read_random_bits(nbits))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

nbits = 706939442664155983...4572200987700759170

    def read_random_bits(nbits: int) ->bytes:
        """Reads 'nbits' random bits.

        If nbits isn't a whole number of bytes, an extra byte will be appended with
        only the lower bits set.
        """
        nbytes, rbits = divmod(nbits, 8)

        # Get the specified number of bytes
>       bytes_data = os.urandom(nbytes)
E       OverflowError: Python int too large to convert to C ssize_t

rsa/randnum.py:16: OverflowError

test_pkcs1.py::SignatureTest::test_prepend_zeroes

test_pkcs1.py::SignatureTest::test_prepend_zeroes
self = 

    def setUp(self):
>       (self.pub, self.priv) = rsa.newkeys(512)

tests/test_pkcs1.py:95: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
rsa/key.py:634: in newkeys
    (p, q, e, d) = gen_keys(nbits, accurate=accurate, exponent=exponent,
rsa/key.py:597: in gen_keys
    p, q = find_p_q(nbits // 2, getprime_func, accurate)
rsa/key.py:512: in find_p_q
    p = getprime_func(pbits)
rsa/prime.py:127: in getprime
    if is_prime(integer):
rsa/prime.py:102: in is_prime
    return miller_rabin_primality_testing(number, get_primality_testing_rounds(number))
rsa/prime.py:72: in miller_rabin_primality_testing
    a = rsa.randnum.read_random_odd_int(n - 3) + 2
rsa/randnum.py:37: in read_random_odd_int
    return read_random_int(nbits) | 1
rsa/randnum.py:28: in read_random_int
    return transform.bytes2int(read_random_bits(nbits))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

nbits = 953503298775686331...9172306128720741954

    def read_random_bits(nbits: int) ->bytes:
        """Reads 'nbits' random bits.

        If nbits isn't a whole number of bytes, an extra byte will be appended with
        only the lower bits set.
        """
        nbytes, rbits = divmod(nbits, 8)

        # Get the specified number of bytes
>       bytes_data = os.urandom(nbytes)
E       OverflowError: Python int too large to convert to C ssize_t

rsa/randnum.py:16: OverflowError

test_pkcs1.py::SignatureTest::test_sign_different_key

test_pkcs1.py::SignatureTest::test_sign_different_key
self = 

    def setUp(self):
>       (self.pub, self.priv) = rsa.newkeys(512)

tests/test_pkcs1.py:95: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
rsa/key.py:634: in newkeys
    (p, q, e, d) = gen_keys(nbits, accurate=accurate, exponent=exponent,
rsa/key.py:597: in gen_keys
    p, q = find_p_q(nbits // 2, getprime_func, accurate)
rsa/key.py:512: in find_p_q
    p = getprime_func(pbits)
rsa/prime.py:127: in getprime
    if is_prime(integer):
rsa/prime.py:102: in is_prime
    return miller_rabin_primality_testing(number, get_primality_testing_rounds(number))
rsa/prime.py:72: in miller_rabin_primality_testing
    a = rsa.randnum.read_random_odd_int(n - 3) + 2
rsa/randnum.py:37: in read_random_odd_int
    return read_random_int(nbits) | 1
rsa/randnum.py:28: in read_random_int
    return transform.bytes2int(read_random_bits(nbits))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

nbits = 828392384400113353...9220164863506751906

    def read_random_bits(nbits: int) ->bytes:
        """Reads 'nbits' random bits.

        If nbits isn't a whole number of bytes, an extra byte will be appended with
        only the lower bits set.
        """
        nbytes, rbits = divmod(nbits, 8)

        # Get the specified number of bytes
>       bytes_data = os.urandom(nbytes)
E       OverflowError: Python int too large to convert to C ssize_t

rsa/randnum.py:16: OverflowError

test_pkcs1.py::SignatureTest::test_sign_verify

test_pkcs1.py::SignatureTest::test_sign_verify
self = 

    def setUp(self):
>       (self.pub, self.priv) = rsa.newkeys(512)

tests/test_pkcs1.py:95: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
rsa/key.py:634: in newkeys
    (p, q, e, d) = gen_keys(nbits, accurate=accurate, exponent=exponent,
rsa/key.py:597: in gen_keys
    p, q = find_p_q(nbits // 2, getprime_func, accurate)
rsa/key.py:512: in find_p_q
    p = getprime_func(pbits)
rsa/prime.py:127: in getprime
    if is_prime(integer):
rsa/prime.py:102: in is_prime
    return miller_rabin_primality_testing(number, get_primality_testing_rounds(number))
rsa/prime.py:72: in miller_rabin_primality_testing
    a = rsa.randnum.read_random_odd_int(n - 3) + 2
rsa/randnum.py:37: in read_random_odd_int
    return read_random_int(nbits) | 1
rsa/randnum.py:28: in read_random_int
    return transform.bytes2int(read_random_bits(nbits))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

nbits = 811706796240895138...1376114899214899928

    def read_random_bits(nbits: int) ->bytes:
        """Reads 'nbits' random bits.

        If nbits isn't a whole number of bytes, an extra byte will be appended with
        only the lower bits set.
        """
        nbytes, rbits = divmod(nbits, 8)

        # Get the specified number of bytes
>       bytes_data = os.urandom(nbytes)
E       OverflowError: Python int too large to convert to C ssize_t

rsa/randnum.py:16: OverflowError

test_pkcs1.py::SignatureTest::test_sign_verify_sha3

test_pkcs1.py::SignatureTest::test_sign_verify_sha3
self = 

    def setUp(self):
>       (self.pub, self.priv) = rsa.newkeys(512)

tests/test_pkcs1.py:95: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
rsa/key.py:634: in newkeys
    (p, q, e, d) = gen_keys(nbits, accurate=accurate, exponent=exponent,
rsa/key.py:597: in gen_keys
    p, q = find_p_q(nbits // 2, getprime_func, accurate)
rsa/key.py:512: in find_p_q
    p = getprime_func(pbits)
rsa/prime.py:127: in getprime
    if is_prime(integer):
rsa/prime.py:102: in is_prime
    return miller_rabin_primality_testing(number, get_primality_testing_rounds(number))
rsa/prime.py:72: in miller_rabin_primality_testing
    a = rsa.randnum.read_random_odd_int(n - 3) + 2
rsa/randnum.py:37: in read_random_odd_int
    return read_random_int(nbits) | 1
rsa/randnum.py:28: in read_random_int
    return transform.bytes2int(read_random_bits(nbits))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

nbits = 104228538748960789...9812861586565040298

    def read_random_bits(nbits: int) ->bytes:
        """Reads 'nbits' random bits.

        If nbits isn't a whole number of bytes, an extra byte will be appended with
        only the lower bits set.
        """
        nbytes, rbits = divmod(nbits, 8)

        # Get the specified number of bytes
>       bytes_data = os.urandom(nbytes)
E       OverflowError: Python int too large to convert to C ssize_t

rsa/randnum.py:16: OverflowError

test_pkcs1.py::SignatureTest::test_split_hash_sign

test_pkcs1.py::SignatureTest::test_split_hash_sign
self = 

    def setUp(self):
>       (self.pub, self.priv) = rsa.newkeys(512)

tests/test_pkcs1.py:95: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
rsa/key.py:634: in newkeys
    (p, q, e, d) = gen_keys(nbits, accurate=accurate, exponent=exponent,
rsa/key.py:597: in gen_keys
    p, q = find_p_q(nbits // 2, getprime_func, accurate)
rsa/key.py:512: in find_p_q
    p = getprime_func(pbits)
rsa/prime.py:127: in getprime
    if is_prime(integer):
rsa/prime.py:102: in is_prime
    return miller_rabin_primality_testing(number, get_primality_testing_rounds(number))
rsa/prime.py:72: in miller_rabin_primality_testing
    a = rsa.randnum.read_random_odd_int(n - 3) + 2
rsa/randnum.py:37: in read_random_odd_int
    return read_random_int(nbits) | 1
rsa/randnum.py:28: in read_random_int
    return transform.bytes2int(read_random_bits(nbits))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

nbits = 777828470107338812...4355753241106016688

    def read_random_bits(nbits: int) ->bytes:
        """Reads 'nbits' random bits.

        If nbits isn't a whole number of bytes, an extra byte will be appended with
        only the lower bits set.
        """
        nbytes, rbits = divmod(nbits, 8)

        # Get the specified number of bytes
>       bytes_data = os.urandom(nbytes)
E       OverflowError: Python int too large to convert to C ssize_t

rsa/randnum.py:16: OverflowError

test_pkcs1.py::PaddingSizeTest::test_too_little_padding

test_pkcs1.py::PaddingSizeTest::test_too_little_padding
self = 

        def test_too_little_padding(self):
            """Padding less than 8 bytes should be rejected."""

            # Construct key that will be small enough to need only 7 bytes of padding.
            # This key is 168 bit long, and was generated with rsa.newkeys(nbits=168).
            self.private_key = rsa.PrivateKey.load_pkcs1(
                b"""
    -----BEGIN RSA PRIVATE KEY-----
    MHkCAQACFgCIGbbNSkIRLtprxka9NgOf5UxgxCMCAwEAAQIVQqymO0gHubdEVS68
    CdCiWmOJxVfRAgwBQM+e1JJwMKmxSF0CCmya6CFxO8Evdn8CDACMM3AlVC4FhlN8
    3QIKC9cjoam/swMirwIMAR7Br9tdouoH7jAE
    -----END RSA PRIVATE KEY-----
            """
            )
>           self.public_key = rsa.PublicKey(n=self.private_key.n, e=self.private_key.e)
E           AttributeError: 'NoneType' object has no attribute 'n'

tests/test_pkcs1.py:201: AttributeError

test_prime.py::PrimeTest::test_is_prime

test_prime.py::PrimeTest::test_is_prime
self = 

    def test_is_prime(self):
        """Test some common primes."""

        # Test some trivial numbers
        self.assertFalse(rsa.prime.is_prime(-1))
        self.assertFalse(rsa.prime.is_prime(0))
        self.assertFalse(rsa.prime.is_prime(1))
        self.assertTrue(rsa.prime.is_prime(2))
        self.assertFalse(rsa.prime.is_prime(42))
        self.assertTrue(rsa.prime.is_prime(41))

        # Test some slightly larger numbers
>       self.assertEqual(
            [907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997],
            [x for x in range(901, 1000) if rsa.prime.is_prime(x)],
        )
E       AssertionError: Lists differ: [907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997] != [907, 911, 919, 929, 937, 941, 947, 967, 971, 983, 991, 997]
E       
E       First differing element 7:
E       953
E       967
E       
E       First list contains 2 additional elements.
E       First extra element 12:
E       991
E       
E       - [907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997]
E       ?                                     -----          -----
E       
E       + [907, 911, 919, 929, 937, 941, 947, 967, 971, 983, 991, 997]

tests/test_prime.py:36: AssertionError

test_prime.py::PrimeTest::test_mersenne_primes

test_prime.py::PrimeTest::test_mersenne_primes
self = 

    def test_mersenne_primes(self):
        """Tests first known Mersenne primes.

        Mersenne primes are prime numbers that can be written in the form
        `Mn = 2**n - 1` for some integer `n`. For the list of known Mersenne
        primes, see:
        https://en.wikipedia.org/wiki/Mersenne_prime#List_of_known_Mersenne_primes
        """

        # List of known Mersenne exponents.
        known_mersenne_exponents = [
            2,
            3,
            5,
            7,
            13,
            17,
            19,
            31,
            61,
            89,
            107,
            127,
            521,
            607,
            1279,
            2203,
            2281,
            4423,
        ]

        # Test Mersenne primes.
        for exp in known_mersenne_exponents:
>           self.assertTrue(rsa.prime.is_prime(2 ** exp - 1))
E           AssertionError: False is not true

tests/test_prime.py:119: AssertionError

test_prime.py::PrimeTest::test_miller_rabin_primality_testing

test_prime.py::PrimeTest::test_miller_rabin_primality_testing
self = 

    def test_miller_rabin_primality_testing(self):
        """Uses monkeypatching to ensure certain random numbers.

        This allows us to predict/control the code path.
        """

        randints = []

        def fake_randint(maxvalue):
            return randints.pop(0)

        orig_randint = rsa.randnum.randint
        rsa.randnum.randint = fake_randint
        try:
            # 'n is composite'
            randints.append(2630484832)  # causes the 'n is composite' case with n=3784949785
            self.assertEqual(False, rsa.prime.miller_rabin_primality_testing(2787998641, 7))
>           self.assertEqual([], randints)
E           AssertionError: Lists differ: [] != [2630484832]
E           
E           Second list contains 1 additional elements.
E           First extra element 0:
E           2630484832
E           
E           - []
E           + [2630484832]

tests/test_prime.py:62: AssertionError

test_strings.py::StringTest::test_enc_dec

test_strings.py::StringTest::test_enc_dec
self = 

    def setUp(self):
>       (self.pub, self.priv) = rsa.newkeys(384)

tests/test_strings.py:28: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
rsa/key.py:634: in newkeys
    (p, q, e, d) = gen_keys(nbits, accurate=accurate, exponent=exponent,
rsa/key.py:597: in gen_keys
    p, q = find_p_q(nbits // 2, getprime_func, accurate)
rsa/key.py:512: in find_p_q
    p = getprime_func(pbits)
rsa/prime.py:127: in getprime
    if is_prime(integer):
rsa/prime.py:102: in is_prime
    return miller_rabin_primality_testing(number, get_primality_testing_rounds(number))
rsa/prime.py:72: in miller_rabin_primality_testing
    a = rsa.randnum.read_random_odd_int(n - 3) + 2
rsa/randnum.py:37: in read_random_odd_int
    return read_random_int(nbits) | 1
rsa/randnum.py:28: in read_random_int
    return transform.bytes2int(read_random_bits(nbits))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

nbits = 428123020015116196...8296057054154531034

    def read_random_bits(nbits: int) ->bytes:
        """Reads 'nbits' random bits.

        If nbits isn't a whole number of bytes, an extra byte will be appended with
        only the lower bits set.
        """
        nbytes, rbits = divmod(nbits, 8)

        # Get the specified number of bytes
>       bytes_data = os.urandom(nbytes)
E       OverflowError: Python int too large to convert to C ssize_t

rsa/randnum.py:16: OverflowError

Patch diff

diff --git a/rsa/cli.py b/rsa/cli.py
index 4449a1f..894c8fb 100644
--- a/rsa/cli.py
+++ b/rsa/cli.py
@@ -15,7 +15,36 @@ Indexable = typing.Union[typing.Tuple, typing.List[str]]

 def keygen() ->None:
     """Key generator."""
-    pass
+    parser = optparse.OptionParser(usage='usage: %prog [options]',
+        description='Generates a new RSA key pair and saves them into two files')
+    parser.add_option('--pubout', type='string',
+        help='Output filename for the public key. The public key is saved in PEM format')
+    parser.add_option('--privout', type='string',
+        help='Output filename for the private key. The private key is saved in PEM format')
+    parser.add_option('-s', '--size', type='int', default=2048,
+        help='Key size in bits. Default: %default bits')
+    cli, cli_args = parser.parse_args()
+
+    if len(cli_args) > 0:
+        parser.print_help()
+        sys.exit(1)
+
+    if not (cli.pubout and cli.privout):
+        parser.print_help()
+        sys.exit(1)
+
+    print('Generating %i-bit key' % cli.size, file=sys.stderr)
+    pub_key, priv_key = rsa.newkeys(cli.size)
+
+    print('Writing public key to %s' % cli.pubout, file=sys.stderr)
+    with open(cli.pubout, 'wb') as f:
+        f.write(pub_key.save_pkcs1('PEM'))
+
+    print('Writing private key to %s' % cli.privout, file=sys.stderr)
+    with open(cli.privout, 'wb') as f:
+        f.write(priv_key.save_pkcs1('PEM'))
+
+    print('Done.')


 class CryptoOperation(metaclass=abc.ABCMeta):
@@ -67,19 +96,51 @@ class CryptoOperation(metaclass=abc.ABCMeta):

         :returns: (cli_opts, cli_args)
         """
-        pass
+        parser = optparse.OptionParser(usage=self.usage, description=self.description)
+
+        parser.add_option('-i', '--input', dest='input',
+                          help=self.input_help)
+        if self.has_output:
+            parser.add_option('-o', '--output', dest='output',
+                              help=self.output_help)
+
+        parser.add_option('--keyform', dest='keyform',
+                          help='Key format of the %s key - default PEM' % self.keyname,
+                          choices=('PEM', 'DER'), default='PEM')
+
+        (cli, cli_args) = parser.parse_args()
+
+        if len(cli_args) != self.expected_cli_args:
+            parser.print_help()
+            sys.exit(1)
+
+        return cli, cli_args

     def read_key(self, filename: str, keyform: str) ->rsa.key.AbstractKey:
         """Reads a public or private key."""
-        pass
+        with open(filename, 'rb') as keyfile:
+            keydata = keyfile.read()
+        
+        if keyform == 'DER':
+            return self.key_class.load_pkcs1(keydata, format='DER')
+        else:
+            return self.key_class.load_pkcs1(keydata, format='PEM')

     def read_infile(self, inname: str) ->bytes:
         """Read the input file"""
-        pass
+        if inname:
+            with open(inname, 'rb') as infile:
+                return infile.read()
+        else:
+            return sys.stdin.buffer.read()

     def write_outfile(self, outdata: bytes, outname: str) ->None:
         """Write the output file"""
-        pass
+        if outname:
+            with open(outname, 'wb') as outfile:
+                outfile.write(outdata)
+        else:
+            sys.stdout.buffer.write(outdata)


 class EncryptOperation(CryptoOperation):
@@ -95,7 +156,7 @@ class EncryptOperation(CryptoOperation):
     def perform_operation(self, indata: bytes, pub_key: rsa.key.AbstractKey,
         cli_args: Indexable=()) ->bytes:
         """Encrypts files."""
-        pass
+        return rsa.encrypt(indata, pub_key)


 class DecryptOperation(CryptoOperation):
@@ -112,7 +173,7 @@ class DecryptOperation(CryptoOperation):
     def perform_operation(self, indata: bytes, priv_key: rsa.key.
         AbstractKey, cli_args: Indexable=()) ->bytes:
         """Decrypts files."""
-        pass
+        return rsa.decrypt(indata, priv_key)


 class SignOperation(CryptoOperation):
@@ -134,7 +195,11 @@ class SignOperation(CryptoOperation):
     def perform_operation(self, indata: bytes, priv_key: rsa.key.
         AbstractKey, cli_args: Indexable) ->bytes:
         """Signs files."""
-        pass
+        hash_method = cli_args[1]
+        if hash_method not in HASH_METHODS:
+            raise ValueError('Invalid hash method, choose one of %s' % 
+                             ', '.join(HASH_METHODS))
+        return rsa.sign(indata, priv_key, hash_method)


 class VerifyOperation(CryptoOperation):
@@ -154,7 +219,16 @@ class VerifyOperation(CryptoOperation):
     def perform_operation(self, indata: bytes, pub_key: rsa.key.AbstractKey,
         cli_args: Indexable) ->None:
         """Verifies files."""
-        pass
+        signature_file = cli_args[1]
+        with open(signature_file, 'rb') as sigfile:
+            signature = sigfile.read()
+        
+        try:
+            rsa.verify(indata, signature, pub_key)
+            print('Verification OK', file=sys.stderr)
+        except rsa.VerificationError:
+            print('Verification failed.', file=sys.stderr)
+            sys.exit(1)


 encrypt = EncryptOperation()
diff --git a/rsa/common.py b/rsa/common.py
index 2f4bc71..8e0dde4 100644
--- a/rsa/common.py
+++ b/rsa/common.py
@@ -33,7 +33,9 @@ def bit_size(num: int) ->int:
     :returns:
         Returns the number of bits in the integer.
     """
-    pass
+    if num == 0:
+        return 0
+    return len(bin(abs(num))) - 2


 def byte_size(number: int) ->int:
@@ -56,7 +58,7 @@ def byte_size(number: int) ->int:
     :returns:
         The number of bytes required to hold a specific long number.
     """
-    pass
+    return (bit_size(number) + 7) // 8


 def ceil_div(num: int, div: int) ->int:
@@ -77,12 +79,19 @@ def ceil_div(num: int, div: int) ->int:

     :return: Rounded up result of the division between the parameters.
     """
-    pass
+    return -(-num // div)


 def extended_gcd(a: int, b: int) ->typing.Tuple[int, int, int]:
     """Returns a tuple (r, i, j) such that r = gcd(a, b) = ia + jb"""
-    pass
+    x, y = 0, 1
+    lx, ly = 1, 0
+    while b:
+        q = a // b
+        a, b = b, a % b
+        x, lx = lx - q * x, x
+        y, ly = ly - q * y, y
+    return a, lx, ly


 def inverse(x: int, n: int) ->int:
@@ -93,7 +102,10 @@ def inverse(x: int, n: int) ->int:
     >>> (inverse(143, 4) * 143) % 4
     1
     """
-    pass
+    gcd, a, _ = extended_gcd(x, n)
+    if gcd != 1:
+        raise NotRelativePrimeError(x, n, gcd)
+    return a % n


 def crt(a_values: typing.Iterable[int], modulo_values: typing.Iterable[int]
@@ -116,7 +128,14 @@ def crt(a_values: typing.Iterable[int], modulo_values: typing.Iterable[int]
     >>> crt([2, 3, 0], [7, 11, 15])
     135
     """
-    pass
+    total = 0
+    prod = 1
+    for m in modulo_values:
+        prod *= m
+    for a_i, m_i in zip(a_values, modulo_values):
+        p = prod // m_i
+        total += a_i * inverse(p, m_i) * p
+    return total % prod


 if __name__ == '__main__':
diff --git a/rsa/core.py b/rsa/core.py
index e7dba89..6b2975e 100644
--- a/rsa/core.py
+++ b/rsa/core.py
@@ -7,9 +7,9 @@ mathematically on integers.

 def encrypt_int(message: int, ekey: int, n: int) ->int:
     """Encrypts a message using encryption key 'ekey', working modulo n"""
-    pass
+    return pow(message, ekey, n)


 def decrypt_int(cyphertext: int, dkey: int, n: int) ->int:
     """Decrypts a cypher text using the decryption key 'dkey', working modulo n"""
-    pass
+    return pow(cyphertext, dkey, n)
diff --git a/rsa/key.py b/rsa/key.py
index c42592d..8e32ed7 100644
--- a/rsa/key.py
+++ b/rsa/key.py
@@ -49,11 +49,12 @@ class AbstractKey:
         :return: the loaded key
         :rtype: AbstractKey
         """
-        pass
+        der = rsa.pem.load_pem(keyfile, b'RSA PUBLIC KEY')
+        return cls._load_pkcs1_der(der)

     @classmethod
     def _load_pkcs1_der(cls: typing.Type[T], keyfile: bytes) ->T:
-        """Loads a key in PKCS#1 PEM format, implement in a subclass.
+        """Loads a key in PKCS#1 DER format, implement in a subclass.

         :param keyfile: contents of a DER-encoded file that contains
             the public key.
@@ -62,7 +63,11 @@ class AbstractKey:
         :return: the loaded key
         :rtype: AbstractKey
         """
-        pass
+        from pyasn1.codec.der import decoder
+        from rsa.asn1 import AsnPubKey
+
+        (priv, _) = decoder.decode(keyfile, asn1Spec=AsnPubKey())
+        return cls(n=int(priv['modulus']), e=int(priv['publicExponent']))

     def _save_pkcs1_pem(self) ->bytes:
         """Saves the key in PKCS#1 PEM format, implement in a subclass.
@@ -70,7 +75,8 @@ class AbstractKey:
         :returns: the PEM-encoded key.
         :rtype: bytes
         """
-        pass
+        der = self._save_pkcs1_der()
+        return rsa.pem.save_pem(der, b'RSA PUBLIC KEY')

     def _save_pkcs1_der(self) ->bytes:
         """Saves the key in PKCS#1 DER format, implement in a subclass.
@@ -78,7 +84,15 @@ class AbstractKey:
         :returns: the DER-encoded key.
         :rtype: bytes
         """
-        pass
+        from pyasn1.type import univ
+        from pyasn1.codec.der import encoder
+        from rsa.asn1 import AsnPubKey
+
+        asn_key = AsnPubKey()
+        asn_key.setComponentByName('modulus', univ.Integer(self.n))
+        asn_key.setComponentByName('publicExponent', univ.Integer(self.e))
+
+        return encoder.encode(asn_key)

     @classmethod
     def load_pkcs1(cls: typing.Type[T], keyfile: bytes, format: str='PEM') ->T:
@@ -93,13 +107,23 @@ class AbstractKey:
         :return: the loaded key
         :rtype: AbstractKey
         """
-        pass
+        methods = {
+            'PEM': cls._load_pkcs1_pem,
+            'DER': cls._load_pkcs1_der,
+        }
+
+        method = cls._assert_format_exists(format, methods)
+        return method(keyfile)

     @staticmethod
     def _assert_format_exists(file_format: str, methods: typing.Mapping[str,
         typing.Callable]) ->typing.Callable:
         """Checks whether the given file format exists in 'methods'."""
-        pass
+        try:
+            return methods[file_format.upper()]
+        except KeyError:
+            formats = ', '.join(sorted(methods.keys()))
+            raise ValueError('Unsupported format: %r, try one of %s' % (file_format, formats))

     def save_pkcs1(self, format: str='PEM') ->bytes:
         """Saves the key in PKCS#1 DER or PEM format.
@@ -109,7 +133,13 @@ class AbstractKey:
         :returns: the DER- or PEM-encoded key.
         :rtype: bytes
         """
-        pass
+        methods = {
+            'PEM': self._save_pkcs1_pem,
+            'DER': self._save_pkcs1_der,
+        }
+
+        method = self._assert_format_exists(format, methods)
+        return method()

     def blind(self, message: int) ->typing.Tuple[int, int]:
         """Performs blinding on the message.
@@ -122,7 +152,12 @@ class AbstractKey:

         See https://en.wikipedia.org/wiki/Blinding_%28cryptography%29
         """
-        pass
+        with self.mutex:
+            if self.blindfac_inverse == -1:
+                self.blindfac, self.blindfac_inverse = self._update_blinding_factor()
+
+        blinded = (message * self.blindfac) % self.n
+        return blinded, self.blindfac_inverse

     def unblind(self, blinded: int, blindfac_inverse: int) ->int:
         """Performs blinding on the message using random number 'blindfac_inverse'.
@@ -135,7 +170,7 @@ class AbstractKey:

         See https://en.wikipedia.org/wiki/Blinding_%28cryptography%29
         """
-        pass
+        return (blinded * blindfac_inverse) % self.n

     def _update_blinding_factor(self) ->typing.Tuple[int, int]:
         """Update blinding factors.
@@ -148,7 +183,9 @@ class AbstractKey:

         :return: the new blinding factor and its inverse.
         """
-        pass
+        blindfac = rsa.randnum.read_random_odd_int(self.n.bit_length())
+        blindfac_inverse = rsa.common.inverse(blindfac, self.n)
+        return blindfac, blindfac_inverse


 class PublicKey(AbstractKey):
@@ -362,7 +399,9 @@ class PrivateKey(AbstractKey):
         :returns: the decrypted message
         :rtype: int
         """
-        pass
+        blinded, blindfac_inverse = self.blind(encrypted)
+        decrypted_blinded = rsa.core.decrypt_int(blinded, self.d, self.n)
+        return self.unblind(decrypted_blinded, blindfac_inverse)

     def blinded_encrypt(self, message: int) ->int:
         """Encrypts the message using blinding to prevent side-channel attacks.
@@ -373,7 +412,9 @@ class PrivateKey(AbstractKey):
         :returns: the encrypted message
         :rtype: int
         """
-        pass
+        blinded, blindfac_inverse = self.blind(message)
+        encrypted_blinded = rsa.core.encrypt_int(blinded, self.e, self.n)
+        return self.unblind(encrypted_blinded, blindfac_inverse)

     @classmethod
     def _load_pkcs1_der(cls, keyfile: bytes) ->'PrivateKey':
@@ -460,7 +501,43 @@ def find_p_q(nbits: int, getprime_func: typing.Callable[[int], int]=rsa.
     True

     """
-    pass
+    total_bits = nbits * 2
+
+    # Make sure that p and q aren't too close or too far apart (for security)
+    shift = nbits // 16
+    pbits = nbits
+    qbits = nbits
+
+    # Choose the two initial primes
+    p = getprime_func(pbits)
+    q = getprime_func(qbits)
+
+    def is_acceptable(p: int, q: int) -> bool:
+        """Returns True iff p and q are acceptable:
+            - p and q differ
+            - (p * q) has the right nr of bits (when accurate=True)
+        """
+        if p == q:
+            return False
+
+        if accurate:
+            return rsa.common.bit_size(p * q) == total_bits
+        return True
+
+    # Keep choosing other primes until they match our requirements.
+    change_p = False
+    while not is_acceptable(p, q):
+        # Change p on one iteration and q on the other
+        if change_p:
+            p = getprime_func(pbits)
+        else:
+            q = getprime_func(qbits)
+
+        change_p = not change_p
+
+    # We want p > q as described on
+    # http://www.di-mgt.com.au/rsa_alg.html#crt
+    return (max(p, q), min(p, q))


 def calculate_keys_custom_exponent(p: int, q: int, exponent: int
@@ -476,7 +553,17 @@ def calculate_keys_custom_exponent(p: int, q: int, exponent: int
     :type exponent: int

     """
-    pass
+    phi_n = (p - 1) * (q - 1)
+
+    try:
+        d = rsa.common.inverse(exponent, phi_n)
+    except ValueError:
+        raise ValueError("e and phi_n are not relatively prime")
+
+    if (exponent * d) % phi_n != 1:
+        raise ValueError("e and d are not multiplicative inverses")
+
+    return (exponent, d)


 def calculate_keys(p: int, q: int) ->typing.Tuple[int, int]:
@@ -488,7 +575,7 @@ def calculate_keys(p: int, q: int) ->typing.Tuple[int, int]:

     :return: tuple (e, d) with the encryption and decryption exponents.
     """
-    pass
+    return calculate_keys_custom_exponent(p, q, DEFAULT_EXPONENT)


 def gen_keys(nbits: int, getprime_func: typing.Callable[[int], int],
@@ -507,7 +594,9 @@ def gen_keys(nbits: int, getprime_func: typing.Callable[[int], int],
         private key can be cracked. A very common choice for e is 65537.
     :type exponent: int
     """
-    pass
+    p, q = find_p_q(nbits // 2, getprime_func, accurate)
+    e, d = calculate_keys_custom_exponent(p, q, exponent)
+    return p, q, e, d


 def newkeys(nbits: int, accurate: bool=True, poolsize: int=1, exponent: int
@@ -536,7 +625,21 @@ def newkeys(nbits: int, accurate: bool=True, poolsize: int=1, exponent: int
     Python 2.6 or newer.

     """
-    pass
+    if poolsize > 1:
+        from rsa import parallel
+
+        (p, q, e, d) = parallel.compute_keys(nbits, getprime_func=rsa.prime.getprime,
+                                             accurate=accurate, exponent=exponent, poolsize=poolsize)
+    else:
+        (p, q, e, d) = gen_keys(nbits, accurate=accurate, exponent=exponent,
+                                getprime_func=rsa.prime.getprime)
+
+    n = p * q
+
+    return (
+        PublicKey(n, e),
+        PrivateKey(n, e, d, p, q)
+    )


 __all__ = ['PublicKey', 'PrivateKey', 'newkeys']
diff --git a/rsa/parallel.py b/rsa/parallel.py
index 0d3a4f8..2552131 100644
--- a/rsa/parallel.py
+++ b/rsa/parallel.py
@@ -31,7 +31,29 @@ def getprime(nbits: int, poolsize: int) ->int:
     True

     """
-    pass
+    def worker(nbits: int, pipe: Connection) ->None:
+        while True:
+            prime = rsa.randnum.read_random_odd_int(nbits)
+            if rsa.prime.is_prime(prime):
+                pipe.send(prime)
+                return
+
+    pipes = []
+    procs = []
+    for _ in range(poolsize):
+        recv_end, send_end = mp.Pipe(False)
+        pipes.append(recv_end)
+        p = mp.Process(target=worker, args=(nbits, send_end))
+        procs.append(p)
+        p.start()
+
+    result = pipes[0].recv()
+    
+    for p in procs:
+        p.terminate()
+        p.join()
+
+    return result


 __all__ = ['getprime']
diff --git a/rsa/pem.py b/rsa/pem.py
index b2b919a..ff78217 100644
--- a/rsa/pem.py
+++ b/rsa/pem.py
@@ -8,13 +8,24 @@ def _markers(pem_marker: FlexiText) ->typing.Tuple[bytes, bytes]:
     """
     Returns the start and end PEM markers, as bytes.
     """
-    pass
+    if isinstance(pem_marker, str):
+        pem_marker = pem_marker.encode('ascii')
+    return (b'-----BEGIN ' + pem_marker + b'-----',
+            b'-----END ' + pem_marker + b'-----')


 def _pem_lines(contents: bytes, pem_start: bytes, pem_end: bytes
     ) ->typing.Iterator[bytes]:
     """Generator over PEM lines between pem_start and pem_end."""
-    pass
+    in_pem_part = False
+    for line in contents.split(b'\n'):
+        line = line.strip()
+        if line == pem_start:
+            in_pem_part = True
+        elif in_pem_part:
+            if line == pem_end:
+                break
+            yield line


 def load_pem(contents: FlexiText, pem_marker: FlexiText) ->bytes:
@@ -31,7 +42,16 @@ def load_pem(contents: FlexiText, pem_marker: FlexiText) ->bytes:
         marker cannot be found.

     """
-    pass
+    if isinstance(contents, str):
+        contents = contents.encode('ascii')
+    
+    (pem_start, pem_end) = _markers(pem_marker)
+    pem_lines = [line for line in _pem_lines(contents, pem_start, pem_end)]
+    
+    if not pem_lines:
+        raise ValueError('Invalid PEM file: No PEM start marker "%s" found' % pem_start)
+    
+    return base64.b64decode(b''.join(pem_lines))


 def save_pem(contents: bytes, pem_marker: FlexiText) ->bytes:
@@ -45,4 +65,13 @@ def save_pem(contents: bytes, pem_marker: FlexiText) ->bytes:
     :return: the base64-encoded content between the start and end markers, as bytes.

     """
-    pass
+    (pem_start, pem_end) = _markers(pem_marker)
+    b64 = base64.b64encode(contents).replace(b'\n', b'')
+    pem_lines = [pem_start]
+    
+    for block_start in range(0, len(b64), 64):
+        block = b64[block_start:block_start + 64]
+        pem_lines.append(block)
+    
+    pem_lines.append(pem_end)
+    return b'\n'.join(pem_lines) + b'\n'
diff --git a/rsa/pkcs1.py b/rsa/pkcs1.py
index 5359be7..46c6158 100644
--- a/rsa/pkcs1.py
+++ b/rsa/pkcs1.py
@@ -68,7 +68,29 @@ def _pad_for_encryption(message: bytes, target_length: int) ->bytes:
     b'\\x00hello'

     """
-    pass
+    max_msglength = target_length - 11
+    msglength = len(message)
+    
+    if msglength > max_msglength:
+        raise OverflowError('%i bytes needed for message, but there is only'
+                            ' space for %i' % (msglength, max_msglength))
+    
+    padding = b''
+    padding_length = target_length - msglength - 3
+    
+    # We need at least 8 bytes of padding, so if the padding
+    # length is less than 8, we make the target_length higher.
+    if padding_length < 8:
+        target_length += 8 - padding_length
+        padding_length = 8
+    
+    for _ in range(padding_length):
+        padding += bytes([random.randint(1, 255)])
+    
+    return b''.join([b'\x00\x02',
+                     padding,
+                     b'\x00',
+                     message])


 def _pad_for_signing(message: bytes, target_length: int) ->bytes:
@@ -89,7 +111,19 @@ def _pad_for_signing(message: bytes, target_length: int) ->bytes:
     b'\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff'

     """
-    pass
+    max_msglength = target_length - 11
+    msglength = len(message)
+    
+    if msglength > max_msglength:
+        raise OverflowError('%i bytes needed for message, but there is only'
+                            ' space for %i' % (msglength, max_msglength))
+    
+    padding_length = target_length - msglength - 3
+    
+    return b''.join([b'\x00\x01',
+                     b'\xff' * padding_length,
+                     b'\x00',
+                     message])


 def encrypt(message: bytes, pub_key: key.PublicKey) ->bytes:
@@ -113,7 +147,15 @@ def encrypt(message: bytes, pub_key: key.PublicKey) ->bytes:
     True

     """
-    pass
+    keylength = common.byte_size(pub_key.n)
+    padded = _pad_for_encryption(message, keylength)
+    
+    payload = transform.bytes2int(padded)
+    encrypted = core.encrypt_int(payload, pub_key.e, pub_key.n)
+    
+    block = transform.int2bytes(encrypted, keylength)
+    
+    return block


 def decrypt(crypto: bytes, priv_key: key.PrivateKey) ->bytes:
@@ -166,7 +208,22 @@ def decrypt(crypto: bytes, priv_key: key.PrivateKey) ->bytes:
     rsa.pkcs1.DecryptionError: Decryption failed

     """
-    pass
+    blocksize = common.byte_size(priv_key.n)
+    encrypted = transform.bytes2int(crypto)
+    decrypted = priv_key.blinded_decrypt(encrypted)
+    cleartext = transform.int2bytes(decrypted, blocksize)
+
+    # If we can't find the cleartext marker, decryption failed.
+    if cleartext[0:2] != b'\x00\x02':
+        raise DecryptionError('Decryption failed')
+
+    # Find the 00 separator between the padding and the message
+    try:
+        sep_idx = cleartext.index(b'\x00', 2)
+    except ValueError:
+        raise DecryptionError('Decryption failed')
+
+    return cleartext[sep_idx + 1:]


 def sign_hash(hash_value: bytes, priv_key: key.PrivateKey, hash_method: str
@@ -185,7 +242,21 @@ def sign_hash(hash_value: bytes, priv_key: key.PrivateKey, hash_method: str
         requested hash.

     """
-    pass
+    # Get the ASN1 code for this hash method
+    if hash_method not in HASH_ASN1:
+        raise ValueError('Invalid hash method: %s' % hash_method)
+    asn1code = HASH_ASN1[hash_method]
+
+    # Encrypt the hash with the private key
+    cleartext = asn1code + hash_value
+    keylength = common.byte_size(priv_key.n)
+    padded = _pad_for_signing(cleartext, keylength)
+
+    payload = transform.bytes2int(padded)
+    encrypted = priv_key.blinded_encrypt(payload)
+    block = transform.int2bytes(encrypted, keylength)
+
+    return block


 def sign(message: bytes, priv_key: key.PrivateKey, hash_method: str) ->bytes:
@@ -205,7 +276,8 @@ def sign(message: bytes, priv_key: key.PrivateKey, hash_method: str) ->bytes:
         requested hash.

     """
-    pass
+    hash_value = compute_hash(message, hash_method)
+    return sign_hash(hash_value, priv_key, hash_method)


 def verify(message: bytes, signature: bytes, pub_key: key.PublicKey) ->str:
@@ -222,7 +294,24 @@ def verify(message: bytes, signature: bytes, pub_key: key.PublicKey) ->str:
     :returns: the name of the used hash.

     """
-    pass
+    keylength = common.byte_size(pub_key.n)
+    encrypted = transform.bytes2int(signature)
+    decrypted = core.decrypt_int(encrypted, pub_key.e, pub_key.n)
+    clearsig = transform.int2bytes(decrypted, keylength)
+
+    # Get the hash method
+    method_name = _find_method_hash(clearsig)
+    message_hash = compute_hash(message, method_name)
+
+    # Reconstruct the expected padded hash
+    cleartext = HASH_ASN1[method_name] + message_hash
+    expected = _pad_for_signing(cleartext, keylength)
+
+    # Compare with the signed one
+    if expected != clearsig:
+        raise VerificationError('Verification failed')
+
+    return method_name


 def find_signature_hash(signature: bytes, pub_key: key.PublicKey) ->str:
@@ -235,7 +324,12 @@ def find_signature_hash(signature: bytes, pub_key: key.PublicKey) ->str:
     :param pub_key: the :py:class:`rsa.PublicKey` of the person signing the message.
     :returns: the name of the used hash.
     """
-    pass
+    keylength = common.byte_size(pub_key.n)
+    encrypted = transform.bytes2int(signature)
+    decrypted = core.decrypt_int(encrypted, pub_key.e, pub_key.n)
+    clearsig = transform.int2bytes(decrypted, keylength)
+
+    return _find_method_hash(clearsig)


 def yield_fixedblocks(infile: typing.BinaryIO, blocksize: int
diff --git a/rsa/pkcs1_v2.py b/rsa/pkcs1_v2.py
index e6d2e23..b8905e8 100644
--- a/rsa/pkcs1_v2.py
+++ b/rsa/pkcs1_v2.py
@@ -27,7 +27,26 @@ def mgf1(seed: bytes, length: int, hasher: str='SHA-1') ->bytes:
     :raise OverflowError: when `length` is too large for the specified `hasher`
     :raise ValueError: when specified `hasher` is invalid
     """
-    pass
+    import hashlib
+
+    # Get the hash function
+    hash_func = getattr(hashlib, hasher.lower().replace('-', ''), None)
+    if hash_func is None:
+        raise ValueError(f"Invalid hash function: {hasher}")
+
+    hLen = hash_func().digest_size
+    if length > (2**32) * hLen:
+        raise OverflowError("Mask length too long for specified hash function")
+
+    # Generate the mask
+    T = b""
+    counter = 0
+    while len(T) < length:
+        C = counter.to_bytes(4, 'big')
+        T += hash_func(seed + C).digest()
+        counter += 1
+
+    return T[:length]


 __all__ = ['mgf1']
diff --git a/rsa/prime.py b/rsa/prime.py
index 07ae2c5..984a946 100644
--- a/rsa/prime.py
+++ b/rsa/prime.py
@@ -14,7 +14,9 @@ def gcd(p: int, q: int) ->int:
     >>> gcd(48, 180)
     12
     """
-    pass
+    while q:
+        p, q = q, p % q
+    return p


 def get_primality_testing_rounds(number: int) ->int:
@@ -29,7 +31,16 @@ def get_primality_testing_rounds(number: int) ->int:
       * p, q bitsize: 1536; rounds: 3
     See: http://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.186-4.pdf
     """
-    pass
+    bitsize = rsa.common.bit_size(number)
+    if bitsize >= 1536:
+        return 3
+    elif bitsize >= 1024:
+        return 4
+    elif bitsize >= 512:
+        return 7
+    else:
+        # For smaller bitsizes, we return a default value of 10
+        return 10


 def miller_rabin_primality_testing(n: int, k: int) ->bool:
@@ -47,7 +58,28 @@ def miller_rabin_primality_testing(n: int, k: int) ->bool:
     :return: False if the number is composite, True if it's probably prime.
     :rtype: bool
     """
-    pass
+    if n == 2 or n == 3:
+        return True
+    if n < 2 or n % 2 == 0:
+        return False
+
+    r, s = 0, n - 1
+    while s % 2 == 0:
+        r += 1
+        s //= 2
+
+    for _ in range(k):
+        a = rsa.randnum.read_random_odd_int(n - 3) + 2
+        x = pow(a, s, n)
+        if x == 1 or x == n - 1:
+            continue
+        for _ in range(r - 1):
+            x = pow(x, 2, n)
+            if x == n - 1:
+                break
+        else:
+            return False
+    return True


 def is_prime(number: int) ->bool:
@@ -60,7 +92,14 @@ def is_prime(number: int) ->bool:
     >>> is_prime(41)
     True
     """
-    pass
+    if number < 2:
+        return False
+    if number == 2:
+        return True
+    if number % 2 == 0:
+        return False
+    
+    return miller_rabin_primality_testing(number, get_primality_testing_rounds(number))


 def getprime(nbits: int) ->int:
@@ -78,7 +117,15 @@ def getprime(nbits: int) ->int:
     >>> common.bit_size(p) == 128
     True
     """
-    pass
+    while True:
+        integer = rsa.randnum.read_random_odd_int(nbits)
+        
+        # Make sure it's odd and the right size
+        integer |= 1
+        integer |= 2 ** (nbits - 1)
+        
+        if is_prime(integer):
+            return integer


 def are_relatively_prime(a: int, b: int) ->bool:
@@ -90,7 +137,7 @@ def are_relatively_prime(a: int, b: int) ->bool:
     >>> are_relatively_prime(2, 4)
     False
     """
-    pass
+    return gcd(a, b) == 1


 if __name__ == '__main__':
diff --git a/rsa/randnum.py b/rsa/randnum.py
index 24066b9..cbf5f14 100644
--- a/rsa/randnum.py
+++ b/rsa/randnum.py
@@ -10,12 +10,22 @@ def read_random_bits(nbits: int) ->bytes:
     If nbits isn't a whole number of bytes, an extra byte will be appended with
     only the lower bits set.
     """
-    pass
+    nbytes, rbits = divmod(nbits, 8)
+    
+    # Get the specified number of bytes
+    bytes_data = os.urandom(nbytes)
+    
+    if rbits > 0:
+        # If there are remaining bits, add one more byte
+        extra_byte = os.urandom(1)[0] & ((1 << rbits) - 1)
+        bytes_data += bytes([extra_byte])
+    
+    return bytes_data


 def read_random_int(nbits: int) ->int:
     """Reads a random integer of approximately nbits bits."""
-    pass
+    return transform.bytes2int(read_random_bits(nbits))


 def read_random_odd_int(nbits: int) ->int:
@@ -24,7 +34,7 @@ def read_random_odd_int(nbits: int) ->int:
     >>> read_random_odd_int(512) & 1
     1
     """
-    pass
+    return read_random_int(nbits) | 1


 def randint(maxvalue: int) ->int:
@@ -34,4 +44,15 @@ def randint(maxvalue: int) ->int:
     to store, the closer maxvalue is to (2 ** N) - 1, the faster this function
     is.
     """
-    pass
+    bit_size = common.bit_size(maxvalue)
+    
+    tries = 0
+    while True:
+        value = read_random_int(bit_size)
+        if 1 <= value <= maxvalue:
+            return value
+        
+        if tries % 10 == 0 and tries:
+            # After some tries, decrease the bit size to improve performance
+            bit_size -= 1
+        tries += 1
diff --git a/rsa/transform.py b/rsa/transform.py
index 0601701..dc40e9f 100644
--- a/rsa/transform.py
+++ b/rsa/transform.py
@@ -16,7 +16,7 @@ def bytes2int(raw_bytes: bytes) ->int:
     8405007

     """
-    pass
+    return int.from_bytes(raw_bytes, byteorder='big')


 def int2bytes(number: int, fill_size: int=0) ->bytes:
@@ -39,7 +39,17 @@ def int2bytes(number: int, fill_size: int=0) ->bytes:
         argument to this function to be set to ``False`` otherwise, no
         error will be raised.
     """
-    pass
+    if number < 0:
+        raise ValueError("Number must be non-negative")
+    
+    byte_length = max(1, math.ceil(number.bit_length() / 8))
+    
+    if fill_size > 0:
+        if byte_length > fill_size:
+            raise OverflowError("Number is too large for the specified fill size")
+        return number.to_bytes(fill_size, byteorder='big')
+    else:
+        return number.to_bytes(byte_length, byteorder='big')


 if __name__ == '__main__':
diff --git a/rsa/util.py b/rsa/util.py
index efc0a3b..4bdeb07 100644
--- a/rsa/util.py
+++ b/rsa/util.py
@@ -6,4 +6,37 @@ import rsa.key

 def private_to_public() ->None:
     """Reads a private key and outputs the corresponding public key."""
-    pass
+    parser = OptionParser(usage='usage: %prog [options]')
+    parser.add_option('--in', dest='infile', type='string',
+                      help='Input filename. Reads from stdin if not specified')
+    parser.add_option('--out', dest='outfile', type='string',
+                      help='Output filename. Writes to stdout of not specified')
+    parser.add_option('--inform', dest='inform', type='string', default='PEM',
+                      help='Input format (PEM or DER). Default: PEM')
+    parser.add_option('--outform', dest='outform', type='string', default='PEM',
+                      help='Output format (PEM or DER). Default: PEM')
+
+    (options, args) = parser.parse_args()
+
+    # Read input file
+    if options.infile:
+        with open(options.infile, 'rb') as infile:
+            keydata = infile.read()
+    else:
+        keydata = sys.stdin.buffer.read()
+
+    # Load the private key
+    privkey = rsa.key.PrivateKey.load_pkcs1(keydata, format=options.inform)
+
+    # Extract the public key
+    pubkey = rsa.key.PublicKey(privkey.n, privkey.e)
+
+    # Save the public key
+    pubkeydata = pubkey.save_pkcs1(format=options.outform)
+
+    # Write output file
+    if options.outfile:
+        with open(options.outfile, 'wb') as outfile:
+            outfile.write(pubkeydata)
+    else:
+        sys.stdout.buffer.write(pubkeydata)