26
26
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31
using Mono.Collections.Generic;
29
33
namespace Mono.Cecil {
32
using System.Collections;
33
using System.Security;
35
public sealed class SecurityDeclaration : IRequireResolving, IAnnotationProvider, IReflectionVisitable {
37
SecurityAction m_action;
38
SecurityDeclarationReader m_reader;
39
IDictionary m_annotations;
41
#if !CF_1_0 && !CF_2_0
42
PermissionSet m_permSet;
35
public enum SecurityAction : ushort {
49
NonCasLinkDemand = 14,
50
NonCasInheritance = 15
53
public interface ISecurityDeclarationProvider : IMetadataTokenProvider {
55
bool HasSecurityDeclarations { get; }
56
Collection<SecurityDeclaration> SecurityDeclarations { get; }
59
public sealed class SecurityAttribute : ICustomAttribute {
61
TypeReference attribute_type;
63
internal Collection<CustomAttributeNamedArgument> fields;
64
internal Collection<CustomAttributeNamedArgument> properties;
66
public TypeReference AttributeType {
67
get { return attribute_type; }
68
set { attribute_type = value; }
71
public bool HasFields {
72
get { return !fields.IsNullOrEmpty (); }
75
public Collection<CustomAttributeNamedArgument> Fields {
76
get { return fields ?? (fields = new Collection<CustomAttributeNamedArgument> ()); }
79
public bool HasProperties {
80
get { return !properties.IsNullOrEmpty (); }
83
public Collection<CustomAttributeNamedArgument> Properties {
84
get { return properties ?? (properties = new Collection<CustomAttributeNamedArgument> ()); }
87
public SecurityAttribute (TypeReference attributeType)
89
this.attribute_type = attributeType;
93
public sealed class SecurityDeclaration {
95
readonly internal uint signature;
96
readonly ModuleDefinition module;
98
internal bool resolved;
99
SecurityAction action;
100
internal Collection<SecurityAttribute> security_attributes;
48
102
public SecurityAction Action {
49
get { return m_action; }
50
set { m_action = value; }
53
#if !CF_1_0 && !CF_2_0
54
public PermissionSet PermissionSet {
55
get { return m_permSet; }
56
set { m_permSet = value; }
60
public bool Resolved {
61
get { return m_resolved; }
62
set { m_resolved = value; }
66
get { return m_blob; }
67
set { m_blob = value; }
70
IDictionary IAnnotationProvider.Annotations {
72
if (m_annotations == null)
73
m_annotations = new Hashtable ();
103
get { return action; }
104
set { action = value; }
107
public bool HasSecurityAttributes {
111
return !security_attributes.IsNullOrEmpty ();
115
public Collection<SecurityAttribute> SecurityAttributes {
119
return security_attributes ?? (security_attributes = new Collection<SecurityAttribute> ());
123
internal bool HasImage {
124
get { return module != null && module.HasImage; }
127
internal SecurityDeclaration (SecurityAction action, uint signature, ModuleDefinition module)
129
this.action = action;
130
this.signature = signature;
131
this.module = module;
78
134
public SecurityDeclaration (SecurityAction action)
83
internal SecurityDeclaration (SecurityAction action, SecurityDeclarationReader reader)
89
public SecurityDeclaration Clone ()
94
internal static SecurityDeclaration Clone (SecurityDeclaration sec)
96
SecurityDeclaration sd = new SecurityDeclaration (sec.Action);
103
#if !CF_1_0 && !CF_2_0
104
sd.PermissionSet = sec.PermissionSet.Copy ();
109
public bool Resolve ()
114
if (m_reader == null)
117
SecurityDeclaration clone = m_reader.FromByteArray (m_action, m_blob, true);
121
m_action = clone.Action;
122
#if !CF_1_0 && !CF_2_0
123
m_permSet = clone.PermissionSet.Copy ();
130
public void Accept (IReflectionVisitor visitor)
132
visitor.VisitSecurityDeclaration (this);
136
this.action = action;
137
this.resolved = true;
140
public byte [] GetBlob ()
142
if (!HasImage || signature == 0)
143
throw new NotSupportedException ();
145
return module.Read (this, (declaration, reader) => reader.ReadSecurityDeclarationBlob (declaration.signature)); ;
150
if (resolved || !HasImage)
153
module.Read (this, (declaration, reader) => {
154
reader.ReadSecurityDeclarationSignature (declaration);
162
static partial class Mixin {
164
public static bool GetHasSecurityDeclarations (
165
this ISecurityDeclarationProvider self,
166
ModuleDefinition module)
168
return module.HasImage ()
169
? module.Read (self, (provider, reader) => reader.HasSecurityDeclarations (provider))
173
public static Collection<SecurityDeclaration> GetSecurityDeclarations (
174
this ISecurityDeclarationProvider self,
175
ModuleDefinition module)
177
return module.HasImage ()
178
? module.Read (self, (provider, reader) => reader.ReadSecurityDeclarations (provider))
179
: new Collection<SecurityDeclaration> ();