formats icon indicating copy to clipboard operation
formats copied to clipboard

der: add `EncodeValueLenCached` wrapper

Open dishmaker opened this issue 7 months ago • 2 comments

Sometimes, when encoding big DER structures, value_len gets called many times.

In order to limit amount of recursive calls, this wrapper caches the computed length, until the value gets encoded.

dishmaker avatar Jul 17 '25 13:07 dishmaker

Using a newtype for this seems pretty heavy-handed. Perhaps there's an alternative solution that can reduce the number of calls?

Do you have a specific example of where this is problematic? Could those types handle caching the length themselves?

tarcieri avatar Jul 17 '25 14:07 tarcieri

I don't have an example. This just seems to be reasonable, where PKCS#15 nests objects recursively (example) Actually, this newtype can be in a separate crate.

dishmaker avatar Jul 17 '25 14:07 dishmaker

Closing as stale

tarcieri avatar Feb 11 '26 20:02 tarcieri