Add std::array support to BigInt::serialize function
This PR resolves the TODO comment in BigInt::serialize() by adding support for std::array<uint8_t, N> alongside existing std::vector and secure_vector support.
TODO Message:
// TODO this supports std::vector and secure_vector
// it would be nice if this also could work with std::array as in
// bn.serialize_to<std::array<uint8_t, 32>>(32);
coverage: 91.956% (+1.3%) from 90.624% when pulling 84439abca89e06ed0053ad673bbd80467e79e644 on KaganCanSit:bigint-array-serialization into e78c62c39cd051ed45d2bb2e502faf777f58c311 on randombit:master.
Nice, thanks!
Interesting way to detect an array! However, IIUC this would work for other tuple-types as well, no? Like
std::pair<int, std::string>. That would produce very strange compiler errors for sure... But then again, the API does also allow passing astd::vector<uint32_t>, which is just as awful I guess. You could look into using thestatically_spanable_range<>concept to detect the array instead.Anyway: Could you please add a few tests that serialize a
BigIntinto an array?src/tests/test_bigint.cpphas a functiontest_bigint_serialization, please add anotherCHECKthat usesstd::array. Also check that the exception is thrown as expected if the array is too short or too long.
You're right that it will provide general support for tuple types. I've made the changes as you suggested.
Additionally, for the situation you mentioned, the API does also allow passing a std::vector<uint32_t>, which is just as awful I guess. I think we could use requires std::same_as<typename T::value_type, uint8_t. There were no issues during compilation and testing.
However, since this is a general change to the API, I haven't added it to the branch. What do you think?