/** * build an object given its tag and the number of bytes to construct it from. */ private Asn1Object BuildObject( int tag, int tagNo, int length) { bool isConstructed = (tag & Asn1Tags.Constructed) != 0; DefiniteLengthInputStream defIn = new DefiniteLengthInputStream(this.s, length); if ((tag & Asn1Tags.Application) != 0) { throw new IOException("invalid ECDSA sig"); } if ((tag & Asn1Tags.Tagged) != 0) { throw new IOException("invalid ECDSA sig"); } if (isConstructed) { switch (tagNo) { case Asn1Tags.Sequence: return(CreateDerSequence(defIn)); default: throw new IOException("unknown tag " + tagNo + " encountered"); } } return(CreatePrimitiveDerObject(tagNo, defIn, tmpBuffers)); }
internal static Asn1Object CreatePrimitiveDerObject( int tagNo, DefiniteLengthInputStream defIn, byte[][] tmpBuffers) { switch (tagNo) { case Asn1Tags.Boolean: throw new IOException("invalid ECDSA sig"); case Asn1Tags.Enumerated: throw new IOException("invalid ECDSA sig"); case Asn1Tags.ObjectIdentifier: throw new IOException("invalid ECDSA sig"); } byte[] bytes = defIn.ToArray(); switch (tagNo) { case Asn1Tags.Integer: return(new DerInteger(bytes)); default: throw new IOException("unknown tag " + tagNo + " encountered"); } }
internal static byte[] GetBuffer(DefiniteLengthInputStream defIn, byte[][] tmpBuffers) { int len = defIn.GetRemaining(); if (len >= tmpBuffers.Length) { return(defIn.ToArray()); } byte[] buf = tmpBuffers[len]; if (buf == null) { buf = tmpBuffers[len] = new byte[len]; } defIn.ReadAllIntoByteArray(buf); return(buf); }
internal virtual DerSequence CreateDerSequence( DefiniteLengthInputStream dIn) { return(DerSequence.FromVector(BuildDerEncodableVector(dIn))); }
internal virtual Asn1EncodableVector BuildDerEncodableVector( DefiniteLengthInputStream dIn) { return(new Asn1InputStream(dIn).BuildEncodableVector()); }