Example #1
0
        public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
        {
            var len = explicitTagging ? MatchTag(buffer, Tag) : implicitLength;

            OidValue        = OidValue.FromArray(buffer.DecodeRelOidContents(len));
            buffer.TypeCode = RelativeOidTypeCode;
        }
        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 Asn1BerDecodeContext(Asn1BerDecodeBuffer decodeBuffer, int elemLength)
 {
     _decodeBuffer = decodeBuffer;
     _decBufByteCount = decodeBuffer.ByteCount;
     _elemLength = elemLength;
     _tagHolder = new Asn1Tag();
 }
        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);
        }
Example #5
0
        public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
        {
            var length = explicitTagging ? MatchTag(buffer, Tag) : implicitLength;

            Value           = (int)Asn1RunTime.DecodeIntValue(buffer, length, true);
            buffer.TypeCode = EnumeratedTypeCode;
        }
        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);
        }
Example #7
0
        public virtual void DecodeComponent(Asn1BerDecodeBuffer buffer)
        {
            var type = new Asn1OpenType();

            type.Decode(buffer, false, 0);
            Value.Add(type);
        }
        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;
        }
Example #9
0
        public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
        {
            var length = explicitTagging ? MatchTag(buffer, Tag) : implicitLength;

            _value          = DecodeValue(buffer, length);
            buffer.TypeCode = 2;
        }
        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 tag = new Asn1Tag();
            buffer.Mark();

            var num = buffer.DecodeTagAndLength(tag);

            if (tag.Equals(0, 0, NullTypeCode))
            {
                buffer.Reset();
                var element = new NullParams();

                SetElement(Null, element);
                Element.Decode(buffer, true, num);
            }
            else
            {
                if (!tag.Equals(0, 0x20, SequenceTypeCode))
                {
                    throw ExceptionUtility.CryptographicException(Resources.Asn1InvalidChoiceOptionTagException, tag, buffer.ByteCount);
                }

                buffer.Reset();
                var parameters = new GostR34102001PublicKeyParameters();

                SetElement(Params, parameters);
                Element.Decode(buffer, true, num);
            }
        }
Example #13
0
 public Asn1BerDecodeContext(Asn1BerDecodeBuffer decodeBuffer, int elemLength)
 {
     _decodeBuffer    = decodeBuffer;
     _decBufByteCount = decodeBuffer.ByteCount;
     _elemLength      = elemLength;
     _tagHolder       = new Asn1Tag();
 }
        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);
        }
Example #15
0
        protected virtual int MatchTag(Asn1BerDecodeBuffer buffer, short tagClass, short tagForm, int tagIdCode)
        {
            if (!buffer.MatchTag(tagClass, tagForm, tagIdCode, _parsedTag, _parsedLen))
            {
                throw ExceptionUtility.CryptographicException(Resources.Asn1TagMatchFailedException, new Asn1Tag(tagClass, tagForm, tagIdCode), _parsedTag, buffer.ByteCount);
            }

            return(_parsedLen.Value);
        }
Example #16
0
		public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
		{
			if (explicitTagging)
			{
				MatchTag(buffer, Tag);
			}

			buffer.TypeCode = NullTypeCode;
		}
Example #17
0
        public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
        {
            if (explicitTagging)
            {
                MatchTag(buffer, Tag);
            }

            buffer.TypeCode = NullTypeCode;
        }
		public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
		{
			base.Decode(buffer, explicitTagging, implicitLength);

			if (Length != 32)
			{
				throw ExceptionUtility.CryptographicException(Resources.Asn1ConsVioException, "Length", Length);
			}
		}
Example #19
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;
        }
Example #20
0
        public virtual void DecodeEventComponent(Asn1BerDecodeBuffer buffer)
        {
            buffer.InvokeStartElement("...", -1);

            var type = new Asn1OpenType();
            type.Decode(buffer, false, 0);

            Value.Add(type);

            buffer.InvokeCharacters(type.ToString());
            buffer.InvokeEndElement("...", -1);
        }
Example #21
0
        public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
        {
            var len = explicitTagging ? MatchTag(buffer, Tag) : implicitLength;

            if (len <= 0)
            {
                throw ExceptionUtility.CryptographicException(Resources.Asn1InvalidLengthException);
            }

            OidValue        = OidValue.FromArray(buffer.DecodeOidContents(len));
            buffer.TypeCode = ObjectIdentifierTypeCode;
        }
        public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
        {
            var num = explicitTagging ? MatchTag(buffer, Tag) : implicitLength;
            var str = new Asn1OctetString();
            str.Decode(buffer, false, num);

            Value = Encoding.UTF8.GetString(str.Value, 0, str.Value.Length);

            if (explicitTagging && (num == Asn1Status.IndefiniteLength))
            {
                MatchTag(buffer, Asn1Tag.Eoc);
            }
        }
Example #23
0
        public virtual void DecodeEventComponent(Asn1BerDecodeBuffer buffer)
        {
            buffer.InvokeStartElement("...", -1);

            var type = new Asn1OpenType();

            type.Decode(buffer, false, 0);

            Value.Add(type);

            buffer.InvokeCharacters(type.ToString());
            buffer.InvokeEndElement("...", -1);
        }
        public static int CalcIndefLen(byte[] data, int offset, int len)
        {
            Asn1BerDecodeBuffer buffer;

            if ((offset == 0) && (len == data.Length))
            {
                buffer = new Asn1BerDecodeBuffer(data);
            }
            else
            {
                var destinationArray = new byte[len];
                Array.Copy(data, offset, destinationArray, 0, len);
                buffer = new Asn1BerDecodeBuffer(destinationArray);
            }

            var tag = new Asn1Tag();
            var num = buffer.DecodeTagAndLength(tag);

            if (num == Asn1Status.IndefiniteLength)
            {
                var num2 = 1;
                num = 0;

                while (num2 > 0)
                {
                    var byteCount = buffer.ByteCount;
                    var num4 = buffer.DecodeTagAndLength(tag);
                    num += buffer.ByteCount - byteCount;

                    if (num4 > 0)
                    {
                        buffer.Skip(num4);
                        num += num4;
                    }
                    else
                    {
                        if (num4 == Asn1Status.IndefiniteLength)
                        {
                            num2++;
                            continue;
                        }
                        if (tag.IsEoc() && (num4 == 0))
                        {
                            num2--;
                        }
                    }
                }
            }

            return num;
        }
Example #25
0
        public static int CalcIndefLen(byte[] data, int offset, int len)
        {
            Asn1BerDecodeBuffer buffer;

            if ((offset == 0) && (len == data.Length))
            {
                buffer = new Asn1BerDecodeBuffer(data);
            }
            else
            {
                var destinationArray = new byte[len];
                Array.Copy(data, offset, destinationArray, 0, len);
                buffer = new Asn1BerDecodeBuffer(destinationArray);
            }

            var tag = new Asn1Tag();
            var num = buffer.DecodeTagAndLength(tag);

            if (num == Asn1Status.IndefiniteLength)
            {
                var num2 = 1;
                num = 0;

                while (num2 > 0)
                {
                    var byteCount = buffer.ByteCount;
                    var num4      = buffer.DecodeTagAndLength(tag);
                    num += buffer.ByteCount - byteCount;

                    if (num4 > 0)
                    {
                        buffer.Skip(num4);
                        num += num4;
                    }
                    else
                    {
                        if (num4 == Asn1Status.IndefiniteLength)
                        {
                            num2++;
                            continue;
                        }
                        if (tag.IsEoc() && (num4 == 0))
                        {
                            num2--;
                        }
                    }
                }
            }

            return(num);
        }
        public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
        {
            var num = explicitTagging ? MatchTag(buffer, Tag) : implicitLength;
            var str = new Asn1OctetString();

            str.Decode(buffer, false, num);

            Value = Encoding.UTF8.GetString(str.Value, 0, str.Value.Length);

            if (explicitTagging && (num == Asn1Status.IndefiniteLength))
            {
                MatchTag(buffer, Asn1Tag.Eoc);
            }
        }
Example #27
0
        public override void BinDump(StreamWriter outs, string varName)
        {
            var buffer = new Asn1BerDecodeBuffer(ByteArrayInputStream);

            try
            {
                buffer.Parse(new Asn1BerMessageDumpHandler(outs));
            }
            catch (Exception exception)
            {
                Console.Out.WriteLine(exception.Message);
                Console.Error.Write(exception.StackTrace);
                Console.Error.Flush();
            }
        }
Example #28
0
        public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
        {
            if (explicitTagging)
            {
                MatchTag(buffer, Tag);
            }

            var num = buffer.Read();

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

            buffer.TypeCode = BooleanTypeCode;
            Value           = num != 0;
        }
Example #29
0
        public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
        {
            if (explicitTagging)
            {
                MatchTag(buffer, Tag);
            }

            var num = buffer.Read();

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

            buffer.TypeCode = BooleanTypeCode;
            Value = num != 0;
        }
Example #30
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;
        }
        private void ReadSegment(Asn1BerDecodeBuffer buffer, int llen, IntHolder idx)
        {
            if ((llen < 0) || ((llen % 4) != 0))
            {
                throw ExceptionUtility.CryptographicException(Resources.Asn1InvalidLengthException);
            }

            var num4 = llen / 4;

            if (_value.Length == 0)
            {
                _value = new int[num4];
            }
            else if ((idx.Value + num4) >= _value.Length)
            {
                ReallocIntArray(idx.Value + num4);
            }

            var value = idx.Value;

            while (value < (idx.Value + num4))
            {
                _value[value] = 0;

                for (var i = 0; i < 4; i++)
                {
                    var num = buffer.Read();

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

                    _value[value] = (_value[value] * 0x100) + num;
                }

                value++;
            }

            idx.Value = value;
        }
        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 void Decode(byte[] data)
        {
            if (data == null)
            {
                throw ExceptionUtility.ArgumentNull("data");
            }

            try
            {
                var asnDecoder = new Asn1BerDecodeBuffer(data);
                var keyTransport = new GostR3410KeyTransport();
                keyTransport.Decode(asnDecoder);

                SessionEncryptedKey = DecodeSessionKey(keyTransport);
                TransportParameters = DecodePublicKey(keyTransport);
            }
            catch (Exception exception)
            {
                throw ExceptionUtility.CryptographicException(exception, Resources.Asn1DecodeError, typeof(GostR3410KeyTransport).FullName);
            }
        }
        public void DecodeParameters(byte[] data)
        {
            if (data == null)
            {
                throw ExceptionUtility.ArgumentNull("data");
            }

            try
            {
                var asnDecoder = new Asn1BerDecodeBuffer(data);
                var publicKeyParameters = new GostR34102001PublicKeyParameters();
                publicKeyParameters.Decode(asnDecoder);

                DigestParamSet = Asn1ObjectIdentifier.ToOidString(publicKeyParameters.DigestParamSet);
                PublicKeyParamSet = Asn1ObjectIdentifier.ToOidString(publicKeyParameters.PublicKeyParamSet);
                EncryptionParamSet = Asn1ObjectIdentifier.ToOidString(publicKeyParameters.EncryptionParamSet);
            }
            catch (Exception exception)
            {
                throw ExceptionUtility.CryptographicException(exception, Resources.Asn1DecodeError, typeof(GostR34102001PublicKeyParameters).FullName);
            }
        }
        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;
            }
        }
        public static string DecodeEncryptionParamSet(byte[] data)
        {
            if (data == null)
            {
                throw ExceptionUtility.ArgumentNull("data");
            }

            string encryptionParamSet;

            try
            {
                var asnDecoder = new Asn1BerDecodeBuffer(data);
                var parameters = new Gost2814789BlobParameters();
                parameters.Decode(asnDecoder);

                encryptionParamSet = Asn1ObjectIdentifier.ToOidString(parameters.EncryptionParamSet);
            }
            catch (Exception exception)
            {
                throw ExceptionUtility.CryptographicException(exception, Resources.Asn1DecodeError, typeof(Gost2814789BlobParameters).FullName);
            }

            return encryptionParamSet;
        }
Example #37
0
 public virtual void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
 {
 }
Example #38
0
 protected virtual int MatchTag(Asn1BerDecodeBuffer buffer, Asn1Tag tag)
 {
     return(MatchTag(buffer, tag.Class, tag.Form, tag.IdCode));
 }
 public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
 {
     Value = buffer.DecodeOpenType();
     buffer.TypeCode = OpenTypeTypeCode;
 }
		public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
		{
			Decode(buffer, explicitTagging, implicitLength, Tag);
		}
Example #41
0
 protected virtual int MatchTag(Asn1BerDecodeBuffer buffer, Asn1Tag tag)
 {
     return MatchTag(buffer, tag.Class, tag.Form, tag.IdCode);
 }
Example #42
0
 public virtual void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
 {
 }
Example #43
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;
        }
 public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
 {
     var llen = explicitTagging ? MatchTag(buffer, Tag) : implicitLength;
     Value = buffer.DecodeRelOidContents(llen);
     buffer.TypeCode = RelativeOidTypeCode;
 }
Example #45
0
 public virtual void DecodeComponent(Asn1BerDecodeBuffer buffer)
 {
     var type = new Asn1OpenType();
     type.Decode(buffer, false, 0);
     Value.Add(type);
 }
Example #46
0
 public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
 {
     DecodeComponent(buffer);
 }
 public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
 {
     base.Decode(buffer, false, 0);
 }
Example #48
0
 public virtual void Decode(Asn1BerDecodeBuffer buffer)
 {
     Decode(buffer, true, 0);
 }
 public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
 {
     Decode(buffer, explicitTagging, implicitLength, Tag);
 }
Example #50
0
 protected override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength, Asn1Tag tag)
 {
     Parsed = false;
     base.Decode(buffer, explicitTagging, implicitLength, tag);
     DerRules = buffer is Asn1DerDecodeBuffer;
 }
Example #51
0
 public virtual void Decode(Asn1BerDecodeBuffer buffer)
 {
     Decode(buffer, true, 0);
 }
Example #52
0
 public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
 {
     Value           = buffer.DecodeOpenType();
     buffer.TypeCode = OpenTypeTypeCode;
 }
Example #53
0
        protected virtual int MatchTag(Asn1BerDecodeBuffer buffer, short tagClass, short tagForm, int tagIdCode)
        {
            if (!buffer.MatchTag(tagClass, tagForm, tagIdCode, _parsedTag, _parsedLen))
            {
                throw ExceptionUtility.CryptographicException(Resources.Asn1TagMatchFailedException, new Asn1Tag(tagClass, tagForm, tagIdCode), _parsedTag, buffer.ByteCount);
            }

            return _parsedLen.Value;
        }
Example #54
0
 public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
 {
     var length = explicitTagging ? MatchTag(buffer, Tag) : implicitLength;
     Value = Asn1RunTime.DecodeIntValue(buffer, length, true);
     buffer.TypeCode = BigIntegerTypeCode;
 }
Example #55
0
        public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
        {
            var length = explicitTagging ? MatchTag(buffer, Tag) : implicitLength;

            if (length == 0)
            {
                Value = 0.0;
            }
            else
            {
                var num2 = buffer.ReadByte();

                if (length == 1)
                {
                    switch (num2)
                    {
                        case PlusInfinity:
                            Value = double.PositiveInfinity;
                            return;

                        case MinusInfinity:
                            Value = double.NegativeInfinity;
                            return;
                    }

                    throw ExceptionUtility.CryptographicException(Resources.Asn1InvalidFormatOfConstructedValue, buffer.ByteCount);
                }

                length--;

                if ((num2 & RealBinary) == 0)
                {
                    var num8 = length;
                    var num9 = 0;

                    var builder = new StringBuilder { Length = num8 };

                    while (num8 > 0)
                    {
                        var num7 = buffer.Read();

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

                        builder[num9++] = (char)num7;
                        num8--;
                    }

                    var num10 = num2 & RealIso6093Mask;
                    var num11 = 0;

                    for (var i = 0; i < builder.Length; i++)
                    {
                        var ch = builder[i];

                        if ((num10 >= 2) && (ch == ','))
                        {
                            builder[i] = '.';
                            num11++;
                        }
                        else if (((num10 >= 1) && (((ch >= '0') && (ch <= '9')) || ((ch == '+') || (ch == '-')))) || (((num10 >= 2) && (ch == '.')) || ((num10 == 3) && ((ch == 'E') || (ch == 'e')))))
                        {
                            num11++;
                        }
                        else if ((num11 != 0) || (ch != ' '))
                        {
                            throw ExceptionUtility.CryptographicException(Resources.Asn1InvalidFormatOfConstructedValue, buffer.ByteCount);
                        }
                    }
                    try
                    {
                        Value = double.Parse(builder.ToString());
                    }
                    catch (FormatException)
                    {
                        throw ExceptionUtility.CryptographicException(Resources.Asn1InvalidFormatOfConstructedValue, buffer.ByteCount);
                    }
                }
                else
                {
                    int num6;
                    int num3;

                    switch ((num2 & RealExplenMask))
                    {
                        case RealExplen1:
                            num3 = 1;
                            break;

                        case RealExplen2:
                            num3 = 2;
                            break;

                        case RealExplen3:
                            num3 = 3;
                            break;

                        default:
                            num3 = buffer.ReadByte();
                            length--;
                            break;
                    }

                    var num4 = (int)Asn1RunTime.DecodeIntValue(buffer, num3, true);
                    length -= num3;

                    var num5 = Asn1RunTime.DecodeIntValue(buffer, length, false) * (1L << ((num2 & RealFactorMask) >> 2));

                    switch ((num2 & RealBaseMask))
                    {
                        case RealBase2:
                            num6 = 2;
                            break;

                        case RealBase8:
                            num6 = 8;
                            break;

                        case RealBase16:
                            num6 = 16;
                            break;

                        default:
                            throw ExceptionUtility.CryptographicException(Resources.Asn1InvalidFormatOfConstructedValue, buffer.ByteCount);
                    }

                    Value = num5 * Math.Pow(num6, num4);

                    if ((num2 & PlusInfinity) != 0)
                    {
                        Value = -Value;
                    }
                }

                buffer.TypeCode = RealTypeCode;
            }
        }
