Skip to content

Commit

Permalink
convert to Net5, convert shared project, make explicit string tags fo…
Browse files Browse the repository at this point in the history
…r constants.
  • Loading branch information
hallambaker committed Dec 8, 2020
1 parent 6111cf8 commit 1596a74
Show file tree
Hide file tree
Showing 75 changed files with 8,142 additions and 440 deletions.
2,022 changes: 2,022 additions & 0 deletions ASN/Goedel.Tool.ASN-core/Asn2.cs

Large diffs are not rendered by default.

87 changes: 87 additions & 0 deletions ASN/Goedel.Tool.ASN-core/Asn2.gdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
Class Goedel.Tool.ASN ASN2

TopType Namespace
Name Token IDName

TopType ROOT
Name ID ArcName
Entries List Entry

Type Entry
Name Token ArcName
Value Integer

TopType OID
Name ID ArcName
Root REF ArcName
Value Integer

TopType Class
Name ID IDName
Entries List Member

TopType Object
Name ID IDName
OID REF ArcName
Entries List Member

TopType SingularObject
Name ID IDName
OID REF ArcName
Entries List Member


Type Member
Name Token IDName
Spec ChoiceREF IDName
OIDRef Any Bits VBits Octets Integer BigInteger Boolean Time
List Set Choice IA5String BMPString UTF8String PrintableString
Qualifiers List Qualifier



Type OIDRef
Type Any

Type Bits
Type VBits

Type Octets

Type Integer
Type BigInteger
Type Boolean
Type Time

Type List
Spec ChoiceREF IDName
OIDRef Any Bits VBits Octets Integer BigInteger Boolean Time
List Set Choice IA5String BMPString UTF8String PrintableString

Type Set
Spec ChoiceREF IDName
OIDRef Any Bits VBits Octets Integer BigInteger Boolean Time
List Set Choice IA5String BMPString UTF8String PrintableString

Type Choice
Entries List Member

Type IA5String
Type BMPString
Type UTF8String
Type PrintableString


Type Qualifier
Entry Choice
Code Implicit Explicit Optional Default Context


Type Code
Value Integer
Type Implicit
Type Explicit
Type Context
Type Optional
Type Default
Value String
202 changes: 202 additions & 0 deletions ASN/Goedel.Tool.ASN-core/AsnPlus.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
using System;
using System.Collections.Generic;
using System.Text;
using Goedel.Registry;
using Goedel.ASN;

namespace Goedel.Tool.ASN {

/// <summary>
/// The core parser
/// </summary>
public partial class ASN2 : Parser {
bool HaveRun = false;

/// <summary>
///
/// </summary>
virtual public void Complete() {
if (!HaveRun) {
HaveRun = true;
foreach (_Choice Entry in Top) {
Entry.Complete();
}
}
}

}


public abstract partial class _Choice {
public List<OID> Children = new List<OID>();

public int[] Binary = null;



virtual public void Complete() {
//Console.WriteLine ("Completing");
}

virtual public void MakeBinary() {
}


protected List<Member> Reverse (List<Member> In ) {
var Array = In.ToArray();
var List2 = new List<Member>(Array);
List2.Reverse();
return List2;
}
}




public partial class Member {

public bool Context = false;
public bool Optional = false;
public bool Implicit = false;
public bool Explicit = false;
public string Default = null;

public int Code = -1;
public int Flags = (int) ASNFlags.Nil;

bool Once = true;

private void SetFlags() => Flags = (int)((Optional ? ASNFlags.Optional : ASNFlags.Nil) |
(Implicit ? ASNFlags.Implicit : ASNFlags.Nil) |
(Explicit ? ASNFlags.Explicit : ASNFlags.Nil) |
(Context ? ASNFlags.Context : ASNFlags.Nil)
);

public override void Complete() {
if (Once) {
foreach (Qualifier Qualifier in Qualifiers) {
_Choice Entry = Qualifier.Entry;

if (Entry._Tag() == ASN2Type.Context) {
Context = true;
}
if (Entry._Tag() == ASN2Type.Implicit) {
Implicit = true;
}
if (Entry._Tag() == ASN2Type.Explicit) {
Explicit = true;
}
if (Entry._Tag() == ASN2Type.Code) {
Code = ((Code)Entry).Value;
}
if (Entry._Tag() == ASN2Type.Optional) {
Optional = true;
}
if (Entry._Tag() == ASN2Type.Default) {
Default = ((Default)Entry).Value;
}
}
SetFlags();

if (Spec._Tag() == ASN2Type.Choice) {
Choice Choice = (Choice) Spec;
foreach (Member Sub in Choice.Entries) {
Sub.Optional = true;
Sub.SetFlags();
}
}

}
Once = false;
}
}

public partial class ROOT {
public override void Complete() {
//Console.WriteLine ("Completing");

if (Binary == null) {
MakeBinary();
}
}

public override void MakeBinary() {

Binary = new int[Entries.Count];
int i = 0;
foreach (Entry Entry in Entries) {
Binary[i++] = Entry.Value;
}
}
}

public partial class OID {
public override void Complete() {
Root.Definition.Children.Add(this);
if (Binary == null) {
MakeBinary();
}
}

public override void MakeBinary() {
if (Root.Definition.Binary == null) {
Root.Definition.MakeBinary();
}

Binary = new int[Root.Definition.Binary.Length + 1];
for (int i = 0; i < Root.Definition.Binary.Length; i++) {
Binary[i] = Root.Definition.Binary[i];
}
Binary[Root.Definition.Binary.Length] = Value;
}
}




public partial class Class {
bool Once = true;
public List<Member> ReversedEntries;

public override void Complete() {
if (Once) {
ReversedEntries = Reverse(Entries);
foreach (Member Member in Entries) {
Member.Complete();
}
}
Once = false;
}
}

public partial class Object {
bool Once = true;
public List<Member> ReversedEntries;

public override void Complete() {
if (Once) {
ReversedEntries = Reverse(Entries);
foreach (Member Member in Entries) {
Member.Complete();
}
}
Once = false;
}
}

public partial class SingularObject {
bool Once = true;
public List<Member> ReversedEntries;

public override void Complete() {
if (Once) {
ReversedEntries = Reverse(Entries);
foreach (Member Member in Entries) {
Member.Complete();
}
}
Once = false;
}
}
}

52 changes: 52 additions & 0 deletions ASN/Goedel.Tool.ASN-core/Design.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title></title>
</head>
<body>

<p>
Design Notes</p>
<p>
Sources</p>
<p>
<a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb540789(v=vs.85).aspx">
http://msdn.microsoft.com/en-us/library/windows/desktop/bb540789(v=vs.85).aspx</a></p>
<p>
&nbsp;</p>
<p>
&nbsp;</p>
<p>
&nbsp;</p>
<p>
OIDs</p>
<p>
Flatten out the OIDs to make them
</p>
<p>
&nbsp;</p>
<p>
Time</p>
<p>
ASN.1 specifies multiple time values, UTCTime and Generalized Time. RFC5280
requires that applications accept either but use UTCTime to encode times before
2050 and Generalized Time thereafter.</p>
<p>
&nbsp;</p>
<p>
&nbsp;</p>
<p>
BitObject / OctetObject</p>
<p>
Sometimes an ASN.1 object is encoded as a BIT string, sometimes as an OCTET
string.
</p>
<p>
BitObject maps to &lt;OID, BIT String&gt;</p>
<p>
OctetObject maps to &lt;OID, [Critical], OCTET STRING&gt;</p>
<p>
&nbsp;</p>

</body>
</html>
Loading

0 comments on commit 1596a74

Please sign in to comment.