1
1
using System ;
2
2
using System . Collections . Generic ;
3
- using System . Linq ;
4
-
5
- using Org . BouncyCastle . Utilities ;
6
3
7
4
namespace Org . BouncyCastle . Asn1 . X509
8
5
{
9
- public class NameConstraints
6
+ public class NameConstraints
10
7
: Asn1Encodable
11
8
{
12
- private Asn1Sequence permitted , excluded ;
9
+ private Asn1Sequence m_permitted , m_excluded ;
13
10
14
- public static NameConstraints GetInstance (
15
- object obj )
11
+ public static NameConstraints GetInstance ( object obj )
16
12
{
17
- if ( obj == null || obj is NameConstraints )
18
- {
19
- return ( NameConstraints ) obj ;
20
- }
21
-
22
- if ( obj is Asn1Sequence )
23
- {
24
- return new NameConstraints ( ( Asn1Sequence ) obj ) ;
25
- }
13
+ if ( obj == null )
14
+ return null ;
15
+ if ( obj is NameConstraints nameConstraints )
16
+ return nameConstraints ;
17
+ #pragma warning disable CS0618 // Type or member is obsolete
18
+ return new NameConstraints ( Asn1Sequence . GetInstance ( obj ) ) ;
19
+ #pragma warning restore CS0618 // Type or member is obsolete
20
+ }
26
21
27
- throw new ArgumentException ( "unknown object in factory: " + Platform . GetTypeName ( obj ) , "obj" ) ;
28
- }
22
+ public static NameConstraints GetInstance ( Asn1TaggedObject taggedObject , bool declaredExplicit )
23
+ {
24
+ return GetInstance ( Asn1Sequence . GetInstance ( taggedObject , declaredExplicit ) ) ;
25
+ }
29
26
30
- public NameConstraints (
31
- Asn1Sequence seq )
27
+ [ Obsolete ( "Use 'GetInstance' instead" ) ]
28
+ public NameConstraints ( Asn1Sequence seq )
32
29
{
33
30
foreach ( Asn1TaggedObject o in seq )
34
31
{
35
32
switch ( o . TagNo )
36
33
{
37
- case 0 :
38
- permitted = Asn1Sequence . GetInstance ( o , false ) ;
39
- break ;
40
- case 1 :
41
- excluded = Asn1Sequence . GetInstance ( o , false ) ;
42
- break ;
34
+ case 0 :
35
+ m_permitted = Asn1Sequence . GetInstance ( o , false ) ;
36
+ break ;
37
+ case 1 :
38
+ m_excluded = Asn1Sequence . GetInstance ( o , false ) ;
39
+ break ;
43
40
}
44
41
}
45
42
}
@@ -52,35 +49,32 @@ public NameConstraints(
52
49
* @param permitted Permitted subtrees
53
50
* @param excluded Excluded subtrees
54
51
*/
55
- public NameConstraints (
56
- IList < GeneralSubtree > permitted ,
57
- IList < GeneralSubtree > excluded )
52
+ public NameConstraints ( IList < GeneralSubtree > permitted , IList < GeneralSubtree > excluded )
58
53
{
59
54
if ( permitted != null )
60
55
{
61
- this . permitted = CreateSequence ( permitted ) ;
56
+ this . m_permitted = CreateSequence ( permitted ) ;
62
57
}
63
58
64
59
if ( excluded != null )
65
60
{
66
- this . excluded = CreateSequence ( excluded ) ;
61
+ this . m_excluded = CreateSequence ( excluded ) ;
67
62
}
68
63
}
69
64
70
65
private DerSequence CreateSequence ( IList < GeneralSubtree > subtrees )
71
66
{
72
- return new DerSequence ( subtrees . ToArray ( ) ) ;
67
+ Asn1EncodableVector v = new Asn1EncodableVector ( subtrees . Count ) ;
68
+ foreach ( var subtree in subtrees )
69
+ {
70
+ v . Add ( subtree ) ;
71
+ }
72
+ return new DerSequence ( v ) ;
73
73
}
74
74
75
- public Asn1Sequence PermittedSubtrees
76
- {
77
- get { return permitted ; }
78
- }
75
+ public Asn1Sequence PermittedSubtrees => m_permitted ;
79
76
80
- public Asn1Sequence ExcludedSubtrees
81
- {
82
- get { return excluded ; }
83
- }
77
+ public Asn1Sequence ExcludedSubtrees => m_excluded ;
84
78
85
79
/*
86
80
* NameConstraints ::= SEQUENCE { permittedSubtrees [0] GeneralSubtrees
@@ -89,8 +83,8 @@ public Asn1Sequence ExcludedSubtrees
89
83
public override Asn1Object ToAsn1Object ( )
90
84
{
91
85
Asn1EncodableVector v = new Asn1EncodableVector ( 2 ) ;
92
- v . AddOptionalTagged ( false , 0 , permitted ) ;
93
- v . AddOptionalTagged ( false , 1 , excluded ) ;
86
+ v . AddOptionalTagged ( false , 0 , m_permitted ) ;
87
+ v . AddOptionalTagged ( false , 1 , m_excluded ) ;
94
88
return new DerSequence ( v ) ;
95
89
}
96
90
}
0 commit comments