Namespace ASN models until Models is updated

This commit is contained in:
Matt Nadareski
2025-09-24 10:40:30 -04:00
parent ad7508c464
commit 4f8751667a
6 changed files with 41 additions and 40 deletions

View File

@@ -1,5 +1,5 @@
using System;
using SabreTools.Serialization.ASN1;
using SabreTools.Models.ASN1;
using SabreTools.Serialization.Extensions;
using Xunit;
@@ -13,7 +13,7 @@ namespace SabreTools.Serialization.Test.Extensions
public void Format_EOC()
{
string expected = "Type: V_ASN1_EOC";
var tlv = new Serialization.ASN1.TypeLengthValue { Type = ASN1Type.V_ASN1_EOC, Length = 0, Value = null };
var tlv = new Models.ASN1.TypeLengthValue { Type = ASN1Type.V_ASN1_EOC, Length = 0, Value = null };
string actual = tlv.Format();
Assert.Equal(expected, actual);
}
@@ -22,7 +22,7 @@ namespace SabreTools.Serialization.Test.Extensions
public void Format_ZeroLength()
{
string expected = "Type: V_ASN1_NULL, Length: 0";
var tlv = new Serialization.ASN1.TypeLengthValue { Type = ASN1Type.V_ASN1_NULL, Length = 0, Value = null };
var tlv = new Models.ASN1.TypeLengthValue { Type = ASN1Type.V_ASN1_NULL, Length = 0, Value = null };
string actual = tlv.Format();
Assert.Equal(expected, actual);
}
@@ -31,7 +31,7 @@ namespace SabreTools.Serialization.Test.Extensions
public void Format_InvalidConstructed()
{
string expected = "Type: V_ASN1_OBJECT, V_ASN1_CONSTRUCTED, Length: 1, Value: [INVALID DATA TYPE]";
var tlv = new Serialization.ASN1.TypeLengthValue { Type = ASN1Type.V_ASN1_OBJECT | ASN1Type.V_ASN1_CONSTRUCTED, Length = 1, Value = (object?)false };
var tlv = new Models.ASN1.TypeLengthValue { Type = ASN1Type.V_ASN1_OBJECT | ASN1Type.V_ASN1_CONSTRUCTED, Length = 1, Value = (object?)false };
string actual = tlv.Format();
Assert.Equal(expected, actual);
}
@@ -40,8 +40,8 @@ namespace SabreTools.Serialization.Test.Extensions
public void Format_ValidConstructed()
{
string expected = "Type: V_ASN1_OBJECT, V_ASN1_CONSTRUCTED, Length: 3, Value:\n Type: V_ASN1_BOOLEAN, Length: 1, Value: True";
var boolTlv = new Serialization.ASN1.TypeLengthValue { Type = ASN1Type.V_ASN1_BOOLEAN, Length = 1, Value = new byte[] { 0x01 } };
var tlv = new Serialization.ASN1.TypeLengthValue { Type = ASN1Type.V_ASN1_OBJECT | ASN1Type.V_ASN1_CONSTRUCTED, Length = 3, Value = new Serialization.ASN1.TypeLengthValue[] { boolTlv } };
var boolTlv = new Models.ASN1.TypeLengthValue { Type = ASN1Type.V_ASN1_BOOLEAN, Length = 1, Value = new byte[] { 0x01 } };
var tlv = new Models.ASN1.TypeLengthValue { Type = ASN1Type.V_ASN1_OBJECT | ASN1Type.V_ASN1_CONSTRUCTED, Length = 3, Value = new Models.ASN1.TypeLengthValue[] { boolTlv } };
string actual = tlv.Format();
Assert.Equal(expected, actual);
}
@@ -50,7 +50,7 @@ namespace SabreTools.Serialization.Test.Extensions
public void Format_InvalidDataType()
{
string expected = "Type: V_ASN1_OBJECT, Length: 1, Value: [INVALID DATA TYPE]";
var tlv = new Serialization.ASN1.TypeLengthValue { Type = ASN1Type.V_ASN1_OBJECT, Length = 1, Value = (object?)false };
var tlv = new Models.ASN1.TypeLengthValue { Type = ASN1Type.V_ASN1_OBJECT, Length = 1, Value = (object?)false };
string actual = tlv.Format();
Assert.Equal(expected, actual);
}
@@ -59,7 +59,7 @@ namespace SabreTools.Serialization.Test.Extensions
public void Format_InvalidLength()
{
string expected = "Type: V_ASN1_NULL, Length: 1, Value: [NO DATA]";
var tlv = new Serialization.ASN1.TypeLengthValue { Type = ASN1Type.V_ASN1_NULL, Length = 1, Value = Array.Empty<byte>() };
var tlv = new Models.ASN1.TypeLengthValue { Type = ASN1Type.V_ASN1_NULL, Length = 1, Value = Array.Empty<byte>() };
string actual = tlv.Format();
Assert.Equal(expected, actual);
}
@@ -68,7 +68,7 @@ namespace SabreTools.Serialization.Test.Extensions
public void Format_InvalidBooleanLength()
{
string expected = "Type: V_ASN1_BOOLEAN, Length: 2 [Expected length of 1], Value: True";
var tlv = new Serialization.ASN1.TypeLengthValue { Type = ASN1Type.V_ASN1_BOOLEAN, Length = 2, Value = new byte[] { 0x01 } };
var tlv = new Models.ASN1.TypeLengthValue { Type = ASN1Type.V_ASN1_BOOLEAN, Length = 2, Value = new byte[] { 0x01 } };
string actual = tlv.Format();
Assert.Equal(expected, actual);
}
@@ -77,7 +77,7 @@ namespace SabreTools.Serialization.Test.Extensions
public void Format_InvalidBooleanArrayLength()
{
string expected = "Type: V_ASN1_BOOLEAN, Length: 1 [Expected value length of 1], Value: True";
var tlv = new Serialization.ASN1.TypeLengthValue { Type = ASN1Type.V_ASN1_BOOLEAN, Length = 1, Value = new byte[] { 0x01, 0x00 } };
var tlv = new Models.ASN1.TypeLengthValue { Type = ASN1Type.V_ASN1_BOOLEAN, Length = 1, Value = new byte[] { 0x01, 0x00 } };
string actual = tlv.Format();
Assert.Equal(expected, actual);
}
@@ -86,7 +86,7 @@ namespace SabreTools.Serialization.Test.Extensions
public void Format_ValidBoolean()
{
string expected = "Type: V_ASN1_BOOLEAN, Length: 1, Value: True";
var tlv = new Serialization.ASN1.TypeLengthValue { Type = ASN1Type.V_ASN1_BOOLEAN, Length = 1, Value = new byte[] { 0x01 } };
var tlv = new Models.ASN1.TypeLengthValue { Type = ASN1Type.V_ASN1_BOOLEAN, Length = 1, Value = new byte[] { 0x01 } };
string actual = tlv.Format();
Assert.Equal(expected, actual);
}
@@ -95,7 +95,7 @@ namespace SabreTools.Serialization.Test.Extensions
public void Format_ValidInteger()
{
string expected = "Type: V_ASN1_INTEGER, Length: 1, Value: 1";
var tlv = new Serialization.ASN1.TypeLengthValue { Type = ASN1Type.V_ASN1_INTEGER, Length = 1, Value = new byte[] { 0x01 } };
var tlv = new Models.ASN1.TypeLengthValue { Type = ASN1Type.V_ASN1_INTEGER, Length = 1, Value = new byte[] { 0x01 } };
string actual = tlv.Format();
Assert.Equal(expected, actual);
}
@@ -104,7 +104,7 @@ namespace SabreTools.Serialization.Test.Extensions
public void Format_ValidBitString_NoBits()
{
string expected = "Type: V_ASN1_BIT_STRING, Length: 1, Value with 0 unused bits";
var tlv = new Serialization.ASN1.TypeLengthValue { Type = ASN1Type.V_ASN1_BIT_STRING, Length = 1, Value = new byte[] { 0x00 } };
var tlv = new Models.ASN1.TypeLengthValue { Type = ASN1Type.V_ASN1_BIT_STRING, Length = 1, Value = new byte[] { 0x00 } };
string actual = tlv.Format();
Assert.Equal(expected, actual);
}
@@ -113,7 +113,7 @@ namespace SabreTools.Serialization.Test.Extensions
public void Format_ValidBitString_Bits()
{
string expected = "Type: V_ASN1_BIT_STRING, Length: 1, Value with 1 unused bits: 01";
var tlv = new Serialization.ASN1.TypeLengthValue { Type = ASN1Type.V_ASN1_BIT_STRING, Length = 1, Value = new byte[] { 0x01, 0x01 } };
var tlv = new Models.ASN1.TypeLengthValue { Type = ASN1Type.V_ASN1_BIT_STRING, Length = 1, Value = new byte[] { 0x01, 0x01 } };
string actual = tlv.Format();
Assert.Equal(expected, actual);
}
@@ -122,7 +122,7 @@ namespace SabreTools.Serialization.Test.Extensions
public void Format_ValidOctetString()
{
string expected = "Type: V_ASN1_OCTET_STRING, Length: 1, Value: 01";
var tlv = new Serialization.ASN1.TypeLengthValue { Type = ASN1Type.V_ASN1_OCTET_STRING, Length = 1, Value = new byte[] { 0x01 } };
var tlv = new Models.ASN1.TypeLengthValue { Type = ASN1Type.V_ASN1_OCTET_STRING, Length = 1, Value = new byte[] { 0x01 } };
string actual = tlv.Format();
Assert.Equal(expected, actual);
}
@@ -131,7 +131,7 @@ namespace SabreTools.Serialization.Test.Extensions
public void Format_ValidObject()
{
string expected = "Type: V_ASN1_OBJECT, Length: 3, Value: 0.1.2.3 (/ITU-T/1/2/3)";
var tlv = new Serialization.ASN1.TypeLengthValue { Type = ASN1Type.V_ASN1_OBJECT, Length = 3, Value = new byte[] { 0x01, 0x02, 0x03 } };
var tlv = new Models.ASN1.TypeLengthValue { Type = ASN1Type.V_ASN1_OBJECT, Length = 3, Value = new byte[] { 0x01, 0x02, 0x03 } };
string actual = tlv.Format();
Assert.Equal(expected, actual);
}
@@ -140,7 +140,7 @@ namespace SabreTools.Serialization.Test.Extensions
public void Format_ValidUTF8String()
{
string expected = "Type: V_ASN1_UTF8STRING, Length: 3, Value: ABC";
var tlv = new Serialization.ASN1.TypeLengthValue { Type = ASN1Type.V_ASN1_UTF8STRING, Length = 3, Value = new byte[] { 0x41, 0x42, 0x43 } };
var tlv = new Models.ASN1.TypeLengthValue { Type = ASN1Type.V_ASN1_UTF8STRING, Length = 3, Value = new byte[] { 0x41, 0x42, 0x43 } };
string actual = tlv.Format();
Assert.Equal(expected, actual);
}
@@ -149,7 +149,7 @@ namespace SabreTools.Serialization.Test.Extensions
public void Format_ValidPrintableString()
{
string expected = "Type: V_ASN1_PRINTABLESTRING, Length: 3, Value: ABC";
var tlv = new Serialization.ASN1.TypeLengthValue { Type = ASN1Type.V_ASN1_PRINTABLESTRING, Length = 3, Value = new byte[] { 0x41, 0x42, 0x43 } };
var tlv = new Models.ASN1.TypeLengthValue { Type = ASN1Type.V_ASN1_PRINTABLESTRING, Length = 3, Value = new byte[] { 0x41, 0x42, 0x43 } };
string actual = tlv.Format();
Assert.Equal(expected, actual);
}
@@ -158,7 +158,7 @@ namespace SabreTools.Serialization.Test.Extensions
public void Format_ValidTeletexString()
{
string expected = "Type: V_ASN1_TELETEXSTRING, Length: 3, Value: ABC";
var tlv = new Serialization.ASN1.TypeLengthValue { Type = ASN1Type.V_ASN1_TELETEXSTRING, Length = 3, Value = new byte[] { 0x41, 0x42, 0x43 } };
var tlv = new Models.ASN1.TypeLengthValue { Type = ASN1Type.V_ASN1_TELETEXSTRING, Length = 3, Value = new byte[] { 0x41, 0x42, 0x43 } };
string actual = tlv.Format();
Assert.Equal(expected, actual);
}
@@ -167,7 +167,7 @@ namespace SabreTools.Serialization.Test.Extensions
public void Format_ValidIA5String()
{
string expected = "Type: V_ASN1_IA5STRING, Length: 3, Value: ABC";
var tlv = new Serialization.ASN1.TypeLengthValue { Type = ASN1Type.V_ASN1_IA5STRING, Length = 3, Value = new byte[] { 0x41, 0x42, 0x43 } };
var tlv = new Models.ASN1.TypeLengthValue { Type = ASN1Type.V_ASN1_IA5STRING, Length = 3, Value = new byte[] { 0x41, 0x42, 0x43 } };
string actual = tlv.Format();
Assert.Equal(expected, actual);
}
@@ -176,7 +176,7 @@ namespace SabreTools.Serialization.Test.Extensions
public void Format_InvalidUTCTime()
{
string expected = "Type: V_ASN1_UTCTIME, Length: 3, Value: ABC";
var tlv = new Serialization.ASN1.TypeLengthValue { Type = ASN1Type.V_ASN1_UTCTIME, Length = 3, Value = new byte[] { 0x41, 0x42, 0x43 } };
var tlv = new Models.ASN1.TypeLengthValue { Type = ASN1Type.V_ASN1_UTCTIME, Length = 3, Value = new byte[] { 0x41, 0x42, 0x43 } };
string actual = tlv.Format();
Assert.Equal(expected, actual);
}
@@ -185,7 +185,7 @@ namespace SabreTools.Serialization.Test.Extensions
public void Format_ValidUTCTime()
{
string expected = "Type: V_ASN1_UTCTIME, Length: 3, Value: 1980-01-01 00:00:00";
var tlv = new Serialization.ASN1.TypeLengthValue { Type = ASN1Type.V_ASN1_UTCTIME, Length = 3, Value = new byte[] { 0x31, 0x39, 0x38, 0x30, 0x2D, 0x30, 0x31, 0x2D, 0x30, 0x31, 0x20, 0x30, 0x30, 0x3A, 0x30, 0x30, 0x3A, 0x30, 0x30 } };
var tlv = new Models.ASN1.TypeLengthValue { Type = ASN1Type.V_ASN1_UTCTIME, Length = 3, Value = new byte[] { 0x31, 0x39, 0x38, 0x30, 0x2D, 0x30, 0x31, 0x2D, 0x30, 0x31, 0x20, 0x30, 0x30, 0x3A, 0x30, 0x30, 0x3A, 0x30, 0x30 } };
string actual = tlv.Format();
Assert.Equal(expected, actual);
}
@@ -194,7 +194,7 @@ namespace SabreTools.Serialization.Test.Extensions
public void Format_ValidBmpString()
{
string expected = "Type: V_ASN1_BMPSTRING, Length: 6, Value: ABC";
var tlv = new Serialization.ASN1.TypeLengthValue { Type = ASN1Type.V_ASN1_BMPSTRING, Length = 6, Value = new byte[] { 0x41, 0x00, 0x42, 0x00, 0x43, 0x00 } };
var tlv = new Models.ASN1.TypeLengthValue { Type = ASN1Type.V_ASN1_BMPSTRING, Length = 6, Value = new byte[] { 0x41, 0x00, 0x42, 0x00, 0x43, 0x00 } };
string actual = tlv.Format();
Assert.Equal(expected, actual);
}
@@ -203,7 +203,7 @@ namespace SabreTools.Serialization.Test.Extensions
public void Format_ValidUnformatted()
{
string expected = "Type: V_ASN1_OBJECT_DESCRIPTOR, Length: 1, Value: 01";
var tlv = new Serialization.ASN1.TypeLengthValue { Type = ASN1Type.V_ASN1_OBJECT_DESCRIPTOR, Length = 1, Value = new byte[] { 0x01 } };
var tlv = new Models.ASN1.TypeLengthValue { Type = ASN1Type.V_ASN1_OBJECT_DESCRIPTOR, Length = 1, Value = new byte[] { 0x01 } };
string actual = tlv.Format();
Assert.Equal(expected, actual);
}

