Ejemplo n.º 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 (buffer)");
            }

            // decode ephemeralPublicKey

            if (context.MatchElemTag(Asn1Tag.CTXT, Asn1Tag.CONS, 0, elemLen, true))
            {
                ephemeralPublicKey = new SubjectPublicKeyInfo();
                ephemeralPublicKey.Decode(buffer, false, elemLen.Value);
            }

            // decode ukm

            if (context.MatchElemTag(Asn1Tag.Universal, Asn1Tag.PRIM, 4, elemLen, false))
            {
                ukm = new Asn1OctetString();
                ukm.Decode(buffer, true, elemLen.Value);
                if (!(ukm.Length == 8))
                {
                    throw new Exception("Asn1ConsVioException (ukm.Length, ukm.Length)");
                }
            }
            else
            {
                throw new Exception("Asn1MissingRequiredException (buffer)");
            }
        }
        public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
        {
            var elemLength = explicitTagging ? MatchTag(buffer, Asn1Tag.Sequence) : implicitLength;

            EncryptionParamSet = null;
            EphemeralPublicKey = null;
            Ukm = 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.MatchElemTag(0x80, 0x20, EocTypeCode, parsedLen, true))
            {
                EphemeralPublicKey = new SubjectPublicKeyInfo();
                EphemeralPublicKey.Decode(buffer, false, parsedLen.Value);
            }

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

            Ukm = new Asn1OctetString();
            Ukm.Decode(buffer, true, parsedLen.Value);

            if (Ukm.Length != 8)
            {
                throw ExceptionUtility.CryptographicException(Resources.Asn1ConsVioException, nameof(Ukm.Length), Ukm.Length);
            }
        }