示例#1
0
        /// <summary>
        /// Used for retrieving applied source security attributes, i.e. attributes derived from well-known SecurityAttribute.
        /// </summary>
        public IEnumerable <Cci.SecurityAttribute> GetSecurityAttributes <T>(ImmutableArray <T> customAttributes)
            where T : Cci.ICustomAttribute
        {
            Debug.Assert(!customAttributes.IsDefault);
            Debug.Assert(_lazyPathsForPermissionSetFixup == null || _lazySecurityActions != null && _lazyPathsForPermissionSetFixup.Length == _lazySecurityActions.Length);

            if (_lazySecurityActions != null)
            {
                Debug.Assert(_lazySecurityActions != null);
                Debug.Assert(_lazySecurityActions.Length == customAttributes.Length);

                for (int i = 0; i < customAttributes.Length; i++)
                {
                    if (_lazySecurityActions[i] != 0)
                    {
                        DeclarativeSecurityAction action    = (DeclarativeSecurityAction)_lazySecurityActions[i];
                        Cci.ICustomAttribute      attribute = customAttributes[i];

                        if (_lazyPathsForPermissionSetFixup?[i] != null)
                        {
                            attribute = new PermissionSetAttributeWithFileReference(attribute, _lazyPathsForPermissionSetFixup[i]);
                        }

                        yield return(new Cci.SecurityAttribute(action, attribute));
                    }
                }
            }
        }
示例#2
0
        internal void DecodeSecurityAttribute <T>(Symbol targetSymbol, CSharpCompilation compilation, ref DecodeWellKnownAttributeArguments <AttributeSyntax, CSharpAttributeData, AttributeLocation> arguments)
            where T : WellKnownAttributeData, ISecurityAttributeTarget, new()
        {
            Debug.Assert(!this.HasErrors);
            Debug.Assert(arguments.Diagnostics is BindingDiagnosticBag);

            bool hasErrors;
            DeclarativeSecurityAction action = DecodeSecurityAttributeAction(targetSymbol, compilation, arguments.AttributeSyntaxOpt, out hasErrors, (BindingDiagnosticBag)arguments.Diagnostics);

            if (!hasErrors)
            {
                T data = arguments.GetOrCreateData <T>();
                SecurityWellKnownAttributeData securityData = data.GetOrCreateData();
                securityData.SetSecurityAttribute(arguments.Index, action, arguments.AttributesCount);

                if (this.IsTargetAttribute(targetSymbol, AttributeDescription.PermissionSetAttribute))
                {
                    string?resolvedPathForFixup = DecodePermissionSetAttribute(compilation, arguments.AttributeSyntaxOpt, (BindingDiagnosticBag)arguments.Diagnostics);
                    if (resolvedPathForFixup != null)
                    {
                        securityData.SetPathForPermissionSetAttributeFixup(arguments.Index, resolvedPathForFixup, arguments.AttributesCount);
                    }
                }
            }
        }
示例#3
0
        public void SetSecurityAttribute(int attributeIndex, DeclarativeSecurityAction action, int totalSourceAttributes)
        {
            Debug.Assert(attributeIndex >= 0 && attributeIndex < totalSourceAttributes);
            Debug.Assert(action != 0);

            if (_lazySecurityActions == null)
            {
                Interlocked.CompareExchange(ref _lazySecurityActions, new byte[totalSourceAttributes], null);
            }

            Debug.Assert(_lazySecurityActions.Length == totalSourceAttributes);
            _lazySecurityActions[attributeIndex] = (byte)action;
        }
示例#4
0
        public void AddDeclarativeSecurityAttribute(
            EntityHandle parent,
            DeclarativeSecurityAction action,
            BlobHandle permissionSet)
        {
            uint parentCodedIndex = (uint)CodedIndex.ToHasDeclSecurity(parent);

            // the table is required to be sorted by Parent:
            _declSecurityTableNeedsSorting |= parentCodedIndex < _declSecurityTableLastParent;
            _declSecurityTableLastParent = parentCodedIndex;

            _declSecurityTable.Add(new DeclSecurityRow
            {
                Parent = parentCodedIndex,
                Action = (ushort)action,
                PermissionSet = permissionSet
            });
        }
示例#5
0
 public SecurityAttribute(DeclarativeSecurityAction action, ICustomAttribute attribute)
 {
     Action    = action;
     Attribute = attribute;
 }
示例#6
0
        public void AddDeclarativeSecurityAttribute(
            uint parent,
            DeclarativeSecurityAction action,
            BlobIdx permissionSet)
        {
            // the table is required to be sorted by Parent:
            _declSecurityTableNeedsSorting |= parent < _declSecurityTableLastParent;
            _declSecurityTableLastParent = parent;

            _declSecurityTable.Add(new DeclSecurityRow
            {
                Parent = parent,
                Action = (ushort)action,
                PermissionSet = permissionSet
            });
        }