summaryrefslogtreecommitdiff
path: root/src/mscorlib/src/System/Security/Permissions/PermissionAttributes.cs
blob: b6ac8ece3ce895c9c33794728f9b0f3a725634f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

namespace System.Security.Permissions
{

    using System.Security.Util;
    using System.IO;
    using System.Security.Policy;
    using System.Text;
    using System.Threading;
    using System.Runtime.InteropServices;
    using System.Runtime.Remoting;
    using System.Runtime.Serialization;
#if FEATURE_X509
    using System.Security.Cryptography.X509Certificates;
#endif
    using System.Runtime.Versioning;
    using System.Diagnostics.Contracts;
    
    [Serializable]
    [System.Runtime.InteropServices.ComVisible(true)]
    // The csharp compiler requires these types to be public, but they are not used elsewhere.
    [Obsolete("SecurityAction is no longer accessible to application code.")]
    public enum SecurityAction
    {
        // Demand permission of all caller
        Demand = 2,

        // Assert permission so callers don't need
        Assert = 3,

        // Deny permissions so checks will fail
        [Obsolete("Deny is obsolete and will be removed in a future release of the .NET Framework. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")]
        Deny = 4,

        // Reduce permissions so check will fail
        PermitOnly = 5,

        // Demand permission of caller
        LinkDemand = 6,
    
        // Demand permission of a subclass
        InheritanceDemand = 7,

        // Request minimum permissions to run
        [Obsolete("Assembly level declarative security is obsolete and is no longer enforced by the CLR by default. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")]
        RequestMinimum = 8,

        // Request optional additional permissions
        [Obsolete("Assembly level declarative security is obsolete and is no longer enforced by the CLR by default. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")]
        RequestOptional = 9,

        // Refuse to be granted these permissions
        [Obsolete("Assembly level declarative security is obsolete and is no longer enforced by the CLR by default. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")]
        RequestRefuse = 10,
    }

    [Serializable]
    [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Assembly, AllowMultiple = true, Inherited = false )] 
    [System.Runtime.InteropServices.ComVisible(true)]
    // The csharp compiler requires these types to be public, but they are not used elsewhere.
    [Obsolete("SecurityAttribute is no longer accessible to application code.")]
    public abstract class SecurityAttribute : System.Attribute
    {
        /// <internalonly/>
        internal SecurityAction m_action;
        /// <internalonly/>
        internal bool m_unrestricted;

        protected SecurityAttribute( SecurityAction action ) 
        {
            m_action = action;
        }

        public SecurityAction Action
        {
            get { return m_action; }
            set { m_action = value; }
        }

        public bool Unrestricted
        {
            get { return m_unrestricted; }
            set { m_unrestricted = value; }
        }

        abstract public IPermission CreatePermission();

        internal static unsafe IntPtr FindSecurityAttributeTypeHandle(String typeName)
        {
            PermissionSet.s_fullTrust.Assert();
            Type t = Type.GetType(typeName, false, false);
            if(t == null)
                return IntPtr.Zero;
            IntPtr typeHandle = t.TypeHandle.Value;
            return typeHandle;
        }
    }

    [Serializable]
    [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Assembly, AllowMultiple = true, Inherited = false )] 
    [System.Runtime.InteropServices.ComVisible(true)]
    // The csharp compiler requires these types to be public, but they are not used elsewhere.
    [Obsolete("CodeAccessSecurityAttribute is no longer accessible to application code.")]
    public abstract class CodeAccessSecurityAttribute : SecurityAttribute
    {
        protected CodeAccessSecurityAttribute( SecurityAction action )
            : base( action )
        {
        }
    }

    [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Assembly, AllowMultiple = true, Inherited = false )] 
[System.Runtime.InteropServices.ComVisible(true)]
    [Serializable]
#pragma warning disable 618
    sealed public class EnvironmentPermissionAttribute : CodeAccessSecurityAttribute
