コード例 #1
0
 public static void checkConstraints(long val, ElementInfo elementInfo)
 {
     if (elementInfo.hasPreparedInfo())
     {
         if (elementInfo.PreparedInfo.hasConstraint())
         {
             if (!elementInfo.PreparedInfo.Constraint.checkValue(val))
             {
                 throw new Exception("Length of '" + elementInfo.AnnotatedClass + "' out of bound");
             }
         }
     }
     else
     {
         if (elementInfo.isAttributePresent <ASN1ValueRangeConstraint>())
         {
             ASN1ValueRangeConstraint constraint = elementInfo.getAttribute <ASN1ValueRangeConstraint>();
             if (val > constraint.Max || val < constraint.Min)
             {
                 throw new Exception("Length of '" + elementInfo.AnnotatedClass + "' out of bound");
             }
         }
         else if (elementInfo.isAttributePresent <ASN1SizeConstraint>())
         {
             ASN1SizeConstraint constraint = elementInfo.getAttribute <ASN1SizeConstraint>();
             if (val != constraint.Max)
             {
                 throw new Exception("Length of '" + elementInfo.AnnotatedClass + "' out of bound");
             }
         }
     }
 }
コード例 #2
0
        protected int encodeLength(int val, ElementInfo elementInfo, System.IO.Stream stream)
        {
            CoderUtils.checkConstraints(val, elementInfo);
            int resultSize = 0;
            BitArrayOutputStream bitStream = (BitArrayOutputStream)stream;

            if (elementInfo.hasPreparedInfo())
            {
                if (elementInfo.PreparedInfo.hasConstraint())
                {
                    IASN1ConstraintMetadata constraint = elementInfo.PreparedInfo.Constraint;
                    if (constraint is ASN1ValueRangeConstraintMetadata)
                    {
                        resultSize += encodeConstraintLengthDeterminant(
                            val,
                            (int)((ASN1ValueRangeConstraintMetadata)constraint).Min,
                            (int)((ASN1ValueRangeConstraintMetadata)constraint).Max,
                            bitStream
                            );
                    }
                    else
                    if (constraint is ASN1SizeConstraintMetadata)
                    {
                    }
                }
                else
                {
                    resultSize += encodeLengthDeterminant(val, bitStream);
                }
            }
            else
            {
                if (elementInfo.isAttributePresent <ASN1ValueRangeConstraint>())
                {
                    ASN1ValueRangeConstraint constraint = elementInfo.getAttribute <ASN1ValueRangeConstraint>();
                    resultSize += encodeConstraintLengthDeterminant(val, (int)constraint.Min, (int)constraint.Max, bitStream);
                }
                else
                if (elementInfo.isAttributePresent <ASN1SizeConstraint>())
                {
                    ASN1SizeConstraint constraint = elementInfo.getAttribute <ASN1SizeConstraint>();
                }
                else
                {
                    resultSize += encodeLengthDeterminant(val, bitStream);
                }
            }
            return(resultSize);
        }
コード例 #3
0
        protected virtual int decodeLength(ElementInfo elementInfo, System.IO.Stream stream)
        {
            int result = 0;
            BitArrayInputStream bitStream = (BitArrayInputStream)stream;

            if (elementInfo.hasPreparedInfo())
            {
                if (elementInfo.PreparedInfo.hasConstraint())
                {
                    IASN1ConstraintMetadata constraint = elementInfo.PreparedInfo.Constraint;
                    if (constraint is ASN1ValueRangeConstraintMetadata)
                    {
                        result = decodeConstraintLengthDeterminant(
                            (int)((ASN1ValueRangeConstraintMetadata)constraint).Min,
                            (int)((ASN1ValueRangeConstraintMetadata)constraint).Max,
                            bitStream
                            );
                    }
                    else
                    if (constraint is ASN1SizeConstraintMetadata)
                    {
                        result = (int)((ASN1SizeConstraintMetadata)constraint).Max;
                    }
                }
                else
                {
                    result = decodeLengthDeterminant(bitStream);
                }
            }
            else
            if (elementInfo.isAttributePresent <ASN1ValueRangeConstraint>())
            {
                ASN1ValueRangeConstraint constraint = elementInfo.getAttribute <ASN1ValueRangeConstraint>();
                result = decodeConstraintLengthDeterminant((int)constraint.Min, (int)constraint.Max, bitStream);
            }
            else
            if (elementInfo.isAttributePresent <ASN1SizeConstraint>())
            {
                ASN1SizeConstraint constraint = elementInfo.getAttribute <ASN1SizeConstraint>();
                result = (int)constraint.Max;
            }
            else
            {
                result = decodeLengthDeterminant(bitStream);
            }
            CoderUtils.checkConstraints(result, elementInfo);
            return(result);
        }
コード例 #4
0
 public ASN1SizeConstraintMetadata(ASN1SizeConstraint annotation)
 {
     maxValue = annotation.Max;
 }