public void DerAsnInteger_Parse_ShouldDecodeCorrectly() { var data = new byte[] { 0x02, 0x81, 0x80, 0x47, 0xeb, 0x99, 0x5a, 0xdf, 0x9e, 0x70, 0x0d, 0xfb, 0xa7, 0x31, 0x32, 0xc1, 0x5f, 0x5c, 0x24, 0xc2, 0xe0, 0xbf, 0xc6, 0x24, 0xaf, 0x15, 0x66, 0x0e, 0xb8, 0x6a, 0x2e, 0xab, 0x2b, 0xc4, 0x97, 0x1f, 0xe3, 0xcb, 0xdc, 0x63, 0xa5, 0x25, 0xec, 0xc7, 0xb4, 0x28, 0x61, 0x66, 0x36, 0xa1, 0x31, 0x1b, 0xbf, 0xdd, 0xd0, 0xfc, 0xbf, 0x17, 0x94, 0x90, 0x1d, 0xe5, 0x5e, 0xc7, 0x11, 0x5e, 0xc9, 0x55, 0x9f, 0xeb, 0xa3, 0x3e, 0x14, 0xc7, 0x99, 0xa6, 0xcb, 0xba, 0xa1, 0x46, 0x0f, 0x39, 0xd4, 0x44, 0xc4, 0xc8, 0x4b, 0x76, 0x0e, 0x20, 0x5d, 0x6d, 0xa9, 0x34, 0x9e, 0xd4, 0xd5, 0x87, 0x42, 0xeb, 0x24, 0x26, 0x51, 0x14, 0x90, 0xb4, 0x0f, 0x06, 0x5e, 0x52, 0x88, 0x32, 0x7a, 0x95, 0x20, 0xa0, 0xfd, 0xf7, 0xe5, 0x7d, 0x60, 0xdd, 0x72, 0x68, 0x9b, 0xf5, 0x7b, 0x05, 0x8f, 0x6d, 0x1e }; var type = DerAsnType.Parse(data); Assert.That(type is DerAsnInteger, Is.True); var integerType = type as DerAsnInteger; Assert.That(integerType.Value as byte[], Is.EqualTo(data.Skip(3).ToArray())); Assert.That(integerType.Unsigned, Is.False); integerType = DerAsnType.Parse(new byte[] { 0x02, 0x02, 0x00, 0x83 }) as DerAsnInteger; Assert.That(integerType.Value as byte[], Is.EqualTo(new byte[] { 0x83 })); Assert.That(integerType.Unsigned, Is.True); integerType = DerAsnType.Parse(new byte[] { 0x02, 0x02, 0x83, 0x40 }) as DerAsnInteger; Assert.That(integerType.Value as byte[], Is.EqualTo(new byte[] { 0x83, 0x40 })); Assert.That(integerType.Unsigned, Is.False); integerType = DerAsnType.Parse(new byte[] { 0x02, 0x01, 0x45 }) as DerAsnInteger; Assert.That(integerType.Value as byte[], Is.EqualTo(new byte[] { 0x45 })); Assert.That(integerType.Unsigned, Is.False); }
public void DerAsnBoolean_Parse_ShouldDecodeCorrectly() { var dataFalse = new byte[] { 0x01, 0x01, 0x00 }; var dataTrue = new byte[] { 0x01, 0x01, 0x07 }; var type = DerAsnType.Parse(dataFalse); Assert.That(type is DerAsnBoolean, Is.True); Assert.That((bool)type.Value, Is.False); type = DerAsnType.Parse(dataTrue); Assert.That(type is DerAsnBoolean, Is.True); Assert.That((bool)type.Value, Is.True); }
public void DerAsnOctetString_Parse_ShouldDecodeCorrectly() { var data = new byte[] { 0x04, 0x0A, 0x1E, 0x08, 0x00, 0x55, 0x00, 0x73, 0x00, 0x65, 0x00, 0x72 }; var type = DerAsnType.Parse(data); Assert.That(type is DerAsnOctetString, Is.True); Assert.That(type.Value, Is.EqualTo(data.Skip(2).ToArray())); }
public void DerAsnObjectIdentifier_Parse_ShouldDecodeCorrectly() { var data = new byte[] { 0x06, 0x09, 0x2B, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x15, 0x14 }; var type = DerAsnType.Parse(data); Assert.That(type is DerAsnObjectIdentifier, Is.True); var objectIdentifier = type as DerAsnObjectIdentifier; Assert.That(objectIdentifier.Value, Is.EqualTo("1.3.6.1.4.1.311.21.20")); }
public void DerAsnSequence_Parse_ShouldDecodeCorrectly() { var data = new byte[] { 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01, 0x05, 0x00 }; var type = DerAsnType.Parse(data); Assert.That(type is DerAsnSequence, Is.True); var items = type.Value as DerAsnType[]; Assert.That(items, Is.Not.Null); Assert.That(items[0] is DerAsnObjectIdentifier, Is.True); Assert.That(items[0].Value, Is.EqualTo("1.2.840.113549.1.1.1")); Assert.That(items[1] is DerAsnNull, Is.True); }
public void DerAsnBitString_Parse_ShouldDecodeCorrectly() { var data = new byte[] { 0x03, 0x81, 0x81, 0x05, 0x47, 0xeb, 0x99, 0x5a, 0xdf, 0x9e, 0x70, 0x0d, 0xfb, 0xa7, 0x31, 0x32, 0xc1, 0x5f, 0x5c, 0x24, 0xc2, 0xe0, 0xbf, 0xc6, 0x24, 0xaf, 0x15, 0x66, 0x0e, 0xb8, 0x6a, 0x2e, 0xab, 0x2b, 0xc4, 0x97, 0x1f, 0xe3, 0xcb, 0xdc, 0x63, 0xa5, 0x25, 0xec, 0xc7, 0xb4, 0x28, 0x61, 0x66, 0x36, 0xa1, 0x31, 0x1b, 0xbf, 0xdd, 0xd0, 0xfc, 0xbf, 0x17, 0x94, 0x90, 0x1d, 0xe5, 0x5e, 0xc7, 0x11, 0x5e, 0xc9, 0x55, 0x9f, 0xeb, 0xa3, 0x3e, 0x14, 0xc7, 0x99, 0xa6, 0xcb, 0xba, 0xa1, 0x46, 0x0f, 0x39, 0xd4, 0x44, 0xc4, 0xc8, 0x4b, 0x76, 0x0e, 0x20, 0x5d, 0x6d, 0xa9, 0x34, 0x9e, 0xd4, 0xd5, 0x87, 0x42, 0xeb, 0x24, 0x26, 0x51, 0x14, 0x90, 0xb4, 0x0f, 0x06, 0x5e, 0x52, 0x88, 0x32, 0x7a, 0x95, 0x20, 0xa0, 0xfd, 0xf7, 0xe5, 0x7d, 0x60, 0xdd, 0x72, 0x68, 0x9b, 0xf5, 0x7b, 0x05, 0x8f, 0x6d, 0x1e }; var type = DerAsnType.Parse(data); Assert.That(type is DerAsnBitString, Is.True); var bitString = type as DerAsnBitString; Assert.That(bitString.UnusedLowerBitsInLastByte, Is.EqualTo(0x05)); Assert.That((bitString.Value as byte[]), Is.EqualTo(data.Skip(4).ToArray())); }
public static DerAsnType Decode(byte[] data) => DerAsnType.Parse(data);
public void DerAsnNull_Parse_ShouldDecodeCorrectly() { var type = DerAsnType.Parse(new byte[] { 0x05, 0x00 }); Assert.That(type is DerAsnNull, Is.True); }