#pragma warning restore 618
    {
        private String m_read = null;
        private String m_write = null;
    
#pragma warning disable 618
        public EnvironmentPermissionAttribute( SecurityAction action )
#pragma warning restore 618
            : base( action )
        {
        }

        public String Read {
            get { return m_read; }
            set { m_read = value; }
        }
    
        public String Write {
            get { return m_write; }
            set { m_write = value; }
        }

        public String All {
            get { throw new NotSupportedException( Environment.GetResourceString( "NotSupported_GetMethod" ) ); }
            set { m_write = value; m_read = value; }
        }

        public override IPermission CreatePermission()
        {
            if (m_unrestricted)
            {
                return new EnvironmentPermission(PermissionState.Unrestricted);
            }
            else
            {
                EnvironmentPermission perm = new EnvironmentPermission(PermissionState.None);
                if (m_read != null)
                    perm.SetPathList( EnvironmentPermissionAccess.Read, m_read );
                if (m_write != null)
                    perm.SetPathList( EnvironmentPermissionAccess.Write, m_write );
                return perm;
            }
        }
    }

    [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Assembly, AllowMultiple = true, Inherited = false )] 
[System.Runtime.InteropServices.ComVisible(true)]
    [Serializable]
#pragma warning disable 618
    sealed public class FileDialogPermissionAttribute : CodeAccessSecurityAttribute
#pragma warning restore 618
    {
        private FileDialogPermissionAccess m_access;

#pragma warning disable 618
        public FileDialogPermissionAttribute( SecurityAction action )
#pragma warning restore 618
            : base( action )
        {
        }

        public bool Open
        {
            get { return (m_access & FileDialogPermissionAccess.Open) != 0; }
            set { m_access = value ? m_access | FileDialogPermissionAccess.Open : m_access & ~FileDialogPermissionAccess.Open; }
        }
            
        public bool Save
        {
            get { return (m_access & FileDialogPermissionAccess.Save) != 0; }
            set { m_access = value ? m_access | FileDialogPermissionAccess.Save : m_access & ~FileDialogPermissionAccess.Save; }
        }

        public override IPermission CreatePermission()
        {
            if (m_unrestricted)
            {
                return new FileDialogPermission( PermissionState.Unrestricted );
            }
            else
            {
                return new FileDialogPermission( m_access );
            }
        }
    }


    [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Assembly, AllowMultiple = true, Inherited = false )] 
[System.Runtime.InteropServices.ComVisible(true)]
    [Serializable]
#pragma warning disable 618
    sealed public class FileIOPermissionAttribute : CodeAccessSecurityAttribute
