Begin to implement Abstract Syntax Notation (ASN) v1 and the related DER-encoded Security Certificate formats

This commit is contained in:
Michael Becker 2014-10-25 21:52:11 -04:00
parent 3727fa7887
commit 61db8164c7
5 changed files with 145 additions and 0 deletions

View File

@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UniversalEditor.IO;
using UniversalEditor.ObjectModels.AbstractSyntax;
namespace UniversalEditor.DataFormats.AbstractSyntax.DER
{
public class DERDataFormat : DataFormat
{
private static DataFormatReference _dfr = null;
public override DataFormatReference MakeReference()
{
if (_dfr == null)
{
_dfr = base.MakeReference();
_dfr.Capabilities.Add(typeof(AbstractSyntaxObjectModel), DataFormatCapabilities.All);
}
return _dfr;
}
protected override void LoadInternal(ref ObjectModel objectModel)
{
AbstractSyntaxObjectModel asn = (objectModel as AbstractSyntaxObjectModel);
if (asn == null) throw new ObjectModelNotSupportedException();
Reader reader = base.Accessor.Reader;
while (!reader.EndOfStream)
{
byte identifier = reader.ReadByte();
byte tagClass = (byte)identifier.GetBits(7, 2);
byte primitiveOrConstructed = (byte)identifier.GetBits(6, 1);
byte tagNumber = (byte)identifier.GetBits(0, 5);
}
}
protected override void SaveInternal(ObjectModel objectModel)
{
throw new NotImplementedException();
}
}
}

View File

@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UniversalEditor.ObjectModels.AbstractSyntax;
using UniversalEditor.DataFormats.AbstractSyntax.DER;
using UniversalEditor.IO;
using UniversalEditor.ObjectModels.SecurityCertificate;
namespace UniversalEditor.DataFormats.SecurityCertificate.DER
{
public class DERCertificateDataFormat : DERDataFormat
{
private static DataFormatReference _dfr = null;
public override DataFormatReference MakeReference()
{
if (_dfr == null)
{
_dfr = new DataFormatReference(GetType());
_dfr.Capabilities.Add(typeof(SecurityCertificateObjectModel), DataFormatCapabilities.All);
_dfr.Filters.Add("Security certificate (Binary-encoded DER)", new byte?[][] { new byte?[] { (byte)0x30, (byte)0x82 } }, new string[] { "*.cer", "*.der", "*.p7b" });
_dfr.Filters.Add("Security certificate (Base64-encoded DER)", new byte?[][] { new byte?[] { (byte)'-', (byte)'-', (byte)'-', (byte)'-', (byte)'-', (byte)'B', (byte)'E', (byte)'G', (byte)'I', (byte)'N', (byte)' ', (byte)'C', (byte)'E', (byte)'R', (byte)'T', (byte)'I', (byte)'F', (byte)'I', (byte)'C', (byte)'A', (byte)'T', (byte)'E', (byte)'-', (byte)'-', (byte)'-', (byte)'-', (byte)'-', (byte)'\r', (byte)'\n' } }, new string[] { "*.cer", "*.der", "*.p7b" });
}
return _dfr;
}
protected override void BeforeLoadInternal(Stack<ObjectModel> objectModels)
{
base.BeforeLoadInternal(objectModels);
objectModels.Push(new AbstractSyntaxObjectModel());
}
protected override void AfterLoadInternal(Stack<ObjectModel> objectModels)
{
base.AfterLoadInternal(objectModels);
AbstractSyntaxObjectModel asn = (objectModels.Pop() as AbstractSyntaxObjectModel);
SecurityCertificateObjectModel cer = (objectModels.Pop() as SecurityCertificateObjectModel);
}
protected override void BeforeSaveInternal(Stack<ObjectModel> objectModels)
{
base.BeforeSaveInternal(objectModels);
SecurityCertificateObjectModel cer = (objectModels.Pop() as SecurityCertificateObjectModel);
AbstractSyntaxObjectModel asn = new AbstractSyntaxObjectModel();
objectModels.Push(asn);
}
}
}

View File

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace UniversalEditor.ObjectModels.AbstractSyntax
{
public class AbstractSyntaxObjectModel : ObjectModel
{
public override void Clear()
{
throw new NotImplementedException();
}
public override void CopyTo(ObjectModel where)
{
throw new NotImplementedException();
}
}
}

View File

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace UniversalEditor.ObjectModels.SecurityCertificate
{
public class SecurityCertificateObjectModel : ObjectModel
{
private static ObjectModelReference _omr = null;
public override ObjectModelReference MakeReference()
{
if (_omr == null)
{
_omr = base.MakeReference();
_omr.Title = "Security certificate";
_omr.Path = new string[] { "Security", "Certificate" };
}
return _omr;
}
public override void Clear()
{
}
public override void CopyTo(ObjectModel where)
{
}
}
}

View File

@ -44,6 +44,7 @@
<Compile Include="Common\Reflection.cs" />
<Compile Include="Condition.cs" />
<Compile Include="Converter.cs" />
<Compile Include="DataFormats\AbstractSyntax\DER\DERDataFormat.cs" />
<Compile Include="DataFormats\Chunked\REV\REVDataFormat.cs" />
<Compile Include="DataFormats\Chunked\RIFF\RIFFDataFormat.cs" />
<Compile Include="DataFormats\FileSystem\UXT\Internal\FileInfo.cs" />
@ -60,10 +61,12 @@
<Compile Include="DataFormats\PropertyList\UniversalPropertyList\VariantType.cs" />
<Compile Include="DataFormats\PropertyList\WindowsConfigurationDataFormat.cs" />
<Compile Include="DataFormats\PropertyList\XML\XMLPropertyListDataFormat.cs" />
<Compile Include="DataFormats\SecurityCertificate\DER\DERCertificateDataFormat.cs" />
<Compile Include="DataFormats\Shortcut\FreeDesktop\DesktopShortcutAction.cs" />
<Compile Include="DataFormats\Shortcut\FreeDesktop\DesktopShortcutDataFormat.cs" />
<Compile Include="DataFormats\Shortcut\FreeDesktop\DesktopShortcutStartupNotifyBehavior.cs" />
<Compile Include="DataFormats\Shortcut\FreeDesktop\DesktopShortcutType.cs" />
<Compile Include="ObjectModels\AbstractSyntax\AbstractSyntaxObjectModel.cs" />
<Compile Include="ObjectModels\Chunked\ChunkedObjectModel.cs" />
<Compile Include="ObjectModels\Chunked\RIFFChunk.cs" />
<Compile Include="ObjectModels\Chunked\RIFFDataChunk.cs" />
@ -95,6 +98,7 @@
<Compile Include="ObjectModels\Project\ProjectFileSystem.cs" />
<Compile Include="ObjectModels\Project\ProjectFolder.cs" />
<Compile Include="ObjectModels\Project\Reference.cs" />
<Compile Include="ObjectModels\SecurityCertificate\SecurityCertificateObjectModel.cs" />
<Compile Include="ObjectModels\Shortcut\ShortcutObjectModel.cs" />
<Compile Include="ObjectModels\Solution\SolutionObjectModel.cs" />
<Compile Include="ObjectModels\Text\Formatted\FormattedTextObjectModel.cs" />