Esempio n. 1
0
        public static DecodedObject <int> getTagValueForElement(ElementInfo info, int tagClass, int elemenType, int universalTag)
        {
            DecodedObject <int> result = new DecodedObject <int>();

            // result.Value =  tagClass | elemenType | universalTag;
            if (universalTag < UniversalTags.LastUniversal)
            {
                result.Value = tagClass | elemenType | universalTag;
            }
            else
            {
                result = getTagValue(tagClass, elemenType, universalTag, universalTag, tagClass);
            }

            result.Size = 1;
            if (info.hasPreparedInfo())
            {
                ASN1ElementMetadata meta = info.PreparedASN1ElementInfo;
                if (meta != null && meta.HasTag)
                {
                    result = getTagValue(tagClass, elemenType, universalTag,
                                         meta.Tag,
                                         meta.TagClass
                                         );
                }
            }
            else
            {
                ASN1Element elementInfo = null;
                if (info.ASN1ElementInfo != null)
                {
                    elementInfo = info.ASN1ElementInfo;
                }
                else
                if (info.isAttributePresent <ASN1Element>())
                {
                    elementInfo = info.getAttribute <ASN1Element>();
                }

                if (elementInfo != null)
                {
                    if (elementInfo.HasTag)
                    {
                        result = getTagValue(tagClass, elemenType, universalTag, elementInfo.Tag, elementInfo.TagClass);
                    }
                }
            }
            return(result);
        }
Esempio n. 2
0
        public int encodePreparedElement(object obj, Stream stream, ElementInfo elementInfo)
        {
            IASN1PreparedElement preparedInstance = (IASN1PreparedElement)obj;

            elementInfo.PreparedInstance = (preparedInstance);
            ASN1ElementMetadata elementDataSave = null;

            if (elementInfo.hasPreparedASN1ElementInfo())
            {
                elementDataSave = elementInfo.PreparedASN1ElementInfo;
            }
            elementInfo.PreparedInfo = (preparedInstance.PreparedData);
            if (elementDataSave != null)
            {
                elementInfo.PreparedASN1ElementInfo = (elementDataSave);
            }
            return(preparedInstance.PreparedData.TypeMetadata.encode(
                       this, obj, stream, elementInfo
                       ));
        }
