Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop the deprecated rand.egd function #630

Merged
merged 6 commits into from May 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.rst
Expand Up @@ -12,7 +12,9 @@ The third digit is only for regressions.
Backward-incompatible changes:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

*none*
- Removed the deprecated ``OpenSSL.rand.egd`` function.
Applications should prefer ``os.urandom()`` for random number generation.
`#630 <https://github.com/pyca/pyopenssl/pull/630>`_


Deprecations:
Expand Down
2 changes: 0 additions & 2 deletions doc/api/rand.rst
Expand Up @@ -20,8 +20,6 @@ This module handles the OpenSSL pseudo random number generator (PRNG) and declar

.. autofunction:: cleanup

.. autofunction:: egd(path[, bytes])

.. autofunction:: load_file(filename[, bytes])

.. autofunction:: seed
Expand Down
35 changes: 0 additions & 35 deletions src/OpenSSL/rand.py
Expand Up @@ -2,9 +2,6 @@
PRNG management routines, thin wrappers.
"""

import os
import warnings

from functools import partial

from six import integer_types as _integer_types
Expand Down Expand Up @@ -113,38 +110,6 @@ def status():
return _lib.RAND_status()


def egd(path, bytes=_unspecified):
"""
Query the system random source and seed the PRNG.

Does *not* actually query the EGD.

.. deprecated:: 16.0.0
EGD was only necessary for some commercial UNIX systems that all
reached their ends of life more than a decade ago. See
`pyca/cryptography#1636
<https://github.com/pyca/cryptography/pull/1636>`_.

:param path: Ignored.
:param bytes: (optional) The number of bytes to read, default is 255.

:returns: ``len(bytes)`` or 255 if not specified.
"""
warnings.warn("OpenSSL.rand.egd() is deprecated as of 16.0.0.",
DeprecationWarning)

if not isinstance(path, _builtin_bytes):
raise TypeError("path must be a byte string")

if bytes is _unspecified:
bytes = 255
elif not isinstance(bytes, int):
raise TypeError("bytes must be an integer")

seed(os.urandom(bytes))
return bytes


def cleanup():
"""
Erase the memory used by the PRNG.
Expand Down
22 changes: 0 additions & 22 deletions tests/test_rand.py
Expand Up @@ -100,28 +100,6 @@ def test_status(self):
# entropy or not.
assert rand.status() in (0, 1)

@pytest.mark.parametrize('args', [
(b"foo", 255),
(b"foo",),
])
def test_egd_warning(self, args):
"""
Calling egd raises :exc:`DeprecationWarning`.
"""
pytest.deprecated_call(rand.egd, *args)

@pytest.mark.parametrize('args', [
(None, 255),
(b"foo", None),
])
def test_egd_wrong_args(self, args):
"""
`OpenSSL.rand.egd` raises `TypeError` if called with a non-`int`
or non-`str` argument.
"""
with pytest.raises(TypeError):
rand.egd(*args)

def test_cleanup(self):
"""
`OpenSSL.rand.cleanup` releases the memory used by the PRNG and
Expand Down