#pragma warning restore 618
    {
        private String m_read = null;
        private String m_write = null;
        private String m_append = null;
        private String m_pathDiscovery = null;
        private String m_viewAccess = null;
        private String m_changeAccess = null;
        [OptionalField(VersionAdded = 2)] private FileIOPermissionAccess m_allLocalFiles = FileIOPermissionAccess.NoAccess;
        [OptionalField(VersionAdded = 2)] private FileIOPermissionAccess m_allFiles = FileIOPermissionAccess.NoAccess;
    
#pragma warning disable 618
        public FileIOPermissionAttribute( SecurityAction action )
#pragma warning restore 618
            : base( action )
        {
        }

        public String Read {
            get { return m_read; }
            set { m_read = value; }
        }
    
        public String Write {
            get { return m_write; }
            set { m_write = value; }
        }

        public String Append {
            get { return m_append; }
            set { m_append = value; }
        }

        public String PathDiscovery {
            get { return m_pathDiscovery; }
            set { m_pathDiscovery = value; }
        }

        public String ViewAccessControl {
            get { return m_viewAccess; }
            set { m_viewAccess = value; }
        }

        public String ChangeAccessControl {
            get { return m_changeAccess; }
            set { m_changeAccess = value; }
        }

        [Obsolete("Please use the ViewAndModify property instead.")]
        public String All {
            set { m_read = value; m_write = value; m_append = value; m_pathDiscovery = value; }
            get { throw new NotSupportedException( Environment.GetResourceString( "NotSupported_GetMethod" ) ); }
        }

        // Read, Write, Append, PathDiscovery, but no ACL-related permissions
        public String ViewAndModify {
            get { throw new NotSupportedException( Environment.GetResourceString( "NotSupported_GetMethod" ) ); }
            set { m_read = value; m_write = value; m_append = value; m_pathDiscovery = value; }
        }

        public FileIOPermissionAccess AllFiles {
            get { return m_allFiles; }
            set { m_allFiles = value; }
        }

        public FileIOPermissionAccess AllLocalFiles {
            get { return m_allLocalFiles; }
            set { m_allLocalFiles = value; }
        }

        public override IPermission CreatePermission()
        {
            if (m_unrestricted)
            {
                return new FileIOPermission(PermissionState.Unrestricted);
            }
            else
            {
                FileIOPermission perm = new FileIOPermission(PermissionState.None);
                if (m_read != null)
                    perm.SetPathList( FileIOPermissionAccess.Read, m_read );
                if (m_write != null)
                    perm.SetPathList( FileIOPermissionAccess.Write, m_write );
                if (m_append != null)
                    perm.SetPathList( FileIOPermissionAccess.Append, m_append );
                if (m_pathDiscovery != null)
                    perm.SetPathList( FileIOPermissionAccess.PathDiscovery, m_pathDiscovery );

                perm.AllFiles = m_allFiles;
                perm.AllLocalFiles = m_allLocalFiles;
                return perm;
            }
        }
    }

    [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Assembly, AllowMultiple = true, Inherited = false )] 
    [Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
#pragma warning disable 618
    public sealed class KeyContainerPermissionAttribute : CodeAccessSecurityAttribute {
#pragma warning restore 618
        KeyContainerPermissionFlags m_flags = KeyContainerPermissionFlags.NoFlags;
        private string m_keyStore;
        private string m_providerName;
        private int m_providerType = -1;
        private string m_keyContainerName;
        private int m_keySpec = -1;

#pragma warning disable 618
        public KeyContainerPermissionAttribute(SecurityAction action) : base(action) {}
#pragma warning restore 618

        public string KeyStore {
            get { return m_keyStore; }
            set { m_keyStore = value; }
        }

        public string ProviderName {
            get { return m_providerName; }
            set { m_providerName = value; }
        }

        public int ProviderType {
            get { return m_providerType; }
            set { m_providerType = value; }
        }

        public string KeyContainerName {
            get { return m_keyContainerName; }
            set { m_keyContainerName = value; }
        }

        public int KeySpec {
            get { return m_keySpec; }
            set { m_keySpec = value; }
        }

        public KeyContainerPermissionFlags Flags {
            get { return m_flags; }
            set { m_flags = value; }
        }

        public override IPermission CreatePermission() {
            if (m_unrestricted) {
                return new KeyContainerPermission(PermissionState.Unrestricted);
            } else {
                if (KeyContainerPermissionAccessEntry.IsUnrestrictedEntry(m_keyStore, m_providerName, m_providerType, m_keyContainerName, m_keySpec))
                    return new KeyContainerPermission(m_flags);

                // create a KeyContainerPermission with a single access entry.
                KeyContainerPermission cp = new KeyContainerPermission(KeyContainerPermissionFlags.NoFlags);
                KeyContainerPermissionAccessEntry accessEntry = new KeyContainerPermissionAccessEntry(m_keyStore, m_providerName, m_providerType, m_keyContainerName, m_keySpec, m_flags);
                cp.AccessEntries.Add(accessEntry);
                return cp;
            }
        }
    }

    [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Assembly, AllowMultiple = true, Inherited = false )] 
[System.Runtime.InteropServices.ComVisible(true)]
    [Serializable]
#pragma warning disable 618
    sealed public class ReflectionPermissionAttribute : CodeAccessSecurityAttribute
