internal static void Decode <T>(AsnReader reader, Asn1Tag expectedTag, out T decoded) where T : KrbDiffieHellmanValidationParameters, new() { if (reader == null) { throw new ArgumentNullException(nameof(reader)); } decoded = new T(); AsnReader sequenceReader = reader.ReadSequence(expectedTag); if (sequenceReader.TryReadPrimitiveBitStringValue(out _, out ReadOnlyMemory <byte> tmpSeed)) { decoded.Seed = tmpSeed; } else { decoded.Seed = sequenceReader.ReadBitString(out _); } decoded.PGenOutput = sequenceReader.ReadInteger(); sequenceReader.ThrowIfNotEmpty(); }
public static void GetDiminutiveBigInteger(PublicEncodingRules ruleSet) { // GetBigInteger with the last byte removed. // Since it is no longer an ArrayPool alignment size the fill code gets tested on netstandard. byte[] inputData = ( "0282010000A46861FA9D5DB763633BF5A64EF6E7C2C2367F48D2D46643A22DFC" + "FCCB24E58A14D0F06BDC956437F2A56BA4BEF70BA361BF12964A0D665AFD84B0" + "F7494C8FA4ABC5FCA2E017C06178AEF2CDAD1B5F18E997A14B965C074E8F5649" + "70607276B00583932240FE6E2DD013026F9AE13D7C91CC07C4E1E8E87737DC06" + "EF2B575B89D62EFE46859F8255A123692A706C68122D4DAFE11CB205A7B3DE06" + "E553F7B95F978EF8601A8DF819BF32040BDF92A0DE0DF269B4514282E17AC699" + "34E8440A48AB9D1F5DF89A502CEF6DFDBE790045BD45E0C94E5CA8ADD76A013E" + "9C978440FC8A9E2A9A4940B2460819C3E302AA9C9F355AD754C86D3ED77DDAA3" + "DA13810B").HexToByteArray(); BigInteger expected = BigInteger.Parse( "2075455505718444046766086325128514549301113944667492053189486607" + "5638152321436011512404808361119326026027238444019992518081753153" + "5965931647037093368608713442955529617501657176146245891571745113" + "4028700771890451167051818999837042261788828826028681595867897235" + "7967091503500375497498573022675671178275171110498592645868107163" + "8525996766798322809764200941677343791419428587801897366593842552" + "7272226864578661449281241619675217353931828233756506947863330597" + "8338073826285687331647183058971791153730741973483420110408271570" + "1367336140572971505716740825623220507359429297584634909330541150" + "79473593821332264673455059897928082590541") >> 8; AsnReader reader = new AsnReader(inputData, (AsnEncodingRules)ruleSet); Assert.Equal(expected, reader.ReadInteger()); }
public static void GetNegativeBigInteger(PublicEncodingRules ruleSet) { // This uses a length that doesn't line up with the array pool size so // the fill code gets tested on netstandard. // It's the same data as above, minus the padding and lead byte (and the // next byte changed from 0x68 to 0x88) byte[] inputData = ( "0281FF8861FA9D5DB763633BF5A64EF6E7C2C2367F48D2D46643A22DFC" + "FCCB24E58A14D0F06BDC956437F2A56BA4BEF70BA361BF12964A0D665AFD84B0" + "F7494C8FA4ABC5FCA2E017C06178AEF2CDAD1B5F18E997A14B965C074E8F5649" + "70607276B00583932240FE6E2DD013026F9AE13D7C91CC07C4E1E8E87737DC06" + "EF2B575B89D62EFE46859F8255A123692A706C68122D4DAFE11CB205A7B3DE06" + "E553F7B95F978EF8601A8DF819BF32040BDF92A0DE0DF269B4514282E17AC699" + "34E8440A48AB9D1F5DF89A502CEF6DFDBE790045BD45E0C94E5CA8ADD76A013E" + "9C978440FC8A9E2A9A4940B2460819C3E302AA9C9F355AD754C86D3ED77DDAA3" + "DA13810B4D").HexToByteArray(); BigInteger expected = BigInteger.Parse( "-" + "5898547409447487884446992857601985651316300515844052200158198046" + "7814538020408452501006415149581619776188797413593169277984980446" + "1302361382932378450492052337986628823880000831383555853860116718" + "5361729331647715885538858385106930514758305144777880150203212976" + "6715081632226412951106013360243549075631850526067219857352295397" + "2308328327377769665309386917336850273904442596855844458638806936" + "6169824439111394938336579524651037239551388910737675470211780509" + "8035477769907389338548451561341965157059382875181284370047601682" + "6924486017215979427815833587119797658480104671279234402026468966" + "86109928634475300812601680679147599027"); AsnReader reader = new AsnReader(inputData, (AsnEncodingRules)ruleSet); Assert.Equal(expected, reader.ReadInteger()); }
public SearchRequest TryDecode(AsnReader reader, byte[] input) { SearchRequest searchRequest = new SearchRequest { RawPacket = input, }; Asn1Tag bindRequestApplication = new Asn1Tag(TagClass.Application, 3); AsnReader subReader = reader.ReadSequence(bindRequestApplication); searchRequest.BaseObject = System.Text.Encoding.ASCII.GetString(subReader.ReadOctetString()); SearchRequest.ScopeEnum scope = subReader.ReadEnumeratedValue <SearchRequest.ScopeEnum>(); SearchRequest.DerefAliasesEnum deref = subReader.ReadEnumeratedValue <SearchRequest.DerefAliasesEnum>(); BigInteger sizeLimit = subReader.ReadInteger(); BigInteger timeLimit = subReader.ReadInteger(); bool typesOnly = subReader.ReadBoolean(); searchRequest.Filter = DecodeSearchFilter(subReader); return(searchRequest); }
public LdapMessage TryParsePacket(byte[] input) { AsnReader reader = new AsnReader(input, AsnEncodingRules.BER); AsnReader sequenceReader = reader.ReadSequence(); BigInteger messageId = sequenceReader.ReadInteger(); TagClass tagClass = sequenceReader.PeekTag().TagClass; int tagValue = sequenceReader.PeekTag().TagValue; if (tagClass != TagClass.Application) { throw new ArgumentException("Input type is expected to be " + TagClass.Application + " but was " + tagClass); } IProtocolOp message = DecodeApplicationData(tagValue, sequenceReader, input); return(new LdapMessage(messageId, message)); }
public BindRequest TryDecode(AsnReader reader, byte[] input) { Asn1Tag bindRequestApplication = new Asn1Tag(TagClass.Application, 0); AsnReader subReader = reader.ReadSequence(bindRequestApplication); BigInteger version = subReader.ReadInteger(); string nameString = System.Text.Encoding.ASCII.GetString(subReader.ReadOctetString()); Asn1Tag authContext = new Asn1Tag(TagClass.ContextSpecific, 0); string authString = System.Text.Encoding.ASCII.GetString(subReader.ReadOctetString(authContext)); subReader.ThrowIfNotEmpty(); reader.ThrowIfNotEmpty(); BindRequest bindRequest = new BindRequest(version, nameString, authString); return(bindRequest); }
/// <summary> /// Decode CRL Number. /// </summary> private void Decode(byte[] data) { if (base.Oid.Value == CrlNumberOid) { try { AsnReader dataReader = new AsnReader(data, AsnEncodingRules.DER); CrlNumber = dataReader.ReadInteger(); dataReader.ThrowIfNotEmpty(); } catch (AsnContentException ace) { throw new CryptographicException("Failed to decode the CRL Number extension.", ace); } } else { throw new CryptographicException("Invalid CrlNumberOid."); } }
internal static void Decode(AsnReader reader, Asn1Tag expectedTag, out CertificationRequestInfoAsn decoded) { if (reader == null) { throw new ArgumentNullException(nameof(reader)); } decoded = default; AsnReader sequenceReader = reader.ReadSequence(expectedTag); AsnReader collectionReader; decoded.Version = sequenceReader.ReadInteger(); if (!sequenceReader.PeekTag().HasSameClassAndValue(new Asn1Tag((UniversalTagNumber)16))) { throw new CryptographicException(); } decoded.Subject = sequenceReader.ReadEncodedValue(); System.Security.Cryptography.Asn1.SubjectPublicKeyInfoAsn.Decode(sequenceReader, out decoded.SubjectPublicKeyInfo); // Decode SEQUENCE OF for Attributes { collectionReader = sequenceReader.ReadSetOf(new Asn1Tag(TagClass.ContextSpecific, 0)); var tmpList = new List <System.Security.Cryptography.Asn1.AttributeAsn>(); System.Security.Cryptography.Asn1.AttributeAsn tmpItem; while (collectionReader.HasData) { System.Security.Cryptography.Asn1.AttributeAsn.Decode(collectionReader, out tmpItem); tmpList.Add(tmpItem); } decoded.Attributes = tmpList.ToArray(); } sequenceReader.ThrowIfNotEmpty(); }