Esempio n. 3
0
        public DecodedObject <object> decodePreparedElement(DecodedObject <object> decodedTag, Type objectClass, ElementInfo elementInfo, Stream stream)
        {
            IASN1PreparedElementData saveInfo         = elementInfo.PreparedInfo;
            IASN1PreparedElement     preparedInstance = (IASN1PreparedElement)createInstanceForElement(objectClass, elementInfo);

            elementInfo.PreparedInstance = preparedInstance;
            ASN1ElementMetadata elementDataSave = null;

            if (elementInfo.hasPreparedASN1ElementInfo())
            {
                elementDataSave = elementInfo.PreparedASN1ElementInfo;
            }
            elementInfo.PreparedInfo = preparedInstance.PreparedData;
            if (elementDataSave != null)
            {
                elementInfo.PreparedASN1ElementInfo = elementDataSave;
            }
            DecodedObject <object> result = preparedInstance.PreparedData.TypeMetadata.decode(
                this, decodedTag, objectClass, elementInfo, stream
                );

            elementInfo.PreparedInfo = saveInfo;
            return(result);
        }
        /*public ASN1PreparedElementData(Type parentClass, String propertyName)
         * {
         *  try
         *  {
         *      PropertyInfo field = parentClass.GetProperty(propertyName);
         *      setupMetadata(field, field.PropertyType);
         *      setupAccessors(parentClass, field);
         *  }
         *  catch (Exception ex)
         *  {
         *      ex = null;
         *  }
         * }*/


        private void setupMetadata(ICustomAttributeProvider annotated, Type objectClass)
        {
            if (CoderUtils.isAttributePresent <ASN1_MMSDataArray>(annotated)) // Pavel
            {
                if (CoderUtils.isAttributePresent <ASN1SequenceOf>(annotated) && ASN1_MMSDataArray.Depth < 10)
                {
                    ASN1_MMSDataArray.Depth++;
                    typeMeta = new ASN1SequenceOfMetadata(CoderUtils.getAttribute <ASN1SequenceOf> (annotated),
                                                          objectClass,
                                                          annotated
                                                          );
                }
            }
            else
            if (CoderUtils.isAttributePresent <ASN1_MMSDataStructure>(annotated))    // Pavel
            {
                if (CoderUtils.isAttributePresent <ASN1SequenceOf>(annotated) && ASN1_MMSDataStructure.Depth < 10)
                {
                    ASN1_MMSDataStructure.Depth++;
                    typeMeta = new ASN1SequenceOfMetadata(CoderUtils.getAttribute <ASN1SequenceOf> (annotated),
                                                          objectClass,
                                                          annotated
                                                          );
                }
            }
            else
            if (CoderUtils.isAttributePresent <ASN1SequenceOf>(annotated))
            {
                typeMeta = new ASN1SequenceOfMetadata(CoderUtils.getAttribute <ASN1SequenceOf> (annotated),
                                                      objectClass,
                                                      annotated
                                                      );
            }
            else
            if (CoderUtils.isAttributePresent <ASN1Sequence>(annotated))
            {
                typeMeta = new ASN1SequenceMetadata(CoderUtils.getAttribute <ASN1Sequence> (annotated));
            }
            else
            if (CoderUtils.isAttributePresent <ASN1Choice>(annotated))
            {
                typeMeta = new ASN1ChoiceMetadata(CoderUtils.getAttribute <ASN1Choice> (annotated));
            }
            else
            if (CoderUtils.isAttributePresent <ASN1Enum>(annotated))
            {
                typeMeta = new ASN1EnumMetadata(CoderUtils.getAttribute <ASN1Enum> (annotated));
            }
            else
            if (CoderUtils.isAttributePresent <ASN1Boolean>(annotated))
            {
                typeMeta = new ASN1BooleanMetadata(CoderUtils.getAttribute <ASN1Boolean> (annotated));
            }
            else
            if (CoderUtils.isAttributePresent <ASN1Any>(annotated))
            {
                typeMeta = new ASN1AnyMetadata(CoderUtils.getAttribute <ASN1Any> (annotated));
            }
            else
            if (CoderUtils.isAttributePresent <ASN1Integer>(annotated))
            {
                typeMeta = new ASN1IntegerMetadata(CoderUtils.getAttribute <ASN1Integer> (annotated));
            }
            else
            if (CoderUtils.isAttributePresent <ASN1Real>(annotated))
            {
                typeMeta = new ASN1RealMetadata(CoderUtils.getAttribute <ASN1Real> (annotated));
            }
            else
            if (CoderUtils.isAttributePresent <ASN1OctetString>(annotated))
            {
                typeMeta = new ASN1OctetStringMetadata(CoderUtils.getAttribute <ASN1OctetString> (annotated));
            }
            else
            if (CoderUtils.isAttributePresent <ASN1BitString>(annotated) || objectClass.Equals(typeof(BitString)))
            {
                typeMeta = new ASN1BitStringMetadata(CoderUtils.getAttribute <ASN1BitString> (annotated));
            }
            else
            if (CoderUtils.isAttributePresent <ASN1ObjectIdentifier>(annotated) || objectClass.Equals(typeof(ObjectIdentifier)))
            {
                typeMeta = new ASN1ObjectIdentifierMetadata(CoderUtils.getAttribute <ASN1ObjectIdentifier>(annotated));
            }
            else
            if (CoderUtils.isAttributePresent <ASN1String>(annotated))
            {
                typeMeta = new ASN1StringMetadata(CoderUtils.getAttribute <ASN1String> (annotated));
            }
            else
            if (CoderUtils.isAttributePresent <ASN1Null>(annotated))
            {
                typeMeta = new ASN1NullMetadata(CoderUtils.getAttribute <ASN1Null> (annotated));
            }
            else
            if (CoderUtils.isAttributePresent <ASN1BoxedType>(annotated))
            {
                typeMeta = new ASN1BoxedTypeMetadata(objectClass, CoderUtils.getAttribute <ASN1BoxedType> (annotated));
            }
            else
            if (CoderUtils.isAttributePresent <ASN1Element>(annotated))
            {
                typeMeta = new ASN1ElementMetadata(CoderUtils.getAttribute <ASN1Element> (annotated));
            }
            else
            if (objectClass.Equals(typeof(String)))
            {
                typeMeta = new ASN1StringMetadata( );
            }
            else
            if (objectClass.Equals(typeof(int)))
            {
                typeMeta = new ASN1IntegerMetadata( );
            }
            else
            if (objectClass.Equals(typeof(long)))
            {
                typeMeta = new ASN1IntegerMetadata( );
            }
            else
            if (objectClass.Equals(typeof(double)))
            {
                typeMeta = new ASN1RealMetadata( );
            }
            else
            if (objectClass.Equals(typeof(bool)))
            {
                typeMeta = new ASN1BooleanMetadata( );
            }
            else
            if (objectClass.Equals(typeof(byte[])))
            {
                typeMeta = new ASN1OctetStringMetadata( );
            }

            if (CoderUtils.isAttributePresent <ASN1Element>(annotated))
            {
                asn1ElementInfo = new ASN1ElementMetadata(CoderUtils.getAttribute <ASN1Element>(annotated));
            }

            //ASN1CyclicDefinition.Depth = 0; // Pavel
            setupConstraint(annotated);
        }