Example #56
0
 public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
 {
     DecodeComponent(buffer);
 }
Example #57
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;
        }
Example #58
0
        public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
        {
            var length = explicitTagging ? MatchTag(buffer, Tag) : implicitLength;

            if (length == 0)
            {
                Value = 0.0;
            }
            else
            {
                var num2 = buffer.ReadByte();

                if (length == 1)
                {
                    switch (num2)
                    {
                    case PlusInfinity:
                        Value = double.PositiveInfinity;
                        return;

                    case MinusInfinity:
                        Value = double.NegativeInfinity;
                        return;
                    }

                    throw ExceptionUtility.CryptographicException(Resources.Asn1InvalidFormatOfConstructedValue, buffer.ByteCount);
                }

                length--;

                if ((num2 & RealBinary) == 0)
                {
                    var num8 = length;
                    var num9 = 0;

                    var builder = new StringBuilder {
                        Length = num8
                    };

                    while (num8 > 0)
                    {
                        var num7 = buffer.Read();

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

                        builder[num9++] = (char)num7;
                        num8--;
                    }

                    var num10 = num2 & RealIso6093Mask;
                    var num11 = 0;

                    for (var i = 0; i < builder.Length; i++)
                    {
                        var ch = builder[i];

                        if ((num10 >= 2) && (ch == ','))
                        {
                            builder[i] = '.';
                            num11++;
                        }
                        else if (((num10 >= 1) && (((ch >= '0') && (ch <= '9')) || ((ch == '+') || (ch == '-')))) || (((num10 >= 2) && (ch == '.')) || ((num10 == 3) && ((ch == 'E') || (ch == 'e')))))
                        {
                            num11++;
                        }
                        else if ((num11 != 0) || (ch != ' '))
                        {
                            throw ExceptionUtility.CryptographicException(Resources.Asn1InvalidFormatOfConstructedValue, buffer.ByteCount);
                        }
                    }
                    try
                    {
                        Value = double.Parse(builder.ToString());
                    }
                    catch (FormatException)
                    {
                        throw ExceptionUtility.CryptographicException(Resources.Asn1InvalidFormatOfConstructedValue, buffer.ByteCount);
                    }
                }
                else
                {
                    int num6;
                    int num3;

                    switch ((num2 & RealExplenMask))
                    {
                    case RealExplen1:
                        num3 = 1;
                        break;

                    case RealExplen2:
                        num3 = 2;
                        break;

                    case RealExplen3:
                        num3 = 3;
                        break;

                    default:
                        num3 = buffer.ReadByte();
                        length--;
                        break;
                    }

                    var num4 = (int)Asn1RunTime.DecodeIntValue(buffer, num3, true);
                    length -= num3;

                    var num5 = Asn1RunTime.DecodeIntValue(buffer, length, false) * (1L << ((num2 & RealFactorMask) >> 2));

                    switch ((num2 & RealBaseMask))
                    {
                    case RealBase2:
                        num6 = 2;
                        break;

                    case RealBase8:
                        num6 = 8;
                        break;

                    case RealBase16:
                        num6 = 16;
                        break;

                    default:
                        throw ExceptionUtility.CryptographicException(Resources.Asn1InvalidFormatOfConstructedValue, buffer.ByteCount);
                    }

                    Value = num5 * Math.Pow(num6, num4);

                    if ((num2 & PlusInfinity) != 0)
                    {
                        Value = -Value;
                    }
                }

                buffer.TypeCode = RealTypeCode;
            }
        }