예제 #1
0
        public virtual int encodeSequenceField(object obj, int fieldIdx, PropertyInfo field, System.IO.Stream stream, ElementInfo elementInfo)
        {
            ElementInfo info = new ElementInfo();

            info.AnnotatedClass = field;

            if (elementInfo.hasPreparedInfo())
            {
                info.PreparedInfo = elementInfo.PreparedInfo.getPropertyMetadata(fieldIdx);
            }
            else
            {
                info.ASN1ElementInfo = CoderUtils.getAttribute <ASN1Element>(field);
            }

            int resultSize = 0;

            if (CoderUtils.isNullField(field, info))
            {
                return(encodeNull(obj, stream, elementInfo));
            }
            else
            {
                object invokeObjResult = invokeGetterMethodForField(field, obj, info);
                if (invokeObjResult != null)
                {
                    resultSize += encodeClassType(invokeObjResult, stream, info);
                }
                else
                {
                    CoderUtils.checkForOptionalField(field, info);
                }
            }
            return(resultSize);
        }
예제 #2
0
        /// <param name="obj">The encoded sequence</param>
        /// <param name="fieldIdx">Index of the sequence field to be encoded</param>
        /// <param name="field">Field of the encoded sequence to be encoded</param>
        /// <param name="stream"></param>
        /// <param name="elementInfo">ElementInfo for the encoded sequence</param>
        public virtual int encodeSequenceField(object obj, int fieldIdx, PropertyInfo field, System.IO.Stream stream, ElementInfo elementInfo)
        {
            ElementInfo info = new ElementInfo();

            info.AnnotatedClass = field;
            if (elementInfo.hasPreparedInfo())
            {
                info.PreparedInfo = elementInfo.PreparedInfo.getPropertyMetadata(fieldIdx);
            }
            else
            {
                info.ASN1ElementInfo = CoderUtils.getAttribute <ASN1Element>(field);
            }

            if (CoderUtils.isNullField(field, info))
            {
                return(encodeNull(obj, stream, elementInfo));
            }
            else
            {
                object invokeObjResult = invokeGetterMethodForField(field, obj, info);
                if (invokeObjResult == null)
                {
                    CoderUtils.checkForOptionalField(field, info);
                    return(0);
                }
                else if (CoderUtils.isDefaultField(field, info))
                {
                    // skip the field if the current value equals to the default value (this is optional for BER, but mandatory for DER)
                    object newSequenceInstance = Activator.CreateInstance(obj.GetType());
                    CoderUtils.initDefaultValues(newSequenceInstance);
                    object defaultFieldValue = invokeGetterMethodForField(field, newSequenceInstance, info);
                    return(CoderUtils.AreEqual(defaultFieldValue, invokeObjResult) ? 0 : encodeClassType(invokeObjResult, stream, info));
                }
                else
                {
                    return(encodeClassType(invokeObjResult, stream, info));
                }
            }
        }
예제 #3
0
        public virtual DecodedObject <object> decodeSequenceField(DecodedObject <object> fieldTag, object sequenceObj, int fieldIdx, PropertyInfo field, System.IO.Stream stream, ElementInfo elementInfo, bool checkOptional)
        {
            ElementInfo info = new ElementInfo();

            info.AnnotatedClass  = field;
            info.MaxAvailableLen = elementInfo.MaxAvailableLen;
            if (elementInfo.hasPreparedInfo())
            {
                info.PreparedInfo = elementInfo.PreparedInfo.getPropertyMetadata(fieldIdx);
            }
            else
            {
                info.ASN1ElementInfo = CoderUtils.getAttribute <ASN1Element>(field);
            }

            if (CoderUtils.isNullField(field, info))
            {
                return(decodeNull(fieldTag, field.PropertyType, info, stream));
            }
            else
            {
                DecodedObject <object> val = decodeClassType(fieldTag, field.PropertyType, info, stream);
                if (val != null)
                {
                    invokeSetterMethodForField(field, sequenceObj, val.Value, info);
                }
                else
                {
                    if (checkOptional)
                    {
                        CoderUtils.checkForOptionalField(field, info);
                    }
                }
                return(val);
            }
        }