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
Use initialCapacity in ASN.1 templates for some primitives #81626
Conversation
Tagging subscribers to this area: @dotnet/area-system-security, @vcsjones Issue DetailsIn our ASN.1 templated encoding, we encode managed values with For some primitives types, like an ASN.1 Boolean and ASN.1 Integer (where the integer is known to be a managed For booleans, we know the encoded length is always going to be 3 bytes for DER. For integers (where the backing type is Where possible, let's give these size hints to reduce the initial allocation size. For example, the
|
(If we ever get one-shot encoding that can write to a stack buffer, that would obviously be better, but we can do this right now) |
Tagging subscribers to this area: @dotnet/area-system-formats-asn1, @vcsjones Issue DetailsIn our ASN.1 templated encoding, we encode managed values with For some primitives types, like an ASN.1 Boolean and ASN.1 Integer (where the integer is known to be a managed For booleans, we know the encoded length is always going to be 3 bytes for DER. For integers (where the backing type is Where possible, let's give these size hints to reduce the initial allocation size. For example, the
|
In our ASN.1 templated encoding, we encode managed values with
AsnWriter
to determine if they are equal todefaultDerInit
.For some primitives types, like an ASN.1 Boolean and ASN.1 Integer (where the integer is known to be a managed
int
) this has some waste asAsnWriter
has an initial capacity of 1024 bytes.For booleans, we know the encoded length is always going to be 3 bytes for DER. For integers (where the backing type is
int
) we know it will encode to at most 6 bytes.Where possible, let's give these size hints to reduce the initial allocation size. For example, the
Critical
boolean in X.509 extensions has a default. Before and after of encoding a basic constraints extension: