Beispiel #1
0
        private static void PrintItemHtml(SizeableType pThis, PEREffectiveConstraint cns, StreamWriterLevel o, long itemNo, IConstraint innerTypeConstraint)
        {
            int inc = ((pThis.minItems(cns) == pThis.maxItems(cns) ? 0 : 1));
            string cssClass = "EvenRow";
            o.WriteLine("<tr class=\"" + cssClass + "\">");
            o.WriteLine("<td class=\"no\">{0}</td>", (itemNo) == -1 ? "&#8734" : (itemNo + inc).ToString());
            o.WriteLine("<td class=\"field\">Item #{0}</td>", (itemNo) == -1 ? "&#8734" : itemNo.ToString());
            o.WriteLine("<td class=\"comment\">{0}</td>", "");
            o.WriteLine("<td class=\"type\">{0}</td>", InternalTypeName(pThis));

            string withComponentPart = string.Empty;
            if (innerTypeConstraint!=null)
            {
                withComponentPart = "<span style=\"color: yellow\">";
                withComponentPart += " (" + innerTypeConstraint.ToString() + ")";
                withComponentPart += "</span>" + ICDBType.WithComponentWhy;
                ICDBackend.m_WithComponentMustBeExplained = true;
            }

            o.WriteLine("<td class=\"constraint\">{0}</td>", o.Constraint(pThis.ItemConstraint(cns) + withComponentPart));

            ArrayType ppthis = pThis as ArrayType;
            if (ppthis != null && ppthis.m_type.GetFinalType() is IntegerType && ppthis.m_type.MinBitsInPER == 0 && ppthis.m_type.MaxBitsInPER == 0)
            {
                o.WriteLine("<td class=\"min\">0{0}</td>", ICDBType.ZeroBitsWhy);
                o.WriteLine("<td class=\"max\">0{0}</td>", ICDBType.ZeroBitsWhy);
                ICDBackend.m_ZeroBitsMustBeExplained = true;
            }
            else
            {
                o.WriteLine("<td class=\"min\">{0}</td>", (pThis.minItemBitsInPER(cns) == -1 ? "&#8734" : pThis.minItemBitsInPER(cns).ToString()));
                o.WriteLine("<td class=\"max\">{0}</td>", (pThis.maxItemBitsInPER(cns) == -1 ? "&#8734" : pThis.maxItemBitsInPER(cns).ToString()));
            }
            o.WriteLine("</tr>");
        }
Beispiel #2
0
        private static void PrintSizeLengthHtml(SizeableType pThis, PEREffectiveConstraint cns, StreamWriterLevel o, int p, string additonalConstraints)
        {
            string cssClass = "OddRow";
            long mnItems = pThis.minItems(cns);
            long mxItems = pThis.maxItems(cns);
            if (mnItems == mxItems)
                return;

            o.WriteLine("<tr class=\"" + cssClass + "\">");
            o.WriteLine("<td class=\"no\">1</td>");
            o.WriteLine("<td class=\"field\">Length</td>");
            //            if (mnItems!=mxItems)
            o.WriteLine("<td class=\"comment\">Special field used by PER to indicate the number of items present in the array.</td>");
            //            else
            //                o.WriteLine("<td class=\"comment\">Special field used by PER to indicate the number of items present in the array.In this case however, the length field requires zero bits because its value ({0}) is known in advanced by its size constraint.</td>", mxItems);

            o.WriteLine("<td class=\"type\">{0}</td>", "unsigned int");

            o.WriteLine("<td class=\"constraint\">{0}</td>", o.Constraint(cns.ToString() + additonalConstraints));
            o.WriteLine("<td class=\"min\">{0}</td>", pThis.minSizeBitsInPER(cns));
            o.WriteLine("<td class=\"max\">{0}</td>", (pThis.maxSizeBitsInPER(cns) == -1 ? "16<a href=\"#ARRAYS_SIZE_EXPLAINED123\"><span style=\"vertical-align: super\">why?</span></a>" : pThis.maxSizeBitsInPER(cns).ToString()));
            if (pThis.maxSizeBitsInPER(cns) == -1)
                DefaultBackend.m_HtmlLengthSizeMustBeExplained = true;
            o.WriteLine("</tr>");
        }
Beispiel #3
0
        public static void PrintHtml(SizeableType pThis, PEREffectiveConstraint cns, StreamWriterLevel o, int lev, List<string> comment, TypeAssigment tas, List<IConstraint> additonalConstraints)
        {
            WithComponentConstraint withComp = null;
            if (additonalConstraints != null && additonalConstraints.Count > 0)
                withComp = additonalConstraints[0] as WithComponentConstraint;

            o.WriteLine("<a name=\"{0}\"></a>", "ICD_" + tas.m_name.Replace("-", "_"));
            o.WriteLine("<table border=\"0\" width=\"100%\" >");
            o.WriteLine("<tbody>");
            o.WriteLine("<tr  bgcolor=\"{0}\">", (tas.m_createdThroughTabulization ? "#379CEE" : "#FF8f00"));
            o.WriteLine("<td height=\"35\" colspan=\"3\">");
            o.WriteLine("<font face=\"Verdana\" color=\"#FFFFFF\" size=\"4\">{0}</font><font face=\"Verdana\" color=\"#FFFFFF\" size=\"2\">({1}) </font>", tas.m_name, pThis.Name);
            o.WriteLine("<font face=\"Verdana\" color=\"#FFFFFF\" size=\"2\"><a href=\"#{0}\">ASN.1</a></font>", "ASN1_" + tas.m_name.Replace("-", "_"));
            o.WriteLine("</td>");
            o.WriteLine("<td height=\"35\" colspan=\"2\"  align=\"center\">");
            o.WriteLine("<font face=\"Verdana\" color=\"#FFFFFF\" size=\"2\">min = {0} bytes</font>", (pThis.MinBytesInPER == -1 ? "&#8734" : pThis.MinBytesInPER.ToString()));
            o.WriteLine("</td>");
            o.WriteLine("<td height=\"35\" colspan=\"2\" align=\"center\">");
            o.WriteLine("<font face=\"Verdana\" color=\"#FFFFFF\" size=\"2\">max = {0} bytes</font>", (pThis.MaxBytesInPER == -1 ? "&#8734" : pThis.MaxBytesInPER.ToString()));
            o.WriteLine("</td>");
            o.WriteLine("</tr>");

            IInternalContentsInHtml pICIH = pThis as IInternalContentsInHtml;
            if (pICIH != null)
                comment.Add(pICIH.InternalContentsInHtml(additonalConstraints));
            if (comment.Count > 0)
            {
                o.WriteLine("<tr class=\"CommentRow\">");
                o.WriteLine("<td class=\"comment\" colspan=\"7\">" + o.BR(comment) + "</td>");
                o.WriteLine("</tr>");
            }

            o.WriteLine("<tr class=\"headerRow\">");
            o.WriteLine("<td class=\"hrNo\">No</td>");
            o.WriteLine("<td class=\"hrField\">Field</td>");
            o.WriteLine("<td class=\"hrComment\">Comment</td>");
            o.WriteLine("<td class=\"hrType\">Type</td>");
            o.WriteLine("<td class=\"hrconstraint\">Constraint</td>");
            o.WriteLine("<td class=\"hrMin\">Min Length (bits)</td>");
            o.WriteLine("<td class=\"hrMax\">Max Length (bits)</td>");
            o.WriteLine("</tr>");

            IConstraint innerTypeConstraint = null;
            if (withComp != null)
                innerTypeConstraint = withComp.m_innerTypeConstraint;

            PrintSizeLengthHtml(pThis, cns, o, lev + 1, BaseConstraint.AsString(additonalConstraints));
            PrintItemHtml(pThis, cns, o, 1, innerTypeConstraint);

            long mxItems = pThis.maxItems(cns);
            if (mxItems > 2 || mxItems==-1)
            {
                o.WriteLine("<tr class=\"CommentRow\">");
                o.WriteLine("<td class=\"threeDots\" colspan=\"7\"> <p>. . .</p> </td>");
                o.WriteLine("</tr>");
            }

            if (pThis.maxItems(cns) >= 2 || mxItems==-1)
                PrintItemHtml(pThis, cns, o, pThis.maxItems(cns), innerTypeConstraint);

            o.WriteLine("</tbody>");
            o.WriteLine("</table>");
        }
Beispiel #4
0
        private static string InternalTypeName(SizeableType pThis)
        {
            if (pThis is ArrayType)
            {
                if (((ArrayType)pThis).m_type is ReferenceType)
                    return "<a href=\"#ICD_" + ((ArrayType)pThis).m_type.Name.Replace("-", "_") + "\">" + ((ArrayType)pThis).m_type.Name + "</a>";
                else
                    return ((ArrayType)pThis).m_type.Name;

            }
            if (pThis is NumericStringType)
                return "NUMERIC CHARACTER";
            if (pThis is IA5StringType)
                return "ASCII CHARACTER";
            if (pThis is BitStringType)
                return "BIT";
            if (pThis is OctetStringType)
                return "OCTET";

            throw new Exception("Internal Error");
        }
Beispiel #5
0
 public static void VarsNeededForEncode(SizeableType pThis, PEREffectiveConstraint cns, int arrayDepth, OrderedDictionary<string, CLocalVariable> existingVars)
 {
     string var = "i" + arrayDepth.ToString();
     if (!existingVars.ContainsKey(var))
     {
         existingVars.Add(var, new CLocalVariable(var, "int", 0, "0"));
     }
     if (pThis.maxItems(cns) > 0x10000)
     {
         var = "nCount" + arrayDepth.ToString();
         if (!existingVars.ContainsKey(var))
             existingVars.Add(var, new CLocalVariable(var, "asn1SccSint", 0, "0"));
         var = "curBlockSize" + arrayDepth.ToString();
         if (!existingVars.ContainsKey(var))
             existingVars.Add(var, new CLocalVariable(var, "asn1SccSint", 0, "0"));
         var = "curItem" + arrayDepth.ToString();
         if (!existingVars.ContainsKey(var))
             existingVars.Add(var, new CLocalVariable(var, "asn1SccSint", 0, "0"));
     }
 }
Beispiel #6
0
        public static void PrintCEncodeFragmentation(SizeableType pThis, PEREffectiveConstraint cns, StreamWriterLevel c, string errorCode, string varName, int lev,
            string nCountInit, string arrName, long max, string i, string prefix, string nCount, string curBlockSize, string curItem)
        {
            //            c.P(lev); c.WriteLine("/* Fragmentation required since {0} is grater than 64K*/", max);

            c.P(lev); c.WriteLine(nCountInit);
            c.P(lev); c.WriteLine("{0} = 0;", curBlockSize);
            c.P(lev); c.WriteLine("{0} = 0;", curItem);
            c.P(lev); c.WriteLine("while ({0} >= 0x4000)", nCount);
            c.P(lev++); c.WriteLine("{");
            c.P(lev); c.WriteLine("if ({0} >= 0x10000)", nCount);
            c.P(lev++); c.WriteLine("{");
            c.P(lev); c.WriteLine("{0} = 0x10000;", curBlockSize);
            c.P(lev); c.WriteLine("BitStream_EncodeConstraintWholeNumber(pBitStrm, 0xC4, 0, 0xFF);");
            c.P(--lev); c.WriteLine("}");
            c.P(lev); c.WriteLine("else if ({0} >= 0xC000)", nCount);
            c.P(lev++); c.WriteLine("{");
            c.P(lev); c.WriteLine("{0} = 0xC000;", curBlockSize);
            c.P(lev); c.WriteLine("BitStream_EncodeConstraintWholeNumber(pBitStrm, 0xC3, 0, 0xFF);");
            c.P(--lev); c.WriteLine("}");
            c.P(lev); c.WriteLine("else if ({0} >= 0x8000)", nCount);
            c.P(lev++); c.WriteLine("{");
            c.P(lev); c.WriteLine("{0} = 0x8000;", curBlockSize);
            c.P(lev); c.WriteLine("BitStream_EncodeConstraintWholeNumber(pBitStrm, 0xC2, 0, 0xFF);");
            c.P(--lev); c.WriteLine("}");
            c.P(lev); c.WriteLine("else");
            c.P(lev++); c.WriteLine("{");
            c.P(lev); c.WriteLine("{0} = 0x4000;", curBlockSize);
            c.P(lev); c.WriteLine("BitStream_EncodeConstraintWholeNumber(pBitStrm, 0xC1, 0, 0xFF);");
            c.P(--lev); c.WriteLine("}");

            c.P(lev); c.WriteLine("for({0}={1}; {0} < {2} + {1}; {0}++)", i, curItem, curBlockSize);
            c.P(lev); c.WriteLine("{");
            ((ISCCSizeable)pThis).PrintCEncodeItem(cns, c, errorCode + "_elem", prefix + arrName + "[" + i + "]", lev + 1);
            c.P(lev); c.WriteLine("}");
            c.P(lev); c.WriteLine("{0} += {1};", curItem, curBlockSize);
            c.P(lev); c.WriteLine("{0} -= {1};", nCount, curBlockSize);
            c.P(--lev); c.WriteLine("}");
            c.P(lev); c.WriteLine("if ({0} <= 0x7F)", nCount);
            c.P(lev + 1); c.WriteLine("BitStream_EncodeConstraintWholeNumber(pBitStrm, {0}, 0, 0xFF);", nCount);
            c.P(lev); c.WriteLine("else");
            c.P(lev++); c.WriteLine("{");
            c.P(lev); c.WriteLine("BitStream_AppendBit(pBitStrm, 1);");
            c.P(lev); c.WriteLine("BitStream_EncodeConstraintWholeNumber(pBitStrm, {0}, 0, 0x7FFF);", nCount);
            c.P(--lev); c.WriteLine("}");
            c.P(lev); c.WriteLine("for({0}={1}; {0} < {1} + {2}; {0}++)", i, curItem, nCount);
            c.P(lev); c.WriteLine("{");
            ((ISCCSizeable)pThis).PrintCEncodeItem(cns, c, errorCode + "_elem", prefix + arrName + "[" + i + "]", lev + 1);
            c.P(lev); c.WriteLine("}");
        }
Beispiel #7
0
        public static void PrintCEncode(SizeableType pThis, PEREffectiveConstraint cns, StreamWriterLevel c, string errorCode, string varName, int lev)
        {
            long min = pThis.minItems(cns);
            long max = pThis.maxItems(cns);
            string i = "i" + (CLocalVariable.GetArrayIndex(varName) + 1);
            string nCount = "nCount" + (CLocalVariable.GetArrayIndex(varName) + 1);
            string curBlockSize = "curBlockSize" + (CLocalVariable.GetArrayIndex(varName) + 1);
            string curItem = "curItem" + (CLocalVariable.GetArrayIndex(varName) + 1);

            string prefix = "";
            bool topLevel = !varName.Contains("->");

            if (topLevel)
                prefix = varName + "->";
            else
                prefix = varName + ".";
            if (max < 0x10000)
            {
                if (min != max)
                {
                    c.P(lev);
                    c.WriteLine("BitStream_EncodeConstraintWholeNumber(pBitStrm, {0}nCount, {1}, {2});", prefix, min, max);
                }
                else
                {
                    c.P(lev); c.WriteLine("/* No need to encode length (it is fixed size ({0})*/", min);
                }

                c.P(lev); c.WriteLine("for({0}=0;{0}<{1}nCount;{0}++)", i, prefix);
                c.P(lev); c.WriteLine("{");
                ((ISCCSizeable)pThis).PrintCEncodeItem(cns, c, errorCode + "_elem", prefix + "arr[" + i + "]", lev + 1);
                c.P(lev); c.WriteLine("}");
            }
            else
            {
                PrintCEncodeFragmentation(pThis, cns, c, errorCode, varName, lev,
                    string.Format(nCount + " = {0}nCount;", prefix), "arr", max, i, prefix,
                    nCount, curBlockSize, curItem);
            }
        }
Beispiel #8
0
        public static void PrintCDecodeFragmentation(SizeableType pThis, PEREffectiveConstraint cns, StreamWriterLevel c, string varName, int lev,
            string arrName, long max, string i, string prefix,
            string length, string curBlockSize, string nCount)
        {
            c.P(lev); c.WriteLine("/* Fragmentation required since {0} is grater than 64K*/", max);
            c.WriteCodeBlock(lev,
            @"if (!BitStream_DecodeConstraintWholeNumber(pBitStrm, &{1}, 0, 0xFF))
            {{
            *pErrCode = ERR_INSUFFICIENT_DATA;
            return FALSE;
            }}
            while(({1} & 0xC0)==0xC0)
            {{
            if ({1} == 0xC4)
            {2} = 0x10000;
            else if ({1} == 0xC3)
            {2} = 0xC000;
            else if ({1} == 0xC2)
            {2} = 0x8000;
            else if ({1} == 0xC1)
            {2} = 0x4000;
            else {{
            *pErrCode = ERR_INCORRECT_PER_STREAM;
            return FALSE;
            }}
            if ({3}+{2}>{4})
            {{
            *pErrCode = ERR_INSUFFICIENT_DATA;
            return FALSE;
            }}

            for({0}=0;{0}<{2};{0}++)
            {{", i, length, curBlockSize, nCount,max);

            ((ISCCSizeable)pThis).PrintCDecodeItem(cns, c, prefix + arrName + "[" + nCount + "+" + i + "]", lev + 2);

            c.WriteCodeBlock(lev,
            @"    }}
            {3}+={2};

            if (!BitStream_DecodeConstraintWholeNumber(pBitStrm, &{1}, 0, 0xFF)) {{
            *pErrCode = ERR_INSUFFICIENT_DATA;
            return FALSE;
            }}
            }}
            if ( ({1} & 0x80)>0)
            {{
            asn1SccSint len2;
            {1}<<=8;
            if (!BitStream_DecodeConstraintWholeNumber(pBitStrm, &len2, 0, 0xFF)) {{
            *pErrCode = ERR_INSUFFICIENT_DATA;
            return FALSE;
            }}
            {1} |= len2;
            {1} &= 0x7FFF;
            }}

            if ({3}+{1}>{4})
            {{
            *pErrCode = ERR_INSUFFICIENT_DATA;
            return FALSE;
            }}
            for({0}=0;{0}<{1};{0}++)
            {{
            ", i, length, curBlockSize, nCount,max);
            ((ISCCSizeable)pThis).PrintCDecodeItem(cns, c, prefix + arrName + "[" + nCount + "+" + i + "]", lev + 1);

            c.WriteCodeBlock(lev,
            @"}}
            {0}+=(long){1};", nCount, length);
            if (arrName != "")
            {
                c.P(lev);
                c.WriteLine("{0}nCount = (long){1};", prefix, nCount);
            }
        }
Beispiel #9
0
        public static void PrintCDecode(SizeableType pThis, PEREffectiveConstraint cns, StreamWriterLevel c, string varName, int lev)
        {
            long min = pThis.minItems(cns);
            long max = pThis.maxItems(cns);
            string i = "i" + (CLocalVariable.GetArrayIndex(varName) + 1);
            string length = "length" + (CLocalVariable.GetArrayIndex(varName) + 1);
            string curBlockSize = "curBlockSize" + (CLocalVariable.GetArrayIndex(varName) + 1);
            //            string curItem = "curItem" + (CLocalVariable.GetArrayIndex(varName) + 1);
            string nCount = "nCount" + (CLocalVariable.GetArrayIndex(varName) + 1);

            string prefix = "";
            bool topLevel = !varName.Contains("->");
            if (topLevel)
                prefix = varName + "->";
            else
                prefix = varName + ".";

            if (max < 0x10000)
            {
                if (min != max)
                {
                    c.P(lev);
                    c.WriteLine("if (!BitStream_DecodeConstraintWholeNumber(pBitStrm, &nCount, {0}, {1})) {{", min, max);
                    c.P(lev + 1);
                    c.WriteLine("*pErrCode = ERR_INSUFFICIENT_DATA;");
                    c.P(lev + 1);
                    c.WriteLine("return FALSE;");
                    c.P(lev);
                    c.WriteLine("}");
                    c.P(lev);
                    c.WriteLine("{0}nCount = (long)nCount;", prefix);
                }
                else
                {
                    c.P(lev);
                    c.WriteLine("{0}nCount = {1};", prefix, max);
                }

                c.P(lev); c.WriteLine("for({0}=0;{0}<{1}nCount;{0}++)", i, prefix);
                c.P(lev); c.WriteLine("{");
                ((ISCCSizeable)pThis).PrintCDecodeItem(cns, c, prefix + "arr[" + i + "]", lev + 1);
                c.P(lev); c.WriteLine("}");
            }
            else
            {
                c.P(lev); c.WriteLine("/* Fragmentation required since {0} is grater than 64K*/", max);
                PrintCDecodeFragmentation(pThis, cns, c, varName, lev,
                        "arr", max, i, prefix, length, curBlockSize, nCount);

            }
        }