public void Load_WithAuthorSignatureWithMultipleSigningCertificateV2AttributeValues_Throws() { using (var test = new LoadTest(_fixture)) { test.CmsSigner.SignedAttributes.Add( AttributeUtility.CreateCommitmentTypeIndication(SignatureType.Author)); test.CmsSigner.SignedAttributes.Add(new Pkcs9SigningTime()); var attribute = AttributeUtility.CreateSigningCertificateV2(test.Certificate, HashAlgorithmName.SHA256); attribute.Values.Add(attribute.Values[0]); test.CmsSigner.SignedAttributes.Add(attribute); test.SignedCms.ComputeSignature(test.CmsSigner); var exception = Assert.Throws <SignatureException>( () => PrimarySignature.Load(test.SignedCms.Encode())); Assert.Equal(NuGetLogCode.NU3011, exception.Code); Assert.Equal("The signing-certificate-v2 attribute must have exactly one attribute value.", exception.Message); } }
public void GetNuGetV3ServiceIndexUrl_WithMultipleAttributeValues_Throws() { using (var certificate = _fixture.GetDefaultCertificate()) { var attributes = CreateAttributeCollection(certificate, _fixture.DefaultKeyPair.Private, vector => { var value = new DerIA5String("https://test.test"); var attribute = new BcAttribute( new DerObjectIdentifier(Oids.NuGetV3ServiceIndexUrl), new DerSet(value, value)); vector.Add(attribute); }); var exception = Assert.Throws <SignatureException>( () => AttributeUtility.GetNuGetV3ServiceIndexUrl(attributes)); Assert.Equal( "The nuget-v3-service-index-url attribute must have exactly one attribute value.", exception.Message); } }
private XmlAttributeOverrides CreateAttributeOverrides(Type concreteType) { XmlAttributeOverrides attributeOverrides = new XmlAttributeOverrides(); foreach (MemberInfo memberInfo in concreteType.FindMembers( MemberTypes.Field | MemberTypes.Property, BindingFlags.Instance | BindingFlags.Public, delegate { return(true); }, null)) { XmlAttributes attributes = new XmlAttributes(); foreach (XmlElementAttribute attribute in AttributeUtility.GetCustomAttributes <XmlElementAttribute> (memberInfo, true)) { attributes.XmlElements.Add(attribute); } attributes.XmlAttribute = AttributeUtility.GetCustomAttribute <XmlAttributeAttribute> (memberInfo, true); attributes.XmlIgnore = attributes.XmlAttribute == null && attributes.XmlElements.Count == 0; attributeOverrides.Add(concreteType, memberInfo.Name, attributes); } return(attributeOverrides); }
public void Load_WithAuthorSignatureWithoutPkcs9SigningTimeAttribute_Throws() { using (var test = new LoadTest(_fixture)) { var chain = new List <X509Certificate2>() { test.Certificate }; test.CmsSigner.SignedAttributes.Add( AttributeUtility.GetCommitmentTypeIndication(SignatureType.Author)); test.CmsSigner.SignedAttributes.Add( AttributeUtility.GetSigningCertificateV2(chain, HashAlgorithmName.SHA256)); test.SignedCms.ComputeSignature(test.CmsSigner); var exception = Assert.Throws <SignatureException>( () => Signature.Load(test.SignedCms.Encode())); Assert.Equal(NuGetLogCode.NU3011, exception.Code); Assert.Equal("The author signature is invalid.", exception.Message); } }
public BindableObjectClass( Type concreteType, BindableObjectProvider businessObjectProvider, BindableObjectGlobalizationService bindableObjectGlobalizationService, IEnumerable <PropertyBase> properties) { ArgumentUtility.CheckNotNull("concreteType", concreteType); Assertion.IsFalse(concreteType.IsValueType, "mixed types cannot be value types"); ArgumentUtility.CheckNotNull("businessObjectProvider", businessObjectProvider); ArgumentUtility.CheckNotNull("bindableObjectGlobalizationService", bindableObjectGlobalizationService); ArgumentUtility.CheckNotNull("properties", properties); _targetType = MixinTypeUtility.GetUnderlyingTargetType(concreteType); _concreteType = concreteType; _businessObjectProvider = businessObjectProvider; _businessObjectProviderAttribute = AttributeUtility.GetCustomAttribute <BusinessObjectProviderAttribute> (concreteType, true); _properties = new PropertyCollection(properties); _bindableObjectGlobalizationService = bindableObjectGlobalizationService; foreach (PropertyBase property in _properties.ToArray()) { property.SetReflectedClass(this); } }
public IEnumerable <MemberOverridePair <TMember> > Analyze(IEnumerable <TMember> overriderMembers) { ArgumentUtility.CheckNotNull("overriderMembers", overriderMembers); foreach (TMember member in overriderMembers) { var overrideAttribute = (IOverrideAttribute)AttributeUtility.GetCustomAttribute(member.MemberInfo, _attributeType, true); if (overrideAttribute != null) { TMember baseMember = FindOverriddenMember(overrideAttribute, member); if (baseMember == null) { string message = string.Format( "The member overridden by '{0}' declared by type '{1}' could not be found. Candidates: {2}.", member.MemberInfo, member.DeclaringClass.FullName, BuildCandidateStringForExceptionMessage(BaseMembersByName[member.Name])); throw new ConfigurationException(message); } yield return(new MemberOverridePair <TMember> (baseMember, member)); } } }
public override void OnGUI(Rect _position, SerializedProperty _property, GUIContent _label) { string propertyName = NamedAttribute.PropertyName; if (string.IsNullOrEmpty(propertyName)) { char[] chars = _property.name.ToCharArray(); chars[0] = char.ToUpper(chars[0]); propertyName = new string(chars); } object prevValue = _property.Value(); SerializedProperty copy = _property.Copy(); EditorGUI.PropertyField(_position, copy); object obj = AttributeUtility.GetParentObjectFromProperty(_property); Type containerType = obj.GetType(); PropertyInfo p = containerType.GetProperty(propertyName); this.fieldInfo.SetValue(obj, prevValue); p.SetValue(obj, copy.Value(), null); }
/// <summary> /// 获取描述内容 /// </summary> /// <param name="enumItem">枚举项</param> /// <returns>返回描述字符串</returns> public static string GetDescriptionText(this Enum enumItem) { var key = enumItem; var fullTypeName = enumItem.GetType().FullName; lock (_lockObj) { if (_dictionary.ContainsKey(fullTypeName)) { if (_dictionary[fullTypeName].ContainsKey(key)) { return(_dictionary[fullTypeName][key].Text); } return(string.Empty); } var enumAttributeDictionary = AttributeUtility.GetEnumAttributeDictionary <EnumDescriptionAttribute>(enumItem); if (enumAttributeDictionary.Count == 0) { return(string.Empty); } _dictionary.Add(fullTypeName, enumAttributeDictionary); return(enumAttributeDictionary[key].Text); } }
public void GetCustomAttributes_Filtered_Properties() { PerformMeasurement( _properties, items => { var counter = 0; for (int i = 0; i < items.Length; ++i) { try { counter += AttributeUtility.GetCustomAttributes(items[i], typeof(NonSerializedAttribute), true).Length; } catch (AmbiguousMatchException) { // Ignore } } return(counter); }, items => { var counter = 0; for (int i = 0; i < items.Length; ++i) { try { counter += Attribute.GetCustomAttributes(items[i], typeof(NonSerializedAttribute), true).Length; } catch (AmbiguousMatchException) { } } return(counter); }); }
public void GetNuGetPackageOwners_WithMultipleAttributeValues_Throws() { using (var certificate = _fixture.GetDefaultCertificate()) { var attributes = CreateAttributeCollection(certificate, _fixture.DefaultKeyPair.Private, vector => { var value = new DerSequence( new DerUtf8String("a"), new DerUtf8String("b"), new DerUtf8String("c")); var attribute = new BcAttribute( new DerObjectIdentifier(Oids.NuGetPackageOwners), new DerSet(value, value)); vector.Add(attribute); }); var exception = Assert.Throws <SignatureException>( () => AttributeUtility.GetNuGetPackageOwners(attributes)); Assert.Equal("The nuget-package-owners attribute must have exactly one attribute value.", exception.Message); } }
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); } }
private static IReadOnlyCollection <ICustomAttributeData> GetAttributes <T> (T member, bool inherit, Func <T, T> baseMemberProvider) where T : MemberInfo { var attributes = s_customAttributeDataRetriever.GetCustomAttributeData(member); if (!inherit) { return(attributes.ToList().AsReadOnly()); } var baseMember = baseMemberProvider(member); if (baseMember == null) { return(attributes.ToList().AsReadOnly()); } var inheritedAttributes = GetCachedAttributes(baseMember, true, baseMemberProvider) .Where(a => AttributeUtility.IsAttributeInherited(a.Type)); var allAttributes = attributes.Concat(inheritedAttributes); return(EvaluateAllowMultiple(allAttributes).ToList().AsReadOnly()); }
public void IsValidCommitmentTypeIndication_CommitmentTypeIndicationWithNoValueVerifyFailure() { var attribute = GetCommitmentTypeTestAttribute(); AttributeUtility.IsValidCommitmentTypeIndication(attribute).Should().BeFalse(); }
public void IsValidCommitmentTypeIndication_CommitmentTypeIndicationWithDuplicateValuesVerifyFailure() { var attribute = GetCommitmentTypeTestAttribute(Oids.CommitmentTypeIdentifierProofOfOrigin, Oids.CommitmentTypeIdentifierProofOfOrigin); AttributeUtility.IsValidCommitmentTypeIndication(attribute).Should().BeFalse(); }
public void IsValidCommitmentTypeIndication_CommitmentTypeIndicationWithBothRepoAndAuthorVerifyFailure() { var attribute = GetCommitmentTypeTestAttribute(Oids.CommitmentTypeIdentifierProofOfReceipt, Oids.CommitmentTypeIdentifierProofOfOrigin); AttributeUtility.IsValidCommitmentTypeIndication(attribute).Should().BeFalse(); }
public void GetCommitmentTypeIndication_CommitmentTypeIndicationWithUnknownSignatureType() { var attribute = GetCommitmentTypeTestAttribute("1.3.6.1.5.5.7.3.3"); AttributeUtility.GetCommitmentTypeIndication(attribute).Should().Be(SignatureType.Unknown); }
public void GetCommitmentTypeIndication_CommitmentTypeIndicationWithAuthorSignatureAndUnknownVerifyAuthor() { var attribute = GetCommitmentTypeTestAttribute(Oids.CommitmentTypeIdentifierProofOfOrigin, "1.3.6.1.5.5.7.3.3"); AttributeUtility.GetCommitmentTypeIndication(attribute).Should().Be(SignatureType.Author); }
public void GetCommitmentTypeIndication_CommitmentTypeIndicationWithRepositorySignature() { var attribute = AttributeUtility.GetCommitmentTypeIndication(SignatureType.Repository); AttributeUtility.GetCommitmentTypeIndication(attribute).Should().Be(SignatureType.Repository); }
public void GetCommitmentTypeIndication_CommitmentTypeIndicationWithAuthorSignature() { var attribute = AttributeUtility.GetCommitmentTypeIndication(SignatureType.Author); AttributeUtility.GetCommitmentTypeIndication(attribute).Should().Be(SignatureType.Author); }
public void ObjectClass_InheritedTrue() { AttributeWithMetadata[] attributes = AttributeUtility.GetCustomAttributesWithMetadata(typeof(object), typeof(Attribute), true).ToArray(); Assert.That(attributes.Length, Is.EqualTo(typeof(object).GetCustomAttributes(false).Length)); }
public override void Begin(Rect position, SerializedProperty property, GUIContent label) { base.Begin(position, property, label); noFieldLabel = ((CustomAttributeBase)attribute).NoFieldLabel; noPrefixLabel = ((CustomAttributeBase)attribute).NoPrefixLabel; noIndex = ((CustomAttributeBase)attribute).NoIndex; prefixLabel = ((CustomAttributeBase)attribute).PrefixLabel; disableOnPlay = ((CustomAttributeBase)attribute).DisableOnPlay; disableOnStop = ((CustomAttributeBase)attribute).DisableOnStop; disableBool = ((CustomAttributeBase)attribute).DisableBool; indent = ((CustomAttributeBase)attribute).Indent; scrollbarThreshold = Screen.width - position.width > 19 ? 298 : 313; currentEvent = Event.current; bool inverseBool = !string.IsNullOrEmpty(disableBool) && disableBool.StartsWith("!"); bool boolDisabled = !string.IsNullOrEmpty(disableBool) && property.serializedObject.targetObject.GetValueFromMemberAtPath <bool>(inverseBool ? disableBool.Substring(1) : disableBool); boolDisabled = inverseBool ? !boolDisabled : boolDisabled; EditorGUI.BeginDisabledGroup((Application.isPlaying && disableOnPlay) || (!Application.isPlaying && disableOnStop) || boolDisabled); EditorGUI.indentLevel += indent; if (typeof(IList).IsAssignableFrom(fieldInfo.FieldType)) { index = AttributeUtility.GetIndexFromLabel(label); arrayProperty = property.GetParent(); if (noIndex) { if (string.IsNullOrEmpty(prefixLabel)) { label.text = label.text.Substring(0, label.text.Length - 2); } } else if (!string.IsNullOrEmpty(prefixLabel)) { prefixLabel += " " + index; } } if (drawPrefixLabel) { if (!noPrefixLabel) { if (!string.IsNullOrEmpty(prefixLabel)) { label.text = prefixLabel; } position = EditorGUI.PrefixLabel(position, label); } } else { if (noPrefixLabel) { label.text = ""; } else if (!string.IsNullOrEmpty(prefixLabel)) { label.text = prefixLabel; } } currentPosition = position; currentLabel = label; }
public void GetCommitmentTypeIndication_CommitmentTypeIndicationWithNoValueVerifyThrows() { var attribute = GetCommitmentTypeTestAttribute(); Assert.Throws <SignatureException>(() => AttributeUtility.GetCommitmentTypeIndication(attribute)); }
public void GetNuGetPackageOwners_WithEmptySignedAttributes_ReturnsNull() { var packageOwners = AttributeUtility.GetNuGetPackageOwners(new CryptographicAttributeObjectCollection()); Assert.Null(packageOwners); }
public void CreateCommitmentTypeIndication_WithUnknownSignature_Throws() { Assert.Throws <ArgumentException>( () => AttributeUtility.CreateCommitmentTypeIndication(SignatureType.Unknown)); }
public void GetCommitmentTypeIndication_CommitmentTypeIndicationWithBothRepoAndAuthorVerifyThrows() { var attribute = GetCommitmentTypeTestAttribute(Oids.CommitmentTypeIdentifierProofOfReceipt, Oids.CommitmentTypeIdentifierProofOfOrigin); Assert.Throws <SignatureException>(() => AttributeUtility.GetCommitmentTypeIndication(attribute)); }
public void GetESSCertIDv2Entries_RejectsNull() { Assert.Throws <ArgumentNullException>( () => AttributeUtility.GetESSCertIDv2Entries(attribute: null)); }
public void GetCommitmentTypeIndication_CommitmentTypeIndicationWithDuplicateValuesVerifyThrows() { var attribute = GetCommitmentTypeTestAttribute(Oids.CommitmentTypeIdentifierProofOfOrigin, Oids.CommitmentTypeIdentifierProofOfOrigin); Assert.Throws <SignatureException>(() => AttributeUtility.GetCommitmentTypeIndication(attribute)); }
public void GetAttributes_WithNoMatches_ReturnsEmptyEnumerable() { var attributes = AttributeUtility.GetAttributes(new CryptographicAttributeObjectCollection(), Oids.SigningTime); Assert.Empty(attributes); }
// // 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 override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { EditorGUI.LabelField(position, label); position.x += EditorGUIUtility.labelWidth; position.width -= EditorGUIUtility.labelWidth; string prevValue = property.Value <string>(); string tk2dspriteName = SpriteNameAttribute.TargetTK2DSprite; if (string.IsNullOrEmpty(tk2dspriteName)) { property.stringValue = string.Empty; EditorGUI.LabelField(position, "Check name reference"); } else { object obj = AttributeUtility.GetParentObjectFromProperty(property); Type containerType = obj.GetType(); FieldInfo f = null; while (containerType != null) { f = containerType.GetField(tk2dspriteName, BindingFlags.NonPublic | BindingFlags.Instance); //fix if (f != null) { break; } containerType = containerType.BaseType; } if ((obj != null) && (f != null)) { tk2dSpriteCollectionData collection = f.GetValue(obj) as tk2dSpriteCollectionData; if (collection == null) { tk2dBaseSprite tk2dSprite = f.GetValue(obj) as tk2dBaseSprite; if (tk2dSprite != null) { collection = tk2dSprite.Collection; } } if (collection != null) { if ((collection.inst != null) && (collection.inst.spriteDefinitions != null)) { List <string> spriteNames = new List <string>(); for (int i = 0; i < collection.inst.spriteDefinitions.Length; i++) { tk2dSpriteDefinition def = collection.inst.spriteDefinitions[i]; if (def != null) { string name = def.name; if (!string.IsNullOrEmpty(name)) { spriteNames.Add(name); } } } if (spriteNames.Count > 0) { spriteNames.Sort(); string[] spriteNamesArray = spriteNames.ToArray(); int spriteNameIndex = Mathf.Max(0, System.Array.IndexOf <string>(spriteNamesArray, prevValue)); spriteNameIndex = EditorGUI.Popup(position, spriteNameIndex, spriteNamesArray); string newValue = spriteNamesArray[spriteNameIndex]; property.stringValue = newValue; } else { property.stringValue = string.Empty; EditorGUI.LabelField(position, "Check sprites collection"); } } else { property.stringValue = string.Empty; EditorGUI.LabelField(position, "Check instance collection"); } } else { property.stringValue = string.Empty; EditorGUI.LabelField(position, "Set TK2DSprite or TK2DCollection reference"); } } else { property.stringValue = string.Empty; EditorGUI.LabelField(position, "Set TK2DSprite or TK2DCollection reference"); } } }