#pragma warning restore 618
    {
        private ReflectionPermissionFlag m_flag = ReflectionPermissionFlag.NoFlags;

#pragma warning disable 618
        public ReflectionPermissionAttribute( SecurityAction action )
#pragma warning restore 618
            : base( action )
        {
        }

        public ReflectionPermissionFlag Flags {
            get { return m_flag; }
            set { m_flag = value; }
        }

        [Obsolete("This API has been deprecated. http://go.microsoft.com/fwlink/?linkid=14202")]
        public bool TypeInformation {
#pragma warning disable 618
            get { return (m_flag & ReflectionPermissionFlag.TypeInformation) != 0; }
            set { m_flag = value ? m_flag | ReflectionPermissionFlag.TypeInformation : m_flag & ~ReflectionPermissionFlag.TypeInformation; }
#pragma warning restore 618
        }

        public bool MemberAccess {
            get { return (m_flag & ReflectionPermissionFlag.MemberAccess) != 0; }
            set { m_flag = value ? m_flag | ReflectionPermissionFlag.MemberAccess : m_flag & ~ReflectionPermissionFlag.MemberAccess; }
        }

        [Obsolete("This permission is no longer used by the CLR.")]
        public bool ReflectionEmit {
#pragma warning disable 618
            get { return (m_flag & ReflectionPermissionFlag.ReflectionEmit) != 0; }
            set { m_flag = value ? m_flag | ReflectionPermissionFlag.ReflectionEmit : m_flag & ~ReflectionPermissionFlag.ReflectionEmit; }
#pragma warning restore 618
        }

        public bool RestrictedMemberAccess
        {
            get { return (m_flag & ReflectionPermissionFlag.RestrictedMemberAccess) != 0; }
            set { m_flag = value ? m_flag | ReflectionPermissionFlag.RestrictedMemberAccess : m_flag & ~ReflectionPermissionFlag.RestrictedMemberAccess; }
        }

        public override IPermission CreatePermission()
        {
            if (m_unrestricted)
            {
                return new ReflectionPermission( PermissionState.Unrestricted );
            }
            else
            {
                return new ReflectionPermission( m_flag );
            }
        }
    }

    [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Assembly, AllowMultiple = true, Inherited = false )] 
[System.Runtime.InteropServices.ComVisible(true)]
    [Serializable]
#pragma warning disable 618
    sealed public class RegistryPermissionAttribute : CodeAccessSecurityAttribute
#pragma warning restore 618
    {
        private String m_read = null;
        private String m_write = null;
        private String m_create = null;
        private String m_viewAcl = null;
        private String m_changeAcl = null;

#pragma warning disable 618
        public RegistryPermissionAttribute( SecurityAction action )
#pragma warning restore 618
            : base( action )
        {
        }

        public String Read {
            get { return m_read; }
            set { m_read = value; }
        }
    
        public String Write {
            get { return m_write; }
            set { m_write = value; }
        }

        public String Create {
            get { return m_create; }
            set { m_create = value; }
        }

        public String ViewAccessControl {
            get { return m_viewAcl; }
            set { m_viewAcl = value; }
        }

        public String ChangeAccessControl {
            get { return m_changeAcl; }
            set { m_changeAcl = value; }
        }

        // Read, Write, & Create, but no ACL's
        public String ViewAndModify {
            get { throw new NotSupportedException( Environment.GetResourceString( "NotSupported_GetMethod" ) ); }
            set { m_read = value; m_write = value; m_create = value; }
        }

        [Obsolete("Please use the ViewAndModify property instead.")]
        public String All {
            get { throw new NotSupportedException( Environment.GetResourceString( "NotSupported_GetMethod" ) ); }
            set { m_read = value; m_write = value; m_create = value; }
        }

        public override IPermission CreatePermission()
        {
            if (m_unrestricted)
            {
                return new RegistryPermission( PermissionState.Unrestricted );
            }
            else
            {
                RegistryPermission perm = new RegistryPermission(PermissionState.None);
                if (m_read != null)
                    perm.SetPathList( RegistryPermissionAccess.Read, m_read );
                if (m_write != null)
                    perm.SetPathList( RegistryPermissionAccess.Write, m_write );
                if (m_create != null)
                    perm.SetPathList( RegistryPermissionAccess.Create, m_create );
                return perm;
            }
        }
    }

    [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Assembly, AllowMultiple = true, Inherited = false )] 
    [System.Runtime.InteropServices.ComVisible(true)]
    [Serializable]
    // The csharp compiler requires these types to be public, but they are not used elsewhere.
    [Obsolete("SecurityPermissionAttribute is no longer accessible to application code.")]
    sealed public class SecurityPermissionAttribute : CodeAccessSecurityAttribute
    {
        private SecurityPermissionFlag m_flag = SecurityPermissionFlag.NoFlags;
    
        public SecurityPermissionAttribute( SecurityAction action )
            : base( action )
        {
        }

        public SecurityPermissionFlag Flags {
            get { return m_flag; }
            set { m_flag = value; }
        }

        public bool Assertion {
            get { return (m_flag & SecurityPermissionFlag.Assertion) != 0; }
            set { m_flag = value ? m_flag | SecurityPermissionFlag.Assertion : m_flag & ~SecurityPermissionFlag.Assertion; }
        }

        public bool UnmanagedCode {
            get { return (m_flag & SecurityPermissionFlag.UnmanagedCode) != 0; }
            set { m_flag = value ? m_flag | SecurityPermissionFlag.UnmanagedCode : m_flag & ~SecurityPermissionFlag.UnmanagedCode; }
        }

        public bool SkipVerification {
            get { return (m_flag & SecurityPermissionFlag.SkipVerification) != 0; }
            set { m_flag = value ? m_flag | SecurityPermissionFlag.SkipVerification : m_flag & ~SecurityPermissionFlag.SkipVerification; }
        }

        public bool Execution {
            get { return (m_flag & SecurityPermissionFlag.Execution) != 0; }
            set { m_flag = value ? m_flag | SecurityPermissionFlag.Execution : m_flag & ~SecurityPermissionFlag.Execution; }
        }

        public bool ControlThread {
            get { return (m_flag & SecurityPermissionFlag.ControlThread) != 0; }
            set { m_flag = value ? m_flag | SecurityPermissionFlag.ControlThread : m_flag & ~SecurityPermissionFlag.ControlThread; }
        }
    
        public bool ControlEvidence {
            get { return (m_flag & SecurityPermissionFlag.ControlEvidence) != 0; }
            set { m_flag = value ? m_flag | SecurityPermissionFlag.ControlEvidence : m_flag & ~SecurityPermissionFlag.ControlEvidence; }
        }
    
        public bool ControlPolicy {
            get { return (m_flag & SecurityPermissionFlag.ControlPolicy) != 0; }
            set { m_flag = value ? m_flag | SecurityPermissionFlag.ControlPolicy : m_flag & ~SecurityPermissionFlag.ControlPolicy; }
        }
    
        public bool SerializationFormatter {
            get { return (m_flag & SecurityPermissionFlag.SerializationFormatter) != 0; }
            set { m_flag = value ? m_flag | SecurityPermissionFlag.SerializationFormatter : m_flag & ~SecurityPermissionFlag.SerializationFormatter; }
        }

        public bool ControlDomainPolicy {
            get { return (m_flag & SecurityPermissionFlag.ControlDomainPolicy) != 0; }
            set { m_flag = value ? m_flag | SecurityPermissionFlag.ControlDomainPolicy : m_flag & ~SecurityPermissionFlag.ControlDomainPolicy; }
        }
    
        public bool ControlPrincipal {
            get { return (m_flag & SecurityPermissionFlag.ControlPrincipal) != 0; }
            set { m_flag = value ? m_flag | SecurityPermissionFlag.ControlPrincipal : m_flag & ~SecurityPermissionFlag.ControlPrincipal; }
        }

        public bool ControlAppDomain {
            get { return (m_flag & SecurityPermissionFlag.ControlAppDomain) != 0; }
            set { m_flag = value ? m_flag | SecurityPermissionFlag.ControlAppDomain : m_flag & ~SecurityPermissionFlag.ControlAppDomain; }
        } 

        public bool RemotingConfiguration {
            get { return (m_flag & SecurityPermissionFlag.RemotingConfiguration) != 0; }
            set { m_flag = value ? m_flag | SecurityPermissionFlag.RemotingConfiguration : m_flag & ~SecurityPermissionFlag.RemotingConfiguration; }
        }

        [System.Runtime.InteropServices.ComVisible(true)]
        public bool Infrastructure {
            get { return (m_flag & SecurityPermissionFlag.Infrastructure) != 0; }
            set { m_flag = value ? m_flag | SecurityPermissionFlag.Infrastructure : m_flag & ~SecurityPermissionFlag.Infrastructure; }
        }
    
        public bool BindingRedirects {
            get { return (m_flag & SecurityPermissionFlag.BindingRedirects) != 0; }
            set { m_flag = value ? m_flag | SecurityPermissionFlag.BindingRedirects : m_flag & ~SecurityPermissionFlag.BindingRedirects; }
        }

        public override IPermission CreatePermission()
        {
            if (m_unrestricted)
            {
                return new SecurityPermission( PermissionState.Unrestricted );
            }
            else
            {
                return new SecurityPermission( m_flag );
            }
        }
    }

    [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Assembly, AllowMultiple = true, Inherited = false )] 
