freebsd-nq/tests/sys/opencrypto
Enji Cooper a60d9a9892 Fix KAT(CCM)?Parser file descriptor leaks
Make `KAT(CCM)?Parser` into a context suite-capable object by implementing
`__enter__` and `__exit__` methods which manage opening up the file descriptors
and closing them on context exit. This implementation was decided over adding
destructor logic to a `__del__` method, as there are a number of issues around
object lifetimes when dealing with threading cleanup, atexit handlers, and a
number of other less obvious edgecases. Plus, the architected solution is more
pythonic and clean.

Complete the iterator implementation by implementing a `__next__` method for
both classes which handles iterating over the data using a generator pattern,
and by changing `__iter__` to return the object instead of the data which it
would iterate over. Alias the `__next__` method to `next` when working with
python 2.x in order to maintain functional compatibility between the two major
versions.

As part of this work and to ensure readability, push the initialization of the
parser objects up one layer and pass it down to a helper function. This could
have been done via a decorator, but I was trying to keep it simple for other
developers to make it easier to modify in the future.

This fixes ResourceWarnings with python 3.

PR:		237403
MFC after:	1 week
Tested with:	python 2.7.16 (amd64), python 3.6.8 (amd64)
2019-05-21 02:30:43 +00:00
..
blake2_test.c Fix sys/opencrypto/blake2_test when kern.cryptodevallowsoft=0 2018-08-16 23:49:56 +00:00
blake2-kat.h Import Blake2 algorithms (blake2b, blake2s) from libb2 2018-03-21 16:18:14 +00:00
cryptodev.py Fix KAT(CCM)?Parser file descriptor leaks 2019-05-21 02:30:43 +00:00
cryptodevh.py Sync cryptographic algorithm constants with current cryptodev.h. 2019-04-19 21:58:51 +00:00
cryptotest.py Fix KAT(CCM)?Parser file descriptor leaks 2019-05-21 02:30:43 +00:00
Makefile Refactor tests/sys/opencrypto/runtests 2019-05-10 00:03:32 +00:00
Makefile.depend
poly1305_test.c Add test cases for Poly1305 from RFC 7539 2018-08-17 00:32:00 +00:00
runtests.sh Allow the end-user to pass along arguments to cryptotest.py via $CRYPTOTEST_ARGS 2019-05-20 22:32:26 +00:00