Use code generation instead of a reflection-based serializer for ASN (BER/DER) data.
authorJeremy Barton <jbarton@microsoft.com>
Sat, 25 Aug 2018 05:49:25 +0000 (22:49 -0700)
committerGitHub <noreply@github.com>
Sat, 25 Aug 2018 05:49:25 +0000 (22:49 -0700)
commitf2df97a92b86ece343c8d7ad8c13b7f9fd6d92fe
tree4317ffa71480c099271b0dd6f8f63792e602cc59
parent1ccbc874d3b3bf09be9a3e32208071cea56d2c2e
Use code generation instead of a reflection-based serializer for ASN (BER/DER) data.

Code generation solves a couple problems that the current serialization mechanism has (while maintaining the goodness):

* When deserialization fails it's really hard to debug why
  * Solution: The genenerated code makes it easier to do things like break after a specific field decode.
* Reflection problems (rd.xml interactions, field ordering guarantees, etc)
  * Solution: It's not reflection
* Perf
  * Benchmarks say that the generated code is ~50x faster than the serializer
  * Some of the sanity checks from the serializer can be moved into #if DEBUG cctors for one-shot verification

The principles for this generator were:

* Avoid the paradigm of "run this tool and check in the output"
* Use inbuilt MSBuild tasks (in this case XslTransformation)

Since MSBuild for .NET Core doesn't have the XslTransformation class it's a combination of "freshly built" and "checked in" for the time being.

This change only converts two types from the serializer to the generator. Others will happen in followup PRs.

Commit migrated from https://github.com/dotnet/corefx/commit/50edd57cbc39f02234a8423125746941c211af13
21 files changed:
src/libraries/Common/src/System/Security/Cryptography/Asn1/AsnXml.targets [new file with mode: 0644]
src/libraries/Common/src/System/Security/Cryptography/Asn1/AttributeAsn.cs
src/libraries/Common/src/System/Security/Cryptography/Asn1/Rc2CbcParameters.manual.cs [moved from src/libraries/Common/src/System/Security/Cryptography/Asn1/Rc2CbcParameters.cs with 82% similarity]
src/libraries/Common/src/System/Security/Cryptography/Asn1/Rc2CbcParameters.xml [new file with mode: 0644]
src/libraries/Common/src/System/Security/Cryptography/Asn1/Rc2CbcParameters.xml.cs [new file with mode: 0644]
src/libraries/Common/src/System/Security/Cryptography/Asn1/asn.xsd [new file with mode: 0644]
src/libraries/Common/src/System/Security/Cryptography/Asn1/asn.xslt [new file with mode: 0644]
src/libraries/Common/src/System/Security/Cryptography/Asn1V2.cs
src/libraries/Common/src/System/Security/Cryptography/AsnReader.cs
src/libraries/Common/src/System/Security/Cryptography/PasswordBasedEncryption.cs
src/libraries/System.Security.Cryptography.Algorithms/src/System.Security.Cryptography.Algorithms.csproj
src/libraries/System.Security.Cryptography.Cng/src/System.Security.Cryptography.Cng.csproj
src/libraries/System.Security.Cryptography.Pkcs/src/Internal/Cryptography/Pal/AnyOS/AsnHelpers.cs
src/libraries/System.Security.Cryptography.Pkcs/src/Internal/Cryptography/Pal/AnyOS/ManagedPal.Encrypt.cs
src/libraries/System.Security.Cryptography.Pkcs/src/Internal/Cryptography/Pal/AnyOS/ManagedPal.cs
src/libraries/System.Security.Cryptography.Pkcs/src/System.Security.Cryptography.Pkcs.csproj
src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/Asn1/SignedAttributesSet.xml [new file with mode: 0644]
src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/Asn1/SignedAttributesSet.xml.cs [new file with mode: 0644]
src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/Asn1/SignerInfoAsn.cs
src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/CmsSigner.cs
src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/SignerInfo.cs