Clone() публичный Метод

Creates a duplicate, not a true clone, of this object and returns a reference to the duplicate.
public Clone ( ) : Object
Результат System.Object
Пример #1
0
        /// <summary> Decode an LBER encoded value into an Asn1Object from an InputStream.
        ///
        ///  This method also returns the total length of this encoded
        /// Asn1Object (length of type + length of length + length of content)
        /// in the parameter len. This information is helpful when decoding
        /// structured types.
        /// </summary>
        public virtual Asn1Object decode(System.IO.Stream in_Renamed, int[] len)
        {
            asn1ID.reset(in_Renamed);
            asn1Len.reset(in_Renamed);

            int length = asn1Len.Length;

            len[0] = asn1ID.EncodedLength + asn1Len.EncodedLength + length;

            if (asn1ID.Universal)
            {
                switch (asn1ID.Tag)
                {
                case Asn1Sequence.TAG:
                    return(new Asn1Sequence(this, in_Renamed, length));

                case Asn1Set.TAG:
                    return(new Asn1Set(this, in_Renamed, length));

                case Asn1Boolean.TAG:
                    return(new Asn1Boolean(this, in_Renamed, length));

                case Asn1Integer.TAG:
                    return(new Asn1Integer(this, in_Renamed, length));

                case Asn1OctetString.TAG:
                    return(new Asn1OctetString(this, in_Renamed, length));

                case Asn1Enumerated.TAG:
                    return(new Asn1Enumerated(this, in_Renamed, length));

                case Asn1Null.TAG:
                    return(new Asn1Null());                            // has no content to decode.

                /* Asn1 TYPE NOT YET SUPPORTED
                 * case Asn1BitString.TAG:
                 * return new Asn1BitString(this, in, length);
                 * case Asn1ObjectIdentifier.TAG:
                 * return new Asn1ObjectIdentifier(this, in, length);
                 * case Asn1Real.TAG:
                 * return new Asn1Real(this, in, length);
                 * case Asn1NumericString.TAG:
                 * return new Asn1NumericString(this, in, length);
                 * case Asn1PrintableString.TAG:
                 * return new Asn1PrintableString(this, in, length);
                 * case Asn1TeletexString.TAG:
                 * return new Asn1TeletexString(this, in, length);
                 * case Asn1VideotexString.TAG:
                 * return new Asn1VideotexString(this, in, length);
                 * case Asn1IA5String.TAG:
                 * return new Asn1IA5String(this, in, length);
                 * case Asn1GraphicString.TAG:
                 * return new Asn1GraphicString(this, in, length);
                 * case Asn1VisibleString.TAG:
                 * return new Asn1VisibleString(this, in, length);
                 * case Asn1GeneralString.TAG:
                 * return new Asn1GeneralString(this, in, length);
                 */


                default:
                    throw new System.IO.EndOfStreamException("Unknown tag");                             // !!! need a better exception
                }
            }
            else
            {
                // APPLICATION or CONTEXT-SPECIFIC tag
                return(new Asn1Tagged(this, in_Renamed, length, (Asn1Identifier)asn1ID.Clone()));
            }
        }
        /// <summary>
        ///     Decode an LBER encoded value into an Asn1Object from an InputStream.
        ///     This method also returns the total length of this encoded
        ///     Asn1Object (length of type + length of length + length of content)
        ///     in the parameter len. This information is helpful when decoding
        ///     structured types.
        /// </summary>
        public Asn1Object Decode(Stream inRenamed, int[] len)
        {
            _asn1Id.Reset(inRenamed);
            _asn1Len.Reset(inRenamed);

            var length = _asn1Len.Length;

            len[0] = _asn1Id.EncodedLength + _asn1Len.EncodedLength + length;

            if (_asn1Id.IsUniversal)
            {
                switch (_asn1Id.Tag)
                {
                case Asn1Sequence.Tag:
                    return(new Asn1Sequence(this, inRenamed, length));

                case Asn1Set.Tag:
                    return(new Asn1Set(this, inRenamed, length));

                case Asn1Boolean.Tag:
                    return(new Asn1Boolean(this, inRenamed, length));

                case Asn1Integer.Tag:
                    return(new Asn1Integer(this, inRenamed, length));

                case Asn1OctetString.Tag:
                    return(new Asn1OctetString(this, inRenamed, length));

                case Asn1Enumerated.Tag:
                    return(new Asn1Enumerated(this, inRenamed, length));

                case Asn1Null.Tag:
                    return(new Asn1Null());    // has no content to decode.

                /* Asn1 TYPE NOT YET SUPPORTED
                 * case Asn1BitString.TAG:
                 * return new Asn1BitString(this, in, length);
                 * case Asn1ObjectIdentifier.TAG:
                 * return new Asn1ObjectIdentifier(this, in, length);
                 * case Asn1Real.TAG:
                 * return new Asn1Real(this, in, length);
                 * case Asn1NumericString.TAG:
                 * return new Asn1NumericString(this, in, length);
                 * case Asn1PrintableString.TAG:
                 * return new Asn1PrintableString(this, in, length);
                 * case Asn1TeletexString.TAG:
                 * return new Asn1TeletexString(this, in, length);
                 * case Asn1VideotexString.TAG:
                 * return new Asn1VideotexString(this, in, length);
                 * case Asn1IA5String.TAG:
                 * return new Asn1IA5String(this, in, length);
                 * case Asn1GraphicString.TAG:
                 * return new Asn1GraphicString(this, in, length);
                 * case Asn1VisibleString.TAG:
                 * return new Asn1VisibleString(this, in, length);
                 * case Asn1GeneralString.TAG:
                 * return new Asn1GeneralString(this, in, length);
                 */

                default:
                    throw new EndOfStreamException("Unknown tag");     // !!! need a better exception
                }
            }

            // APPLICATION or CONTEXT-SPECIFIC tag
            return(new Asn1Tagged(this, inRenamed, length, (Asn1Identifier)_asn1Id.Clone()));
        }
        /// <summary>
        ///     Decode an LBER encoded value into an Asn1Object from an InputStream.
        ///     This method also returns the total length of this encoded
        ///     Asn1Object (length of type + length of length + length of content)
        ///     in the parameter len. This information is helpful when decoding
        ///     structured types.
        /// </summary>
        public async ValueTask <Asn1Object> Decode(Stream inRenamed, int[] len, CancellationToken cancellationToken)
        {
            _asn1Id.Reset(inRenamed);
            _asn1Len.Reset(inRenamed);

            var length = _asn1Len.Length;

            len[0] = _asn1Id.EncodedLength + _asn1Len.EncodedLength + length;

            if (_asn1Id.IsUniversal)
            {
                switch (_asn1Id.Tag)
                {
                case Asn1Sequence.Tag:
                    return(new Asn1Sequence(await Asn1Structured.DecodeStructured(this, inRenamed, length, cancellationToken).ConfigureAwait(false)));

                case Asn1Set.Tag:
                    return(new Asn1Set(await Asn1Structured.DecodeStructured(this, inRenamed, length, cancellationToken).ConfigureAwait(false)));

                case Asn1Boolean.Tag:
                    return(new Asn1Boolean(await DecodeBoolean(inRenamed, length, cancellationToken).ConfigureAwait(false)));

                case Asn1Integer.Tag:
                    return(new Asn1Integer(await DecodeNumeric(inRenamed, length, cancellationToken).ConfigureAwait(false)));

                case Asn1OctetString.Tag:
                    return(new Asn1OctetString(length > 0 ? await DecodeOctetString(inRenamed, length, cancellationToken).ConfigureAwait(false) : new byte[0]));

                case Asn1Enumerated.Tag:
                    return(new Asn1Enumerated(await DecodeNumeric(inRenamed, length, cancellationToken).ConfigureAwait(false)));

                case Asn1Null.Tag:
                    return(new Asn1Null());    // has no content to decode.

                /* Asn1 TYPE NOT YET SUPPORTED
                 * case Asn1BitString.TAG:
                 * return new Asn1BitString(this, in, length);
                 * case Asn1ObjectIdentifier.TAG:
                 * return new Asn1ObjectIdentifier(this, in, length);
                 * case Asn1Real.TAG:
                 * return new Asn1Real(this, in, length);
                 * case Asn1NumericString.TAG:
                 * return new Asn1NumericString(this, in, length);
                 * case Asn1PrintableString.TAG:
                 * return new Asn1PrintableString(this, in, length);
                 * case Asn1TeletexString.TAG:
                 * return new Asn1TeletexString(this, in, length);
                 * case Asn1VideotexString.TAG:
                 * return new Asn1VideotexString(this, in, length);
                 * case Asn1IA5String.TAG:
                 * return new Asn1IA5String(this, in, length);
                 * case Asn1GraphicString.TAG:
                 * return new Asn1GraphicString(this, in, length);
                 * case Asn1VisibleString.TAG:
                 * return new Asn1VisibleString(this, in, length);
                 * case Asn1GeneralString.TAG:
                 * return new Asn1GeneralString(this, in, length);
                 */

                default:
                    throw new EndOfStreamException("Unknown tag");     // !!! need a better exception
                }
            }

            // APPLICATION or CONTEXT-SPECIFIC tag
            return(new Asn1Tagged((Asn1Identifier)_asn1Id.Clone(), new Asn1OctetString(length > 0 ? await DecodeOctetString(inRenamed, length, cancellationToken).ConfigureAwait(false) : new byte[0])));
        }