Пример #1
0
        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:
                return(DerObjectIdentifier.FromOctetString(GetBuffer(defIn, tmpBuffers)));
            }

            byte[] bytes = defIn.ToArray();

            switch (tagNo)
            {
            case Asn1Tags.Integer:
                return(new DerInteger(bytes));

            case Asn1Tags.OctetString:
                return(new DerOctetString(bytes));

            case Asn1Tags.Null:
                return(DerNull.Instance);                          // actual content is ignored (enforce 0 length?)

            default:
                throw new IOException("unknown tag " + tagNo + " encountered");
            }
        }
Пример #2
0
        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);
        }