Move some shared logic to functions

Pulled from #1116
The test is supposed to fail on private_numbers, but since this PR actually enforces sanity inside `RSAPublicNumbers` `e=1` (correctly) causes a `ValueError`. It worked previously because we weren't checking anything other than whether you were passing integers.