freebsd-src/tests/sys/opencrypto
Enji Cooper ffbc8cc0f2 Fix encoding issues with python 3
In python 3, the default encoding was switched from ascii character sets to
unicode character sets in order to support internationalization by default.
Some interfaces, like ioctls and packets, however, specify data in terms of
non-unicode encodings formats, either in host endian (`fcntl.ioctl`) or
network endian (`dpkt`) byte order/format.

This change alters assumptions made by previous code where it was all
data objects were assumed to be basestrings, when they should have been
treated as byte arrays. In order to achieve this the following are done:
* str objects with encodings needing to be encoded as ascii byte arrays are
  done so via `.encode("ascii")`. In order for this to work on python 3 in a
  type agnostic way (as it anecdotally varied depending on the caller), call
  `.encode("ascii")` only on str objects with python 3 to cast them to ascii
  byte arrays in a helper function name `str_to_ascii(..)`.
* `dpkt.Packet` objects needing to be passed in to `fcntl.ioctl(..)` are done
  so by casting them to byte arrays via `bytes()`, which calls
  `dpkt.Packet__str__` under the covers and does the necessary str to byte array
  conversion needed for the `dpkt` APIs and `struct` module.

In order to accomodate this change, apply the necessary typecasting for the
byte array literal in order to search `fop.name` for nul bytes.

This resolves all remaining python 2.x and python 3.x compatibility issues on
amd64. More work needs to be done for the tests to function with i386, in
general (this is a legacy issue).

PR:		237403
MFC after:	1 week
Tested with:	python 2.7.16 (amd64), python 3.6.8 (amd64)
2019-05-21 03:52:48 +00:00
..
blake2-kat.h Import Blake2 algorithms (blake2b, blake2s) from libb2 2018-03-21 16:18:14 +00:00
blake2_test.c Fix sys/opencrypto/blake2_test when kern.cryptodevallowsoft=0 2018-08-16 23:49:56 +00:00
cryptodev.py Fix encoding issues with python 3 2019-05-21 03:52:48 +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