HermaFx.Cryptography.ASN1.Decode C# (CSharp) Method

Decode() protected method

protected Decode ( byte asn1, int &anPos, int anLength ) : void
asn1 byte
anPos int
anLength int
return void
        protected void Decode(byte[] asn1, ref int anPos, int anLength)
        {
            byte nTag;
            int nLength;
            byte[] aValue;

            // minimum is 2 bytes (tag + length of 0)
            while (anPos < anLength - 1)
            {
                DecodeTLV(asn1, ref anPos, out nTag, out nLength, out aValue);
                // sometimes we get trailing 0
                if (nTag == 0)
                    continue;

                ASN1 elm = Add(new ASN1(nTag, aValue));

                if ((nTag & 0x20) == 0x20)
                {
                    int nConstructedPos = anPos;
                    elm.Decode(asn1, ref nConstructedPos, nConstructedPos + nLength);
                }
                anPos += nLength; // value length
            }
        }

Usage Example

Example #1
0
        // Note: Recursive
        protected void Decode(byte[] asn1, ref int anPos, int anLength)
        {
            byte nTag;
            int  nLength;

            byte[] aValue;

            // minimum is 2 bytes (tag + length of 0)
            while (anPos < anLength - 1)
            {
                DecodeTLV(asn1, ref anPos, out nTag, out nLength, out aValue);
                // sometimes we get trailing 0
                if (nTag == 0)
                {
                    continue;
                }

                ASN1 elm = Add(new ASN1(nTag, aValue));

                if ((nTag & 0x20) == 0x20)
                {
                    int nConstructedPos = anPos;
                    elm.Decode(asn1, ref nConstructedPos, nConstructedPos + nLength);
                }
                anPos += nLength;                 // value length
            }
        }