[System.Runtime.InteropServices.ComVisible(true)]
    [Serializable]
#pragma warning disable 618
    sealed public class UIPermissionAttribute : CodeAccessSecurityAttribute
#pragma warning restore 618
    {
        private UIPermissionWindow m_windowFlag = UIPermissionWindow.NoWindows;
        private UIPermissionClipboard m_clipboardFlag = UIPermissionClipboard.NoClipboard;
    
#pragma warning disable 618
        public UIPermissionAttribute( SecurityAction action )
#pragma warning restore 618
            : base( action )
        {
        }

        public UIPermissionWindow Window {
            get { return m_windowFlag; }
            set { m_windowFlag = value; }
        }

        public UIPermissionClipboard Clipboard {
            get { return m_clipboardFlag; }
            set { m_clipboardFlag = value; }
        }
    
        public override IPermission CreatePermission()
        {
            if (m_unrestricted)
            {
                return new UIPermission( PermissionState.Unrestricted );
            }
            else
            {
                return new UIPermission( m_windowFlag, m_clipboardFlag );
            }
        }
    }

    [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Assembly, AllowMultiple = true, Inherited = false )] 
[System.Runtime.InteropServices.ComVisible(true)]
    [Serializable]
#pragma warning disable 618
    sealed public class ZoneIdentityPermissionAttribute : CodeAccessSecurityAttribute
#pragma warning restore 618
    {
        private SecurityZone m_flag = SecurityZone.NoZone;
    
#pragma warning disable 618
        public ZoneIdentityPermissionAttribute( SecurityAction action )
#pragma warning restore 618
            : base( action )
        {
        }

        public SecurityZone Zone {
            get { return m_flag; }
            set { m_flag = value; }
        }
    
        public override IPermission CreatePermission()
        {
            if (m_unrestricted)
            {
                return new ZoneIdentityPermission(PermissionState.Unrestricted);
            }
            else
            {
                return new ZoneIdentityPermission( m_flag );
            }
        }
    }

    [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Assembly, AllowMultiple = true, Inherited = false )] 
[System.Runtime.InteropServices.ComVisible(true)]
    [Serializable]
#pragma warning disable 618
    sealed public class StrongNameIdentityPermissionAttribute : CodeAccessSecurityAttribute
