Skip to content

der: add EncodeValueLenCached wrapper #1949

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

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

dishmaker
Copy link
Contributor

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.

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.
@tarcieri
Copy link
Member

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?

@dishmaker
Copy link
Contributor Author

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 dishmaker marked this pull request as draft July 18, 2025 09:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants