Пример #1
0
        private void CheckAlg(bool decode)
        {
            AlgorithmId algorithmId = null;

            foreach (var alg in PkiConstants.SupportedAlgorithms)
            {
                if (alg.Id.Equals(Algorithm))
                {
                    algorithmId = alg;
                    break;
                }
            }

            if ((algorithmId != null) && ((decode && (Parameters != null)) && (algorithmId.Type != null)))
            {
                try
                {
                    var buffer = new Asn1BerDecodeBuffer(((Asn1OpenType)Parameters).Value);
                    Parameters = (Asn1Type)Activator.CreateInstance(algorithmId.Type.GetType());
                    Parameters.Decode(buffer, true, 0);
                    buffer.InvokeEndElement("parameters", -1);
                }
                catch (Exception exception)
                {
                    Asn1Util.WriteStackTrace(exception, Console.Error);
                    throw ExceptionUtility.CryptographicException(Resources.Asn1TableConstraint);
                }
            }
        }
Пример #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);
        }
Пример #3
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);
        }
Пример #4
0
        public void checkTC(bool decode)
        {
            /* check algorithm */
            ALGORITHM_ID _index = null;

            for (int i = 0; i < _PKIX1Explicit88Values.SupportedAlgorithms.Length; i++)
            {
                if (_PKIX1Explicit88Values.SupportedAlgorithms[i].id.Equals(algorithm))
                {
                    _index = _PKIX1Explicit88Values.SupportedAlgorithms[i];
                    break;
                }
            }
            if (null == _index)
            {
                return;
            }

            /* check parameters */
            if (decode)
            {
                if (parameters != null && _index.Type != null)
                {
                    try {
                        Asn1BerDecodeBuffer buffer = new Asn1BerDecodeBuffer(((Asn1OpenType)parameters).Value);
                        parameters = (Asn1Type)System.Activator.CreateInstance(_index.Type.GetType());
                        parameters.Decode(buffer, Asn1Tag.EXPL, 0);
                        buffer.InvokeEndElement("parameters", -1);
                    }
                    catch (Exception e) {
                        //Asn1Util.WriteStackTrace(e, Console.Error);
                        //throw new Exception("Asn1Exception(table constraint: parameters decode failed)");
                        throw e;
                    }
                }
            }
        }