-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
[META] Declarative API for ASN.1 in Python #12283
Comments
As an implementation/integration consideration: we'll (@facutuesca and I) begin prototyping this as its own independent codebase, which should then be relatively straightforward to fold into Cryptography (since the only deps should be pyO3 and rust-asn1). |
Some notes as I begin to look into this:
|
This would be a huge win for cryptography, to use it to implement custom ASN1 formats. I am currently using asn1crypto for that, but this has not type hints and converting between the cryptography objects and those from asn1crypto is cumbersome. Maybe adding some small helper to convert to and from PEM would also be helpful. This is not very complicated but doing it in each project individually fells wrong. |
This is a meta-issue/design issue for tracking a declarative ASN.1 API for Cryptography!
The goal: an importable Python API that users of Cryptography can define ASN.1 structures with, which can then be ser/de'd to and from DER (and only DER).
A rough sketch, demonstrating the basic idioms of the API:
This declarative API should have fully generality/expressivity with respect to ASN.1's own feature set, including qualifiers like
EXPLICIT
andIMPLICIT
:This would also (naturally) include generality over user-defined types:
Key design constraints:
Open design questions:
What's the best way to handle
ANY
?asn1.Any
as a generic TLV type, similar to rust-asn1?What's the best way to handle
ANY DEFINED BY
?Maybe something like this:
To what extent/how can we best support trivial "native" Python types (
int
,str
, etc.) versus "synthetic" types?str
? ProbablyUTF8String
, with all other string-ish types beingbytes
?What about non-trivial native types like
list[T]
,set[T]
, etc? Should we support these with fixed mappings (e.g.list[T] -> SEQUENCE OF
), or should we have our own types that don't require as much object conversion (e.g.asn.List[T]
)?To what extent should we support
datetime
as a time type/map betweendatetime
andUTCTime
/GeneralizedTime
?UTCTime OR GeneralizedTime
but instead gets onlyGeneralizedTime
What's the best way to handle ASN.1 type constraints, e.g. ranged integers and min/max sequence/set lengths?
Annotated
, e.g.Annotated[list[T], asn1.size(1...10)]
Open integration questions:
cryptography
? Doescryptography.hazmat.asn1
make sense, or should it becryptography.asn1
, or something else?There are probably many other questions too, and I'm sure I've missed some in my notes 🙂
CC @facutuesca
The text was updated successfully, but these errors were encountered: