public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
        {
            var elemLength = explicitTagging ? MatchTag(buffer, Asn1Tag.Sequence) : implicitLength;

            Init();

            var context = new Asn1BerDecodeContext(buffer, elemLength);
            var parsedLen = new IntHolder();

            if (!context.MatchElemTag(0, 0, 6, parsedLen, false))
            {
                throw ExceptionUtility.CryptographicException(Resources.Asn1MissingRequiredException, buffer.ByteCount);
            }

            _publicKeyParamSet = new Asn1ObjectIdentifier();
            _publicKeyParamSet.Decode(buffer, true, parsedLen.Value);

            if (!context.MatchElemTag(0, 0, 6, parsedLen, false))
            {
                throw ExceptionUtility.CryptographicException(Resources.Asn1MissingRequiredException, buffer.ByteCount);
            }

            _digestParamSet = new Asn1ObjectIdentifier();
            _digestParamSet.Decode(buffer, true, parsedLen.Value);

            if (context.MatchElemTag(0, 0, 6, parsedLen, false))
            {
                _encryptionParamSet = new Gost2814789ParamSet();
                _encryptionParamSet.Decode(buffer, true, parsedLen.Value);
            }
        }
        public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
        {
            var llen = explicitTagging ? MatchTag(buffer, Tag) : implicitLength;
            var idx = new IntHolder(0);
            var lastTag = buffer.LastTag;

            if ((lastTag == null) || !lastTag.Constructed)
            {
                ReadSegment(buffer, llen, idx);
            }
            else
            {
                var context = new Asn1BerDecodeContext(buffer, llen);

                while (!context.Expired())
                {
                    var num2 = MatchTag(buffer, Asn1OctetString.Tag);

                    if (num2 <= 0)
                    {
                        throw ExceptionUtility.CryptographicException(Resources.Asn1InvalidFormatOfConstructedValue, buffer.ByteCount);
                    }

                    ReadSegment(buffer, num2, idx);
                }

                if (llen == Asn1Status.IndefiniteLength)
                {
                    MatchTag(buffer, Asn1Tag.Eoc);
                }
            }

            buffer.TypeCode = UniversalStringTypeCode;
        }
        public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
        {
            var llen    = explicitTagging ? MatchTag(buffer, Tag) : implicitLength;
            var idx     = new IntHolder(0);
            var lastTag = buffer.LastTag;

            if ((lastTag == null) || !lastTag.Constructed)
            {
                ReadSegment(buffer, llen, idx);
            }
            else
            {
                var context = new Asn1BerDecodeContext(buffer, llen);

                while (!context.Expired())
                {
                    var num2 = MatchTag(buffer, Asn1OctetString.Tag);

                    if (num2 <= 0)
                    {
                        throw ExceptionUtility.CryptographicException(Resources.Asn1InvalidFormatOfConstructedValue, buffer.ByteCount);
                    }

                    ReadSegment(buffer, num2, idx);
                }

                if (llen == Asn1Status.IndefiniteLength)
                {
                    MatchTag(buffer, Asn1Tag.Eoc);
                }
            }

            buffer.TypeCode = UniversalStringTypeCode;
        }
        public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
        {
            var elemLength = explicitTagging ? MatchTag(buffer, Asn1Tag.Sequence) : implicitLength;

            Init();

            var context = new Asn1BerDecodeContext(buffer, elemLength);
            var parsedLen = new IntHolder();

            if (!context.MatchElemTag(0, 0, 6, parsedLen, false))
            {
                throw ExceptionUtility.CryptographicException(Resources.Asn1MissingRequiredException, buffer.ByteCount);
            }

            Algorithm = new Asn1ObjectIdentifier();
            Algorithm.Decode(buffer, true, parsedLen.Value);

            if (!context.Expired())
            {
                Parameters = new Asn1OpenType();
                Parameters.Decode(buffer, true, 0);
            }

            CheckTc(true);
        }
        public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
        {
            var elemLength = explicitTagging ? MatchTag(buffer, Asn1Tag.Sequence) : implicitLength;

            Init();

            var context = new Asn1BerDecodeContext(buffer, elemLength);
            var parsedLen = new IntHolder();

            if (!context.MatchElemTag(0, 0, ObjectIdentifierTypeCode, parsedLen, false))
            {
                throw ExceptionUtility.CryptographicException(Resources.Asn1MissingRequiredException, buffer.ByteCount);
            }

            EncryptionParamSet = new Gost2814789ParamSet();
            EncryptionParamSet.Decode(buffer, true, parsedLen.Value);

            if (context.MatchElemTag(0, 0, OctetStringTypeCode, parsedLen, false))
            {
                Ukm = new Asn1OctetString();
                Ukm.Decode(buffer, true, parsedLen.Value);

                if (Ukm.Length != 8)
                {
                    throw ExceptionUtility.CryptographicException(Resources.Asn1ConsVioException, "Ukm.Length", Ukm.Length);
                }
            }
        }
        public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
        {
            var elemLength = explicitTagging ? MatchTag(buffer, Asn1Tag.Sequence) : implicitLength;

            Init();

            var context = new Asn1BerDecodeContext(buffer, elemLength);
            var parsedLen = new IntHolder();

            if (!context.MatchElemTag(0, 0x20, 0x10, parsedLen, false))
            {
                throw ExceptionUtility.CryptographicException(Resources.Asn1MissingRequiredException, buffer.ByteCount);
            }

            Algorithm = new AlgorithmIdentifier();
            Algorithm.Decode(buffer, true, parsedLen.Value);

            if (!context.MatchElemTag(0, 0, 3, parsedLen, false))
            {
                throw ExceptionUtility.CryptographicException(Resources.Asn1MissingRequiredException, buffer.ByteCount);
            }

            SubjectPublicKey = new Asn1BitString();
            SubjectPublicKey.Decode(buffer, true, parsedLen.Value);
        }
        public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
        {
            var elemLength = explicitTagging ? MatchTag(buffer, Asn1Tag.Sequence) : implicitLength;

            Init();

            var context = new Asn1BerDecodeContext(buffer, elemLength);
            var parsedLen = new IntHolder();

            if (!context.MatchElemTag(0, 0x20, SequenceTypeCode, parsedLen, false))
            {
                throw ExceptionUtility.CryptographicException(Resources.Asn1MissingRequiredException, buffer.ByteCount);
            }

            EncryptedKey = new Gost2814789EncryptedKey();
            EncryptedKey.Decode(buffer, true, parsedLen.Value);

            if (!context.MatchElemTag(0, 0x20, SequenceTypeCode, parsedLen, false))
            {
                throw ExceptionUtility.CryptographicException(Resources.Asn1MissingRequiredException, buffer.ByteCount);
            }

            EncryptedParameters = new Gost2814789KeyWrapParameters();
            EncryptedParameters.Decode(buffer, true, parsedLen.Value);
        }
示例#8
0
        public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
        {
            var elemLength = explicitTagging ? MatchTag(buffer, Tag) : implicitLength;
            var lastTag    = buffer.LastTag;

            if ((lastTag == null) || !lastTag.Constructed)
            {
                if (elemLength < 0)
                {
                    throw ExceptionUtility.CryptographicException(Resources.Asn1InvalidLengthException);
                }

                Value = new byte[elemLength];

                if (elemLength != 0)
                {
                    buffer.Read(Value);
                }
            }
            else
            {
                var nbytes  = 0;
                var offset  = 0;
                var context = new Asn1BerDecodeContext(buffer, elemLength);

                while (!context.Expired())
                {
                    var num2 = MatchTag(buffer, Tag);

                    if (num2 <= 0)
                    {
                        throw ExceptionUtility.CryptographicException(Resources.Asn1InvalidFormatOfConstructedValue, buffer.ByteCount);
                    }

                    nbytes += num2;

                    if (offset == 0)
                    {
                        Value = new byte[nbytes];
                    }
                    else
                    {
                        ReAllocByteArray(nbytes);
                    }

                    buffer.Read(Value, offset, num2);
                    offset = nbytes;
                }

                if (elemLength == Asn1Status.IndefiniteLength)
                {
                    MatchTag(buffer, Asn1Tag.Eoc);
                }
            }

            buffer.TypeCode = OctetStringTypeCode;
        }
示例#9
0
        public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
        {
            var elemLength = explicitTagging ? MatchTag(buffer, Tag) : implicitLength;
            var len        = elemLength;
            var sb         = new StringBuilder();

            var lastTag = buffer.LastTag;

            if ((lastTag == null) || !lastTag.Constructed)
            {
                sb.EnsureCapacity(elemLength / 2);
                ReadSegment(buffer, sb, len);
            }
            else
            {
                var capacity = 0;
                var context  = new Asn1BerDecodeContext(buffer, elemLength);

                while (!context.Expired())
                {
                    var num3 = MatchTag(buffer, Asn1OctetString.Tag);

                    if (num3 <= 0)
                    {
                        throw ExceptionUtility.CryptographicException(Resources.Asn1InvalidFormatOfConstructedValue, buffer.ByteCount);
                    }

                    capacity += num3;
                    sb.EnsureCapacity(capacity);
                    ReadSegment(buffer, sb, num3);
                }

                if (elemLength == Asn1Status.IndefiniteLength)
                {
                    MatchTag(buffer, Asn1Tag.Eoc);
                }
            }

            Value           = sb.ToString();
            buffer.TypeCode = BmpStringTypeCode;
        }
示例#10
0
        public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
        {
            var elemLength = explicitTagging ? MatchTag(buffer, Tag) : implicitLength;
            var len = elemLength;
            var sb = new StringBuilder();

            var lastTag = buffer.LastTag;

            if ((lastTag == null) || !lastTag.Constructed)
            {
                sb.EnsureCapacity(elemLength / 2);
                ReadSegment(buffer, sb, len);
            }
            else
            {
                var capacity = 0;
                var context = new Asn1BerDecodeContext(buffer, elemLength);

                while (!context.Expired())
                {
                    var num3 = MatchTag(buffer, Asn1OctetString.Tag);

                    if (num3 <= 0)
                    {
                        throw ExceptionUtility.CryptographicException(Resources.Asn1InvalidFormatOfConstructedValue, buffer.ByteCount);
                    }

                    capacity += num3;
                    sb.EnsureCapacity(capacity);
                    ReadSegment(buffer, sb, num3);
                }

                if (elemLength == Asn1Status.IndefiniteLength)
                {
                    MatchTag(buffer, Asn1Tag.Eoc);
                }
            }

            Value = sb.ToString();
            buffer.TypeCode = BmpStringTypeCode;
        }
        public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
        {
            var elemLength = explicitTagging ? MatchTag(buffer, Asn1Tag.Sequence) : implicitLength;

            Init();

            var context = new Asn1BerDecodeContext(buffer, elemLength);
            var parsedLen = new IntHolder();

            if (!context.MatchElemTag(0, 0, ObjectIdentifierTypeCode, parsedLen, false))
            {
                throw ExceptionUtility.CryptographicException(Resources.Asn1MissingRequiredException, buffer.ByteCount);
            }

            EncryptionParamSet = new Gost2814789ParamSet();
            EncryptionParamSet.Decode(buffer, true, parsedLen.Value);

            if (!context.Expired())
            {
                if (buffer.PeekTag().Equals(0, 0, ObjectIdentifierTypeCode))
                {
                    throw ExceptionUtility.CryptographicException(Resources.Asn1SeqOrderException);
                }

                _extElem1 = new Asn1OpenExt();

                while (!context.Expired())
                {
                    _extElem1.DecodeComponent(buffer);
                }
            }
            else
            {
                _extElem1 = null;
            }
        }
示例#12
0
        protected virtual void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength, Asn1Tag tag)
        {
            int num2;
            var elemLength = explicitTagging ? MatchTag(buffer, tag) : implicitLength;
            var num3       = elemLength;
            var num4       = 0;

            if (StringBuffer == null)
            {
                StringBuffer = new StringBuilder();
            }

            var lastTag = buffer.LastTag;

            if ((lastTag == null) || !lastTag.Constructed)
            {
                if (num3 < 0)
                {
                    throw ExceptionUtility.CryptographicException(Resources.Asn1InvalidLengthException);
                }

                StringBuffer.Length = num3;

                while (num3 > 0)
                {
                    num2 = buffer.Read();

                    if (num2 == -1)
                    {
                        throw ExceptionUtility.CryptographicException(Resources.Asn1EndOfBufferException, buffer.ByteCount);
                    }

                    StringBuffer[num4++] = (char)num2;
                    num3--;
                }
            }
            else
            {
                var capacity = 0;
                var context  = new Asn1BerDecodeContext(buffer, elemLength);

                while (!context.Expired())
                {
                    var num5 = MatchTag(buffer, Asn1OctetString.Tag);

                    if (num5 <= 0)
                    {
                        throw ExceptionUtility.CryptographicException(Resources.Asn1InvalidFormatOfConstructedValue, buffer.ByteCount);
                    }

                    capacity += num5;
                    StringBuffer.EnsureCapacity(capacity);

                    while (num5 > 0)
                    {
                        num2 = buffer.Read();

                        if (num2 == -1)
                        {
                            throw ExceptionUtility.CryptographicException(Resources.Asn1EndOfBufferException, buffer.ByteCount);
                        }

                        StringBuffer.Append((char)num2);
                        num5--;
                    }
                }

                if (elemLength == Asn1Status.IndefiniteLength)
                {
                    MatchTag(buffer, Asn1Tag.Eoc);
                }
            }

            Value           = StringBuffer.ToString();
            buffer.TypeCode = (short)tag.IdCode;
        }
示例#13
0
        public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
        {
            var elemLength = explicitTagging ? MatchTag(buffer, Tag) : implicitLength;
            var lastTag    = buffer.LastTag;

            if ((lastTag == null) || !lastTag.Constructed)
            {
                if (elemLength < 0)
                {
                    throw ExceptionUtility.CryptographicException(Resources.Asn1InvalidLengthException);
                }

                if (elemLength != 0)
                {
                    var num8 = elemLength - 1;
                    var num7 = buffer.Read();

                    if (num7 < 0)
                    {
                        throw ExceptionUtility.CryptographicException(Resources.Asn1EndOfBufferException, buffer.ByteCount);
                    }

                    if ((num7 < 0) || (num7 > 7))
                    {
                        throw ExceptionUtility.CryptographicException(Resources.Asn1InvalidFormatOfBitString, num7);
                    }

                    if ((num8 == 0) && (num7 != 0))
                    {
                        throw ExceptionUtility.CryptographicException(Resources.Asn1InvalidLengthException);
                    }

                    NumBits = (num8 * 8) - num7;
                    Value   = new byte[num8];
                    buffer.Read(Value);
                }
                else
                {
                    NumBits = 0;
                    Value   = null;
                }
            }
            else
            {
                var num3   = 0;
                var offset = 0;
                var index  = -1;
                var num6   = 0;

                var context = new Asn1BerDecodeContext(buffer, elemLength);

                while (!context.Expired())
                {
                    var nbytes = MatchTag(buffer, Tag);

                    if (nbytes <= 0)
                    {
                        throw ExceptionUtility.CryptographicException(Resources.Asn1InvalidFormatOfConstructedValue, buffer.ByteCount);
                    }

                    num3 += nbytes;

                    if (offset == 0)
                    {
                        AllocBitArray(num3 * 8);
                    }
                    else
                    {
                        ReallocBitArray(num3 * 8);
                    }

                    index = offset;
                    buffer.Read(Value, offset, nbytes);
                    offset = num3;
                }

                if (index >= 0)
                {
                    num6 = Value[index];

                    if (((offset - index) - 1) > 0)
                    {
                        Array.Copy(Value, index + 1, Value, index, (offset - index) - 1);
                    }

                    num3--;
                }

                if ((num6 < 0) || (num6 > 7))
                {
                    throw ExceptionUtility.CryptographicException(Resources.Asn1InvalidFormatOfBitString, num6);
                }

                ReallocBitArray((num3 * 8) - num6);

                if (elemLength == Asn1Status.IndefiniteLength)
                {
                    MatchTag(buffer, Asn1Tag.Eoc);
                }
            }

            buffer.TypeCode = 3;
        }
        protected virtual void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength, Asn1Tag tag)
        {
            int num2;
            var elemLength = explicitTagging ? MatchTag(buffer, tag) : implicitLength;
            var num3 = elemLength;
            var num4 = 0;

            if (StringBuffer == null)
            {
                StringBuffer = new StringBuilder();
            }

            var lastTag = buffer.LastTag;

            if ((lastTag == null) || !lastTag.Constructed)
            {
                if (num3 < 0)
                {
                    throw ExceptionUtility.CryptographicException(Resources.Asn1InvalidLengthException);
                }

                StringBuffer.Length = num3;

                while (num3 > 0)
                {
                    num2 = buffer.Read();

                    if (num2 == -1)
                    {
                        throw ExceptionUtility.CryptographicException(Resources.Asn1EndOfBufferException, buffer.ByteCount);
                    }

                    StringBuffer[num4++] = (char)num2;
                    num3--;
                }
            }
            else
            {
                var capacity = 0;
                var context = new Asn1BerDecodeContext(buffer, elemLength);

                while (!context.Expired())
                {
                    var num5 = MatchTag(buffer, Asn1OctetString.Tag);

                    if (num5 <= 0)
                    {
                        throw ExceptionUtility.CryptographicException(Resources.Asn1InvalidFormatOfConstructedValue, buffer.ByteCount);
                    }

                    capacity += num5;
                    StringBuffer.EnsureCapacity(capacity);

                    while (num5 > 0)
                    {
                        num2 = buffer.Read();

                        if (num2 == -1)
                        {
                            throw ExceptionUtility.CryptographicException(Resources.Asn1EndOfBufferException, buffer.ByteCount);
                        }

                        StringBuffer.Append((char)num2);
                        num5--;
                    }
                }

                if (elemLength == Asn1Status.IndefiniteLength)
                {
                    MatchTag(buffer, Asn1Tag.Eoc);
                }
            }

            Value = StringBuffer.ToString();
            buffer.TypeCode = (short)tag.IdCode;
        }
        public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
        {
            var elemLength = explicitTagging ? MatchTag(buffer, Tag) : implicitLength;
            var lastTag = buffer.LastTag;

            if ((lastTag == null) || !lastTag.Constructed)
            {
                if (elemLength < 0)
                {
                    throw ExceptionUtility.CryptographicException(Resources.Asn1InvalidLengthException);
                }

                Value = new byte[elemLength];

                if (elemLength != 0)
                {
                    buffer.Read(Value);
                }
            }
            else
            {
                var nbytes = 0;
                var offset = 0;
                var context = new Asn1BerDecodeContext(buffer, elemLength);

                while (!context.Expired())
                {
                    var num2 = MatchTag(buffer, Tag);

                    if (num2 <= 0)
                    {
                        throw ExceptionUtility.CryptographicException(Resources.Asn1InvalidFormatOfConstructedValue, buffer.ByteCount);
                    }

                    nbytes += num2;

                    if (offset == 0)
                    {
                        Value = new byte[nbytes];
                    }
                    else
                    {
                        ReAllocByteArray(nbytes);
                    }

                    buffer.Read(Value, offset, num2);
                    offset = nbytes;
                }

                if (elemLength == Asn1Status.IndefiniteLength)
                {
                    MatchTag(buffer, Asn1Tag.Eoc);
                }
            }

            buffer.TypeCode = OctetStringTypeCode;
        }