コード例 #1
0
        /// <inheritdoc/>
        public override byte[] Write()
        {
            if (Constructed)
            {
                throw new FormatException("The encoding of an object identifier value shall be primitive.");
            }

            var resBytes = new List <byte>();
            var oidParts = this.Content.Split(new string[] { "." }, StringSplitOptions.RemoveEmptyEntries)
                           .Select(p => Convert.ToInt32(p, CultureInfo.InvariantCulture)).ToArray();

            var  res       = new List <byte>(oidParts.Length - 1);
            byte firstByte = (byte)((40 * oidParts[0]) + oidParts[1]);

            res.Add(firstByte);

            // first 2 subidentifiers were already computed
            DerWriterUtils.ParseSubIdentifiers(oidParts.Skip(2).ToArray(), res);

            resBytes.AddRange(DerWriter.WriteTag(this.Asn1Class, this.Asn1Tag, this.Constructed));
            resBytes.AddRange(DerWriter.WriteLength(res, (Asn1Type)this.Asn1Tag));
            resBytes.AddRange(res);

            return(resBytes.ToArray());
        }
コード例 #2
0
        /// <inheritdoc/>
        public override byte[] Write()
        {
            if (Constructed)
            {
                throw new FormatException("The encoding of a relative object identifier value shall be primitive.");
            }

            var resBytes = new List <byte>();
            var oidParts = this.Content.Split(new string[] { "." }, StringSplitOptions.RemoveEmptyEntries)
                           .Select(p => Convert.ToInt32(p, CultureInfo.InvariantCulture)).ToArray();

            var res = new List <byte>(oidParts.Length);

            DerWriterUtils.ParseSubIdentifiers(oidParts, res);

            resBytes.AddRange(DerWriter.WriteTag(this.Asn1Class, this.Asn1Tag, this.Constructed));
            resBytes.AddRange(DerWriter.WriteLength(res, (Asn1Type)this.Asn1Tag));
            resBytes.AddRange(res);

            return(resBytes.ToArray());
        }