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

Use initialCapacity in ASN.1 templates for some primitives #81626

Merged
merged 3 commits into from
Feb 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ internal void Encode(AsnWriter writer, Asn1Tag tag)

// DEFAULT value handler for IterationCount.
{
AsnWriter tmp = new AsnWriter(AsnEncodingRules.DER);
const int AsnManagedIntegerDerMaxEncodeSize = 6;
AsnWriter tmp = new AsnWriter(AsnEncodingRules.DER, initialCapacity: AsnManagedIntegerDerMaxEncodeSize);
vcsjones marked this conversation as resolved.
Show resolved Hide resolved
tmp.WriteInteger(IterationCount);

if (!tmp.EncodedValueEquals(DefaultIterationCount))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ internal void Encode(AsnWriter writer, Asn1Tag tag)

// DEFAULT value handler for SaltLength.
{
AsnWriter tmp = new AsnWriter(AsnEncodingRules.DER);
const int AsnManagedIntegerDerMaxEncodeSize = 6;
AsnWriter tmp = new AsnWriter(AsnEncodingRules.DER, initialCapacity: AsnManagedIntegerDerMaxEncodeSize);
tmp.WriteInteger(SaltLength);

if (!tmp.EncodedValueEquals(DefaultSaltLength))
Expand All @@ -113,7 +114,8 @@ internal void Encode(AsnWriter writer, Asn1Tag tag)

// DEFAULT value handler for TrailerField.
{
AsnWriter tmp = new AsnWriter(AsnEncodingRules.DER);
const int AsnManagedIntegerDerMaxEncodeSize = 6;
AsnWriter tmp = new AsnWriter(AsnEncodingRules.DER, initialCapacity: AsnManagedIntegerDerMaxEncodeSize);
tmp.WriteInteger(TrailerField);

if (!tmp.EncodedValueEquals(DefaultTrailerField))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ internal void Encode(AsnWriter writer, Asn1Tag tag)

// DEFAULT value handler for Critical.
{
AsnWriter tmp = new AsnWriter(AsnEncodingRules.DER);
const int AsnBoolDerEncodeSize = 3;
AsnWriter tmp = new AsnWriter(AsnEncodingRules.DER, initialCapacity: AsnBoolDerEncodeSize);
tmp.WriteBoolean(Critical);

if (!tmp.EncodedValueEquals(DefaultCritical))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,10 @@ namespace <xsl:value-of select="@namespace" />
<xsl:when test="@defaultDerInit and not(@explicitTag)" xml:space="preserve">

// DEFAULT value handler for <xsl:value-of select="@name" />.
{
AsnWriter tmp = new AsnWriter(AsnEncodingRules.DER);<xsl:apply-templates select="." mode="EncodeValue">
{<xsl:apply-templates select="." mode="AsnWriterDefaultDer">
<xsl:with-param name="writerName" select="'tmp'" />
<xsl:with-param name="indent" select="concat(' ', $indent)" />
</xsl:apply-templates><xsl:apply-templates select="." mode="EncodeValue">
<xsl:with-param name="writerName" select="'tmp'" />
<xsl:with-param name="indent" select="concat(' ', $indent)" />
</xsl:apply-templates>
Expand All @@ -297,6 +299,21 @@ namespace <xsl:value-of select="@namespace" />
</xsl:choose>
</xsl:template>

<xsl:template match="*" mode="AsnWriterDefaultDer" xml:space="default">
<xsl:param name="writerName" />
<xsl:param name="indent" />
<xsl:choose>
<xsl:when test="self::asn:Boolean" xml:space="preserve">
<xsl:value-of select="$indent"/>const int AsnBoolDerEncodeSize = 3;
<xsl:value-of select="$indent"/>AsnWriter <xsl:value-of select="$writerName"/> = new AsnWriter(AsnEncodingRules.DER, initialCapacity: AsnBoolDerEncodeSize);</xsl:when>
<xsl:when test="self::asn:Integer[@backingType = 'int']" xml:space="preserve">
<xsl:value-of select="$indent"/>const int AsnManagedIntegerDerMaxEncodeSize = 6;
<xsl:value-of select="$indent"/>AsnWriter <xsl:value-of select="$writerName"/> = new AsnWriter(AsnEncodingRules.DER, initialCapacity: AsnManagedIntegerDerMaxEncodeSize);</xsl:when>
<xsl:otherwise xml:space="preserve">
<xsl:value-of select="$indent"/>AsnWriter <xsl:value-of select="$writerName"/> = new AsnWriter(AsnEncodingRules.DER);</xsl:otherwise>
</xsl:choose>
</xsl:template>

<!-- Struct OPTIONAL -->
<xsl:template match="asn:AsnType | asn:AnyValue | asn:Boolean | asn:Integer | asn:BitString | asn:NamedBitList | asn:OctetString | asn:Enumerated | asn:UtcTime | asn:GeneralizedTime" mode="EncodeOptional">

Expand Down Expand Up @@ -342,8 +359,10 @@ namespace <xsl:value-of select="@namespace" />
<xsl:when test="@defaultDerInit and @explicitTag" xml:space="preserve">

// DEFAULT value handler for <xsl:value-of select="@name" />.
{
AsnWriter tmp = new AsnWriter(AsnEncodingRules.DER);<xsl:apply-templates select="." mode="EncodeSimpleValue">
{<xsl:apply-templates select="." mode="AsnWriterDefaultDer">
<xsl:with-param name="writerName" select="'tmp'" />
<xsl:with-param name="indent" select="concat(' ', $indent)" />
</xsl:apply-templates><xsl:apply-templates select="." mode="EncodeSimpleValue">
<xsl:with-param name="writerName" select="'tmp'" />
<xsl:with-param name="indent" select="concat(' ', $indent)" />
</xsl:apply-templates>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ internal void Encode(AsnWriter writer, Asn1Tag tag)

// DEFAULT value handler for CertReq.
{
AsnWriter tmp = new AsnWriter(AsnEncodingRules.DER);
const int AsnBoolDerEncodeSize = 3;
AsnWriter tmp = new AsnWriter(AsnEncodingRules.DER, initialCapacity: AsnBoolDerEncodeSize);
tmp.WriteBoolean(CertReq);

if (!tmp.EncodedValueEquals(DefaultCertReq))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ internal void Encode(AsnWriter writer, Asn1Tag tag)

// DEFAULT value handler for Ordering.
{
AsnWriter tmp = new AsnWriter(AsnEncodingRules.DER);
const int AsnBoolDerEncodeSize = 3;
AsnWriter tmp = new AsnWriter(AsnEncodingRules.DER, initialCapacity: AsnBoolDerEncodeSize);
tmp.WriteBoolean(Ordering);

if (!tmp.EncodedValueEquals(DefaultOrdering))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ internal void Encode(AsnWriter writer, Asn1Tag tag)

// DEFAULT value handler for CA.
{
AsnWriter tmp = new AsnWriter(AsnEncodingRules.DER);
const int AsnBoolDerEncodeSize = 3;
AsnWriter tmp = new AsnWriter(AsnEncodingRules.DER, initialCapacity: AsnBoolDerEncodeSize);
tmp.WriteBoolean(CA);

if (!tmp.EncodedValueEquals(DefaultCA))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ internal void Encode(AsnWriter writer, Asn1Tag tag)

// DEFAULT value handler for Version.
{
AsnWriter tmp = new AsnWriter(AsnEncodingRules.DER);
const int AsnManagedIntegerDerMaxEncodeSize = 6;
AsnWriter tmp = new AsnWriter(AsnEncodingRules.DER, initialCapacity: AsnManagedIntegerDerMaxEncodeSize);
tmp.WriteInteger(Version);

if (!tmp.EncodedValueEquals(DefaultVersion))
Expand Down