2
// SecurityDeclaration.cs
5
// Jb Evain (jbevain@gmail.com)
7
// Copyright (c) 2008 - 2010 Jb Evain
9
// Permission is hereby granted, free of charge, to any person obtaining
10
// a copy of this software and associated documentation files (the
11
// "Software"), to deal in the Software without restriction, including
12
// without limitation the rights to use, copy, modify, merge, publish,
13
// distribute, sublicense, and/or sell copies of the Software, and to
14
// permit persons to whom the Software is furnished to do so, subject to
15
// the following conditions:
17
// The above copyright notice and this permission notice shall be
18
// included in all copies or substantial portions of the Software.
20
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31
using Mono.Collections.Generic;
33
namespace Mono.Cecil {
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;
102
public SecurityAction Action {
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;
134
public SecurityDeclaration (SecurityAction action)
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> ();