public void GetAttributes_WhenOidNullOrEmpty_Throws(string oid)
        {
            var exception = Assert.Throws <ArgumentException>(
                () => AttributeUtility.GetAttributes(new CryptographicAttributeObjectCollection(), oid));

            Assert.Equal("oid", exception.ParamName);
        }
        public void GetAttributes_WhenAttributesNull_Throws()
        {
            var exception = Assert.Throws <ArgumentNullException>(
                () => AttributeUtility.GetAttributes(attributes: null, oid: "1.2.3"));

            Assert.Equal("attributes", exception.ParamName);
        }
        public void GetAttributes_WithMultipleMatches_ReturnsMatches()
        {
            using (var certificate = _fixture.GetDefaultCertificate())
            {
                var attributes = CreateAttributeCollection(certificate, _fixture.DefaultKeyPair.Private,
                                                           vector =>
                {
                    vector.Add(
                        new BcAttribute(
                            CmsAttributes.SigningTime,
                            new DerSet(new DerUtcTime(DateTime.UtcNow))));

                    vector.Add(
                        new BcAttribute(
                            PkcsObjectIdentifiers.IdAAEtsCommitmentType,
                            new DerSet(
                                new BcCommitmentTypeIndication(PkcsObjectIdentifiers.IdCtiEtsProofOfOrigin))));

                    vector.Add(
                        new BcAttribute(
                            PkcsObjectIdentifiers.IdAAEtsCommitmentType,
                            new DerSet(
                                new BcCommitmentTypeIndication(PkcsObjectIdentifiers.IdCtiEtsProofOfReceipt))));
                });

                var matches = AttributeUtility.GetAttributes(attributes, Oids.CommitmentTypeIndication).ToArray();

                Assert.Equal(2, matches.Length);
                Assert.Equal(
                    PkcsObjectIdentifiers.IdCtiEtsProofOfOrigin.ToString(),
                    CommitmentTypeIndication.Read(matches[0].Values[0].RawData).CommitmentTypeId.Value);
                Assert.Equal(
                    PkcsObjectIdentifiers.IdCtiEtsProofOfReceipt.ToString(),
                    CommitmentTypeIndication.Read(matches[1].Values[0].RawData).CommitmentTypeId.Value);
            }
        }
Esempio n. 4
0
        //
        // Static Methods
        //


        #region GetDrawer of type
        //TODO maybe use ScriptUtilityAttributeW for some
        /// <summary>
        /// Gets the drawer.
        /// </summary>
        /// <returns>The drawer.</returns>
        /// <param name="type">Type.</param>
        public static PropertyDrawer GetDrawer(Type type)
        {
            Type           typeDrawer;
            PropertyDrawer drawer = null;

            if (EditorUtilityEx.__drawers == null)
            {
                EditorUtilityEx.__drawers = new Dictionary <Type, PropertyDrawer> ();
                Type[] derivedTypes = ReflectionUtility.GetDerivedTypes(typeof(PropertyDrawer));
                CustomPropertyDrawer[] attributes;
                CustomPropertyDrawer   attribute;
                for (int i = 0; i < derivedTypes.Length; i++)
                {
                    typeDrawer = derivedTypes [i];

                    attributes = AttributeUtility.GetAttributes <CustomPropertyDrawer> (typeDrawer, false);

                    if (attributes != null)
                    {
                        for (int j = 0; j < attributes.Length; j++)
                        {
                            attribute = attributes [j];

                            if (attribute != null)
                            {
                                FieldInfo m_TypeFieldInfo = attribute.GetType().GetField("m_Type", BindingFlags.Instance | BindingFlags.NonPublic);



                                if (m_TypeFieldInfo != null)
                                {
                                    Type typeProperty = (Type)m_TypeFieldInfo.GetValue(attribute);



                                    if (typeProperty != null && typeProperty.BaseType != typeof(PropertyAttribute))
                                    {
                                        if (typeProperty.IsGenericType)
                                        {
                                            typeProperty = typeProperty.GetGenericTypeDefinition();
                                        }

                                        if (!EditorUtilityEx.__drawers.ContainsKey(typeProperty))
                                        {
                                            EditorUtilityEx.__drawers.Add(typeProperty, Activator.CreateInstance(typeDrawer) as PropertyDrawer);

//																				Debug.Log("  "+typeProperty.Name+" "+typeDrawer.Name+" "+typeProperty.BaseType);
                                        }
                                    }
                                }
                            }
                        }                                        //attributes
                    }
                }                                                //types in dll
            }

            if (type.IsGenericType)
            {
                type = type.GetGenericTypeDefinition();
            }


            EditorUtilityEx.__drawers.TryGetValue(type, out drawer);
            if (drawer != null)
            {
                return(drawer);
            }

            if (type.BaseType != null)
            {
                if (EditorUtilityEx.__drawers.TryGetValue(type.BaseType, out drawer))
                {
                    return(drawer);
                }
            }

            if (__drawerDefault == null)
            {
                __drawerDefault = new UnityDefaultPropertyDrawer();
            }


            return(__drawerDefault);
        }
        public void GetAttributes_WithNoMatches_ReturnsEmptyEnumerable()
        {
            var attributes = AttributeUtility.GetAttributes(new CryptographicAttributeObjectCollection(), Oids.SigningTime);

            Assert.Empty(attributes);
        }