Example #1
0
        public override void Decode
            (Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
        {
            int llen = (explicitTagging) ?
                       MatchTag(buffer, Asn1Tag.Sequence) : implicitLength;

            Init();

            // decode SEQUENCE

            Asn1BerDecodeContext context =
                new Asn1BerDecodeContext(buffer, llen);

            IntHolder elemLen = new IntHolder();

            // decode encryptionParamSet

            if (context.MatchElemTag(Asn1Tag.Universal, Asn1Tag.PRIM, 6, elemLen, false))
            {
                encryptionParamSet = new Gost28147_89_ParamSet();
                encryptionParamSet.Decode(buffer, true, elemLen.Value);
            }
            else
            {
                throw new Exception("Asn1MissingRequiredException");
            }

            // decode extElem1

            if (!context.Expired())
            {
                Asn1Tag _tag = buffer.PeekTag();
                if (_tag.Equals(Asn1Tag.Universal, Asn1Tag.PRIM, 6))
                {
                    throw new Exception("Asn1SeqOrderException");
                }
                else
                {
                    extElem1 = new Asn1OpenExt();
                    while (!context.Expired())
                    {
                        extElem1.DecodeComponent(buffer);
                    }
                }
            }
            else
            {
                extElem1 = null;
            }
        }
Example #2
0
        public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
        {
            var elemLength = explicitTagging ? MatchTag(buffer, Asn1Tag.Sequence) : implicitLength;

            Algorithm  = null;
            Parameters = null;

            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);
            }

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

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

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

            EncryptionParamSet = null;
            ExtElement         = null;

            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 Gost_28147_89_ParamSet();
            EncryptionParamSet.Decode(buffer, true, parsedLen.Value);

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

                ExtElement = new Asn1OpenExt();

                while (!context.Expired())
                {
                    ExtElement.DecodeComponent(buffer);
                }
            }
            else
            {
                ExtElement = null;
            }
        }
Example #4
0
        public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
        {
            var elemLength = explicitTagging ? MatchTag(buffer, Asn1Tag.Sequence) : implicitLength;

            PublicKeyParamSet  = null;
            DigestParamSet     = null;
            EncryptionParamSet = null;

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

            if (context.MatchElemTag(0, 0, ObjectIdentifierTypeCode, parsedLen, false))
            {
                PublicKeyParamSet = new Asn1ObjectIdentifier();
                PublicKeyParamSet.Decode(buffer, true, parsedLen.Value);
            }
            else
            {
                throw ExceptionUtility.CryptographicException(Resources.Asn1MissingRequiredException, buffer.ByteCount);
            }

            if (context.MatchElemTag(0, 0, ObjectIdentifierTypeCode, parsedLen, false))
            {
                DigestParamSet = new Asn1ObjectIdentifier();
                DigestParamSet.Decode(buffer, true, parsedLen.Value);
            }

            if (context.MatchElemTag(0, 0, ObjectIdentifierTypeCode, parsedLen, false))
            {
                EncryptionParamSet = new Asn1ObjectIdentifier();
                EncryptionParamSet.Decode(buffer, true, parsedLen.Value);
            }

            if (!context.Expired())
            {
                var lastTag = buffer.PeekTag();

                if (lastTag.Equals(0, 0, ObjectIdentifierTypeCode))
                {
                    throw ExceptionUtility.CryptographicException(Resources.Asn1SeqOrderException);
                }
            }
        }
Example #5
0
        public override void Decode
            (Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
        {
            int llen = (explicitTagging) ?
                       MatchTag(buffer, Asn1Tag.Sequence) : implicitLength;

            Init();

            // decode SEQUENCE

            Asn1BerDecodeContext context =
                new Asn1BerDecodeContext(buffer, llen);

            IntHolder elemLen = new IntHolder();

            // decode algorithm

            if (context.MatchElemTag(Asn1Tag.Universal, Asn1Tag.PRIM, 6, elemLen, false))
            {
                algorithm = new Asn1ObjectIdentifier();
                algorithm.Decode(buffer, true, elemLen.Value);
            }
            else
            {
                throw new Exception("Asn1MissingRequiredException (buffer)");
            }

            // decode parameters

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

            checkTC(true);
        }