View File

@@ -1,13 +1,14 @@
using System.Collections.Generic;
using System.IO;
using SabreTools.IO.Extensions;
using SabreTools.Models.ASN1;
namespace SabreTools.Serialization.Deserializers
{
public class AbstractSyntaxNotationOne : BaseBinaryDeserializer<ASN1.TypeLengthValue[]>
public class AbstractSyntaxNotationOne : BaseBinaryDeserializer<TypeLengthValue[]>
{
/// <inheritdoc/>
public override ASN1.TypeLengthValue[]? Deserialize(Stream? data)
public override TypeLengthValue[]? Deserialize(Stream? data)
{
// If the data is invalid
if (data == null || !data.CanRead)
@@ -19,7 +20,7 @@ namespace SabreTools.Serialization.Deserializers
long initialOffset = data.Position;
// Loop through the data and return all top-level values
var topLevelValues = new List<ASN1.TypeLengthValue>();
var topLevelValues = new List<TypeLengthValue>();
while (data.Position < data.Length)
{
var topLevelValue = ParseTypeLengthValue(data);
@@ -48,15 +49,15 @@ namespace SabreTools.Serialization.Deserializers
/// </summary>
/// <param name="data">Stream to parse</param>
/// <returns>Filled TypeLengthValue on success, null on error</returns>
public ASN1.TypeLengthValue? ParseTypeLengthValue(Stream data)
public TypeLengthValue? ParseTypeLengthValue(Stream data)
{
var obj = new ASN1.TypeLengthValue();
var obj = new TypeLengthValue();
// Get the type and modifiers
obj.Type = (ASN1.ASN1Type)data.ReadByteValue();
obj.Type = (ASN1Type)data.ReadByteValue();
// If we have an end indicator, we just return
if (obj.Type == ASN1.ASN1Type.V_ASN1_EOC)
if (obj.Type == ASN1Type.V_ASN1_EOC)
return obj;
// Get the length of the value
@@ -69,12 +70,12 @@ namespace SabreTools.Serialization.Deserializers
// Read the value
#if NET20 || NET35
if ((obj.Type & ASN1.ASN1Type.V_ASN1_CONSTRUCTED) != 0)
if ((obj.Type & ASN1Type.V_ASN1_CONSTRUCTED) != 0)
#else
if (obj.Type.HasFlag(ASN1.ASN1Type.V_ASN1_CONSTRUCTED))
if (obj.Type.HasFlag(ASN1Type.V_ASN1_CONSTRUCTED))
#endif
{
var valueList = new List<ASN1.TypeLengthValue>();
var valueList = new List<TypeLengthValue>();
long currentIndex = data.Position;
while (data.Position < currentIndex + (long)obj.Length)

View File

@@ -1,6 +1,7 @@
using System;
using System.Numerics;
using System.Text;
using SabreTools.Models.ASN1;
using SabreTools.Serialization.ASN1;
namespace SabreTools.Serialization.Extensions
@@ -12,7 +13,7 @@ namespace SabreTools.Serialization.Extensions
/// </summary>
/// <param name="paddingLevel">Padding level of the item when formatting</param>
/// <returns>String representing the TypeLengthValue, if possible</returns>
public static string Format(this ASN1.TypeLengthValue tlv, int paddingLevel = 0)
public static string Format(this Models.ASN1.TypeLengthValue tlv, int paddingLevel = 0)
{
// Create the left-padding string
string padding = new(' ', paddingLevel);
@@ -37,7 +38,7 @@ namespace SabreTools.Serialization.Extensions
if (tlv.Type.HasFlag(ASN1Type.V_ASN1_CONSTRUCTED))
#endif
{
if (tlv.Value is not ASN1.TypeLengthValue[] valueAsObjectArray)
if (tlv.Value is not Models.ASN1.TypeLengthValue[] valueAsObjectArray)
{
formatBuilder.Append(", Value: [INVALID DATA TYPE]");
return formatBuilder.ToString();

View File

@@ -7,7 +7,6 @@ using SabreTools.Models.COFF;
using SabreTools.Models.COFF.SymbolTableEntries;
using SabreTools.Models.PortableExecutable;
using SabreTools.Models.PortableExecutable.Resource.Entries;
using SabreTools.Serialization.ASN1;
using SabreTools.Serialization.Extensions;
using SabreTools.Serialization.Interfaces;
@@ -481,7 +480,7 @@ namespace SabreTools.Serialization.Printers
}
else
{
foreach (ASN1.TypeLengthValue tlv in topLevelValues)
foreach (Models.ASN1.TypeLengthValue tlv in topLevelValues)
{
string tlvString = tlv.Format(paddingLevel: 4);
builder.AppendLine(tlvString);

View File

@@ -1,6 +1,6 @@
using System;
namespace SabreTools.Serialization.ASN1
namespace SabreTools.Models.ASN1
{
/// <summary>
/// ASN.1 type indicators

View File

@@ -1,4 +1,4 @@
namespace SabreTools.Serialization.ASN1
namespace SabreTools.Models.ASN1
{
/// <summary>
/// ASN.1 type/length/value class that all types are based on