Esempio n. 1
0
        public override int Encode()
        {
            int length = 0;

            length += extnID.Encode();
            if (critical != null)
            {
                length += critical.Encode();
            }
            length += extnValue.Encode();

            byte[] lengthBytes = EncodeLength(length);
            derValue = new byte[1 + lengthBytes.Length + length];

            derValue[0] = 0x30; // sequence

            int d = 1;

            Array.Copy(lengthBytes, 0, derValue, d, lengthBytes.Length);
            d += lengthBytes.Length;

            Array.Copy(extnID.derValue, 0, derValue, d, extnID.derValue.Length);
            d += extnID.derValue.Length;
            if (critical != null)
            {
                Array.Copy(critical.derValue, 0, derValue, d, critical.derValue.Length);
                d += critical.derValue.Length;
            }
            Array.Copy(extnValue.derValue, 0, derValue, d, extnValue.derValue.Length);
            d += extnValue.derValue.Length;

            PrependContextTag();

            return(derValue.Length);
        }
        // TODO: note 4.1.2.9 of RFC5280 - there are some additional requirements on CAs
        // especially regarding the optional path length stuff
        public void ExtensionBasicConstraints(bool ca)
        {
            if (extensions == null)
            {
                extensions = new AsnExtensions();
            }

            AsnBoolean caFlag = new AsnBoolean(ca);
            int        length = caFlag.Encode();

            byte[] bytes = new byte[length + 2];
            bytes[0] = 0x30;             // it's a sequence
            bytes[1] = (byte)length;
            Array.Copy(caFlag.derValue, 0, bytes, 2, caFlag.derValue.Length);

            AsnExtension extension = new AsnExtension(new AsnOid("2.5.29.19"), true, bytes);

            extensions.extensions.Add(extension);
        }