Esempio n. 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.ToString() + "' 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.ToString() + "' out of bound");
             }
         }
         else
         if (elementInfo.isAttributePresent <ASN1SizeConstraint>())
         {
             ASN1SizeConstraint constraint = elementInfo.getAttribute <ASN1SizeConstraint>();
             if (val != constraint.Max)
             {
                 throw new Exception("Length of '" + elementInfo.AnnotatedClass.ToString() + "' out of bound");
             }
         }
     }
 }
Esempio n. 2
0
        public static int getStringTagForElement(ElementInfo elementInfo)
        {
            int result = UniversalTags.PrintableString;

            if (elementInfo.hasPreparedInfo())
            {
                result = ((ASN1StringMetadata)elementInfo.PreparedInfo.TypeMetadata).StringType;
            }
            else if (elementInfo.isAttributePresent <ASN1String>())
            {
                ASN1String val = elementInfo.getAttribute <ASN1String>();
                result = val.StringType;
            }
            else if (elementInfo.ParentAnnotatedClass != null && elementInfo.isParentAttributePresent <ASN1String>())
            {
                ASN1String value = elementInfo.getParentAttribute <ASN1String>();
                result = value.StringType;
            }
            return(result);
        }
Esempio n. 3
0
        public virtual int encodeClassType(object obj, System.IO.Stream stream, ElementInfo elementInfo)
        {
            int resultSize = 0;

            if (elementInfo.hasPreparedInfo())
            {
                resultSize += elementInfo.PreparedInfo.TypeMetadata.encode(this, obj, stream, elementInfo);
            }
            else
            if (obj is IASN1PreparedElement)
            {
                resultSize += encodePreparedElement(obj, stream, elementInfo);
            }
            else
            if (elementInfo.isAttributePresent <ASN1SequenceOf>())
            {
                resultSize += encodeSequenceOf(obj, stream, elementInfo);
            }
            else
            if (elementInfo.isAttributePresent <ASN1Sequence>())
            {
                resultSize += encodeSequence(obj, stream, elementInfo);
            }
            else
            if (elementInfo.isAttributePresent <ASN1Choice>())
            {
                resultSize += encodeChoice(obj, stream, elementInfo);
            }
            else
            if (elementInfo.isAttributePresent <ASN1BoxedType>())
            {
                resultSize += encodeBoxedType(obj, stream, elementInfo);
            }
            else
            if (elementInfo.isAttributePresent <ASN1Enum>())
            {
                resultSize += encodeEnum(obj, stream, elementInfo);
            }
            else
            if (elementInfo.isAttributePresent <ASN1Boolean>())
            {
                resultSize += encodeBoolean(obj, stream, elementInfo);
            }
            else
            if (elementInfo.isAttributePresent <ASN1Any>())
            {
                resultSize += encodeAny(obj, stream, elementInfo);
            }
            else
            if (elementInfo.isAttributePresent <ASN1Integer>())
            {
                resultSize += encodeInteger(obj, stream, elementInfo);
            }
            else
            if (elementInfo.isAttributePresent <ASN1Real>())
            {
                resultSize += encodeReal(obj, stream, elementInfo);
            }
            else
            if (elementInfo.isAttributePresent <ASN1OctetString>())
            {
                resultSize += encodeOctetString(obj, stream, elementInfo);
            }
            else
            if (elementInfo.isAttributePresent <ASN1BitString>() || obj.GetType().Equals(typeof(BitString)))
            {
                resultSize += encodeBitString(obj, stream, elementInfo);
            }
            else
            if (elementInfo.isAttributePresent <ASN1ObjectIdentifier>() || obj.GetType().Equals(typeof(ObjectIdentifier)))
            {
                resultSize += encodeObjectIdentifier(obj, stream, elementInfo);
            }
            else
            if (elementInfo.isAttributePresent <ASN1String>())
            {
                resultSize += encodeString(obj, stream, elementInfo);
            }
            else
            if (elementInfo.isAttributePresent <ASN1Null>())
            {
                resultSize += encodeNull(obj, stream, elementInfo);
            }
            else
            if (elementInfo.isAttributePresent <ASN1Element>())
            {
                resultSize += encodeElement(obj, stream, elementInfo);
            }
            else
            {
                resultSize += encodeCSElement(obj, stream, elementInfo);
            }
            return(resultSize);
        }
Esempio n. 4
0
 public virtual DecodedObject <object> decodeClassType(DecodedObject <object> decodedTag, System.Type objectClass, ElementInfo elementInfo, System.IO.Stream stream)
 {
     if (CoderUtils.isImplements(objectClass, typeof(IASN1PreparedElement)))
     {
         return(decodePreparedElement(decodedTag, objectClass, elementInfo, stream));
     }
     else
     if (elementInfo.hasPreparedInfo() && elementInfo.PreparedInfo.TypeMetadata != null)     // Pavel
     {
         return(elementInfo.PreparedInfo.TypeMetadata.decode(
                    this, decodedTag, objectClass, elementInfo, stream
                    ));
     }
     else
     if (elementInfo.isAttributePresent <ASN1SequenceOf>())
     {
         return(decodeSequenceOf(decodedTag, objectClass, elementInfo, stream));
     }
     else
     if (elementInfo.isAttributePresent <ASN1Sequence>())
     {
         return(decodeSequence(decodedTag, objectClass, elementInfo, stream));
     }
     else
     if (elementInfo.isAttributePresent <ASN1Choice>())
     {
         return(decodeChoice(decodedTag, objectClass, elementInfo, stream));
     }
     else
     if (elementInfo.isAttributePresent <ASN1BoxedType>())
     {
         return(decodeBoxedType(decodedTag, objectClass, elementInfo, stream));
     }
     else
     if (elementInfo.isAttributePresent <ASN1Enum>())
     {
         return(decodeEnum(decodedTag, objectClass, elementInfo, stream));
     }
     else
     if (elementInfo.isAttributePresent <ASN1Boolean>())
     {
         return(decodeBoolean(decodedTag, objectClass, elementInfo, stream));
     }
     else
     if (elementInfo.isAttributePresent <ASN1Any>())
     {
         return(decodeAny(decodedTag, objectClass, elementInfo, stream));
     }
     else
     if (elementInfo.isAttributePresent <ASN1Integer>())
     {
         return(decodeInteger(decodedTag, objectClass, elementInfo, stream));
     }
     else
     if (elementInfo.isAttributePresent <ASN1Real>())
     {
         return(decodeReal(decodedTag, objectClass, elementInfo, stream));
     }
     else
     if (elementInfo.isAttributePresent <ASN1OctetString>())
     {
         return(decodeOctetString(decodedTag, objectClass, elementInfo, stream));
     }
     else
     if (elementInfo.isAttributePresent <ASN1BitString>() || elementInfo.AnnotatedClass.Equals(typeof(BitString)))
     {
         return(decodeBitString(decodedTag, objectClass, elementInfo, stream));
     }
     else
     if (elementInfo.isAttributePresent <ASN1ObjectIdentifier>() || elementInfo.AnnotatedClass.Equals(typeof(ObjectIdentifier)))
     {
         return(decodeObjectIdentifier(decodedTag, objectClass, elementInfo, stream));
     }
     else
     if (elementInfo.isAttributePresent <ASN1String>())
     {
         return(decodeString(decodedTag, objectClass, elementInfo, stream));
     }
     else
     if (elementInfo.isAttributePresent <ASN1Null>())
     {
         return(decodeNull(decodedTag, objectClass, elementInfo, stream));
     }
     else
     if (elementInfo.isAttributePresent <ASN1Element>())
     {
         return(decodeElement(decodedTag, objectClass, elementInfo, stream));
     }
     else
     {
         return(decodeCSElement(decodedTag, objectClass, elementInfo, stream));
     }
 }