Skip to content
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

Helper function for BER to DER transcoding #1652

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dwhjames
Copy link
Contributor

@dwhjames dwhjames commented Feb 9, 2025

Issue #779 has had some progress (PR #1321). However, this helper function is intended to provide an escape hatch for limited support of some cases of BER, while not waiting for general support or needing API changes.

Specifically, the transcoding of occurrences of the constructed, indefinite-length method into the constructed, definite-length method. This is likely sufficient to address the examples in the wild, reported in Issue #779 and elsewhere.

The goal is not to support all possible violations of DER that are still following valid BER. Examples are non-canonical encodings of lengths (which would require an alternative Length), or constructed string types (which could be handled by further work on this function, but usage may not be well motivated).

@dwhjames
Copy link
Contributor Author

dwhjames commented Feb 9, 2025

I originally developed this as a recursive function, in fact, a set of co-recursive functions. To preserve stack safety for arbitrary depth encodings, I rewrote it as a loop + stack; however, this is certainly far harder code to read.

I used the recursive approach as a reference implementation to test the iterative implementation. Although I haven’t included it within the PR, so as to keep the PR size more reasonable. As the unit and integration tests give effectively 100% code coverage (except for some unreachable error cases), I’m hoping that is sufficient assurance, even without the more comprehensible reference implementation.

Issue RustCrypto#779 has had some progress (PR RustCrypto#1321). However, this helper
function is intended to provide an escape hatch for limited support
of some cases of BER, while not waiting for general support or needing
API changes.

Specifically, the transcoding of occurrences of the constructed,
indefinite-length method into the constructed, definite-length method.
This is likely sufficient to address the examples in the wild, reported
in Issue RustCrypto#779 and elsewhere.

The goal is not to support all possible violations of DER that are still
following valid BER. Examples are non-canonical encodings of lengths
(which would require an alternative `Length`), or constructed string
types (which could be handled by further work on this function, but
usage may not be well motivated).
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.

1 participant