NBitcoin.BouncyCastle.Asn1.DerOutputStream.WriteTag C# (CSharp) Method

WriteTag() public method

public WriteTag ( int flags, int tagNo ) : void
flags int
tagNo int
return void
		public void WriteTag(
			int flags,
			int tagNo)
		{
			if(tagNo < 31)
			{
				WriteByte((byte)(flags | tagNo));
			}
			else
			{
				WriteByte((byte)(flags | 0x1f));
				if(tagNo < 128)
				{
					WriteByte((byte)tagNo);
				}
				else
				{
					byte[] stack = new byte[5];
					int pos = stack.Length;

					stack[--pos] = (byte)(tagNo & 0x7F);

					do
					{
						tagNo >>= 7;
						stack[--pos] = (byte)(tagNo & 0x7F | 0x80);
					}
					while(tagNo > 127);

					Write(stack, pos, stack.Length - pos);
				}
			}
		}

Usage Example

示例#1
0
        internal override void Encode(
            DerOutputStream derOut)
        {
            if (derOut is Asn1OutputStream || derOut is BerOutputStream)
            {
                derOut.WriteTag((byte)(Asn1Tags.Constructed | Asn1Tags.Tagged), tagNo);
                derOut.WriteByte(0x80);

                if (!IsEmpty())
                {
                    if (!explicitly)
                    {
                        IEnumerable eObj;
                        if (obj is Asn1OctetString)
                        {
                            if (obj is BerOctetString)
                            {
                                eObj = (BerOctetString)obj;
                            }
                            else
                            {
                                Asn1OctetString octs = (Asn1OctetString)obj;
                                eObj = new BerOctetString(octs.GetOctets());
                            }
                        }
                        else if (obj is Asn1Sequence)
                        {
                            eObj = (Asn1Sequence)obj;
                        }
                        else if (obj is Asn1Set)
                        {
                            eObj = (Asn1Set)obj;
                        }
                        else
                        {
                            throw Platform.CreateNotImplementedException(obj.GetType().Name);
                        }

                        foreach (Asn1Encodable o in eObj)
                        {
                            derOut.WriteObject(o);
                        }
                    }
                    else
                    {
                        derOut.WriteObject(obj);
                    }
                }

                derOut.WriteByte(0x00);
                derOut.WriteByte(0x00);
            }
            else
            {
                base.Encode(derOut);
            }
        }
All Usage Examples Of NBitcoin.BouncyCastle.Asn1.DerOutputStream::WriteTag