#pragma warning restore 618
    {
        private String m_name = null;
        private String m_version = null;
        private String m_blob = null;

#pragma warning disable 618
        public StrongNameIdentityPermissionAttribute( SecurityAction action )
#pragma warning restore 618
            : base( action )
        {
        }

        public String Name
        {
            get { return m_name; }
            set { m_name = value; }
        }
        
        public String Version
        {
            get { return m_version; }
            set { m_version = value; }
        }
        
        public String PublicKey
        {
            get { return m_blob; }
            set { m_blob = value; }
        }

        public override IPermission CreatePermission()
        {
            if (m_unrestricted)
            {
                return new StrongNameIdentityPermission( PermissionState.Unrestricted );
            }
            else
            {
                if (m_blob == null && m_name == null && m_version == null)
                    return new StrongNameIdentityPermission( PermissionState.None );
            
                if (m_blob == null)
                    throw new ArgumentException( Environment.GetResourceString("ArgumentNull_Key"));
                    
                StrongNamePublicKeyBlob blob = new StrongNamePublicKeyBlob( m_blob );
                
                if (m_version == null || m_version.Equals(String.Empty))
                    return new StrongNameIdentityPermission( blob, m_name, null );
                else    
                    return new StrongNameIdentityPermission( blob, m_name, new Version( m_version ) );
            }
        }
    }


    [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Assembly, AllowMultiple = true, Inherited = false )] 
[System.Runtime.InteropServices.ComVisible(true)]
    [Serializable]
#pragma warning disable 618
    sealed public class SiteIdentityPermissionAttribute : CodeAccessSecurityAttribute
#pragma warning restore 618
    {
        private String m_site = null;
    
#pragma warning disable 618
        public SiteIdentityPermissionAttribute( SecurityAction action )
#pragma warning restore 618
            : base( action )
        {
        }

        public String Site {
            get { return m_site; }
            set { m_site = value; }
        }
    
        public override IPermission CreatePermission()
        {
            if (m_unrestricted)
            {
                return new SiteIdentityPermission( PermissionState.Unrestricted );
            }
            else
            {
                if (m_site == null)
                    return new SiteIdentityPermission( PermissionState.None );
            
                return new SiteIdentityPermission( m_site );
            }
        }
    }

    [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Assembly, AllowMultiple = true, Inherited = false )] 
[System.Runtime.InteropServices.ComVisible(true)]
#pragma warning disable 618
    [Serializable] sealed public class UrlIdentityPermissionAttribute : CodeAccessSecurityAttribute
#pragma warning restore 618
    {
        private String m_url = null;
    
#pragma warning disable 618
        public UrlIdentityPermissionAttribute( SecurityAction action )
#pragma warning restore 618
            : base( action )
        {
        }

        public String Url {
            get { return m_url; }
            set { m_url = value; }
        }
    
        public override IPermission CreatePermission()
        {
            if (m_unrestricted)
            {
                return new UrlIdentityPermission( PermissionState.Unrestricted );
            }
            else
            {
                if (m_url == null)
                    return new UrlIdentityPermission( PermissionState.None );
                    
                return new UrlIdentityPermission( m_url );
            }
        }
    }

    [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Assembly, AllowMultiple = true, Inherited = false )] 
[System.Runtime.InteropServices.ComVisible(true)]
    [Serializable]
#pragma warning disable 618
    sealed public class PermissionSetAttribute : CodeAccessSecurityAttribute
#pragma warning restore 618
    {
        private String m_file;
        private String m_name;
        private bool m_unicode;
        private String m_xml;
        private String m_hex;

#pragma warning disable 618
        public PermissionSetAttribute( SecurityAction action )
#pragma warning restore 618
            : base( action )
        {
            m_unicode = false;
        }

        public String File {
            get { return m_file; }
            set { m_file = value; }
        }
    
        public bool UnicodeEncoded {
            get { return m_unicode; }
            set { m_unicode = value; }
        }
        
        public String Name {
            get { return m_name; }
            set { m_name = value; }
        }
        
        public String XML {
            get { return m_xml; }
            set { m_xml = value; }
        }       

        public String Hex {
            get { return m_hex; }
            set { m_hex = value; }
        }

        public override IPermission CreatePermission()
        {
            return null;
        }

        public PermissionSet CreatePermissionSet()
        {
            if (m_unrestricted)
                return new PermissionSet( PermissionState.Unrestricted );
            else if (m_name != null)
                return NamedPermissionSet.GetBuiltInSet( m_name );
            else
                return new PermissionSet( PermissionState.None );
        }
    }
}