.NET's System.DirectoryServices.Protocols assembly specifies a light-weight ASN.1 BER encoder, but the documentation is not great: BerConverter
.
You call it by specifying a format string and a list of objects to encode.
INTEGER
s can be encoded with format charactersi
ore
OCTET STRING
s can be encoded witho
characterSEQUENCE
s can be encoded with{
and}
- etc.
I'd really like to make use of this simple converter so I don't have to take on an additional dependency. Taking on a dependency is undesirable because C# is callable from Powershell, and it is great to distribute a script that does something fancy with C# so long as it doesn't require an assembly that isn't included with .NET.
However, BerConverter doesn't seem to have a way to specify an Application or Context-Specific tag, which are often used to remove ambiguity in ASN.1, for example when components of a constructed type are marked as OPTIONAL
So, I can encode the following:
BerConverter.Encode("{i{i}}", 1, 2);
Which gives:
30 84 00 00 00 0c 02 01 01 30 84 00 00 00 03 02 01 02
But, if that second sequence needs to be [Application 1]
or 61
... I'm not sure what to put in the format string to emit that in the encoding.
Does BerConverter even have this capability?