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"); } } } }
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); }
public virtual int encodeClassType(object obj, 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); }
public virtual DecodedObject <object> decodeClassType(DecodedObject <object> decodedTag, Type objectClass, ElementInfo elementInfo, Stream stream) { if (CoderUtils.isImplements(objectClass, typeof(IASN1PreparedElement))) { return(decodePreparedElement(decodedTag, objectClass, elementInfo, stream)); } else if (elementInfo.hasPreparedInfo()) { 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)); } }