1
1
using System ;
2
2
using System . Collections ;
3
3
4
- using Org . BouncyCastle . Asn1 ;
4
+ using Org . BouncyCastle . Asn1 . X500 ;
5
5
6
6
namespace Org . BouncyCastle . Asn1 . Esf
7
7
{
@@ -20,10 +20,9 @@ namespace Org.BouncyCastle.Asn1.Esf
20
20
public class SignerLocation
21
21
: Asn1Encodable
22
22
{
23
- // TODO Should these be using DirectoryString?
24
- private DerUtf8String countryName ;
25
- private DerUtf8String localityName ;
26
- private Asn1Sequence postalAddress ;
23
+ private DirectoryString countryName ;
24
+ private DirectoryString localityName ;
25
+ private Asn1Sequence postalAddress ;
27
26
28
27
public SignerLocation (
29
28
Asn1Sequence seq )
@@ -33,10 +32,10 @@ public SignerLocation(
33
32
switch ( obj . TagNo )
34
33
{
35
34
case 0 :
36
- this . countryName = DerUtf8String . GetInstance ( obj , true ) ;
35
+ this . countryName = DirectoryString . GetInstance ( obj , true ) ;
37
36
break ;
38
37
case 1 :
39
- this . localityName = DerUtf8String . GetInstance ( obj , true ) ;
38
+ this . localityName = DirectoryString . GetInstance ( obj , true ) ;
40
39
break ;
41
40
case 2 :
42
41
bool isExplicit = obj . IsExplicit ( ) ; // handle erroneous implicitly tagged sequences
@@ -50,33 +49,36 @@ public SignerLocation(
50
49
}
51
50
}
52
51
53
- public SignerLocation (
54
- DerUtf8String countryName ,
55
- DerUtf8String localityName ,
56
- Asn1Sequence postalAddress )
57
- {
58
- if ( postalAddress != null && postalAddress . Count > 6 )
59
- {
60
- throw new ArgumentException ( "postal address must contain less than 6 strings" ) ;
61
- }
62
-
63
- if ( countryName != null )
64
- {
65
- this . countryName = DerUtf8String . GetInstance ( countryName . ToAsn1Object ( ) ) ;
66
- }
67
-
68
- if ( localityName != null )
69
- {
70
- this . localityName = DerUtf8String . GetInstance ( localityName . ToAsn1Object ( ) ) ;
71
- }
72
-
73
- if ( postalAddress != null )
74
- {
75
- this . postalAddress = ( Asn1Sequence ) postalAddress . ToAsn1Object ( ) ;
76
- }
77
- }
78
-
79
- public static SignerLocation GetInstance (
52
+ private SignerLocation (
53
+ DirectoryString countryName ,
54
+ DirectoryString localityName ,
55
+ Asn1Sequence postalAddress )
56
+ {
57
+ if ( postalAddress != null && postalAddress . Count > 6 )
58
+ throw new ArgumentException ( "postal address must contain less than 6 strings" ) ;
59
+
60
+ this . countryName = countryName ;
61
+ this . localityName = localityName ;
62
+ this . postalAddress = postalAddress ;
63
+ }
64
+
65
+ public SignerLocation (
66
+ DirectoryString countryName ,
67
+ DirectoryString localityName ,
68
+ DirectoryString [ ] postalAddress )
69
+ : this ( countryName , localityName , new DerSequence ( postalAddress ) )
70
+ {
71
+ }
72
+
73
+ public SignerLocation (
74
+ DerUtf8String countryName ,
75
+ DerUtf8String localityName ,
76
+ Asn1Sequence postalAddress )
77
+ : this ( DirectoryString . GetInstance ( countryName ) , DirectoryString . GetInstance ( localityName ) , postalAddress )
78
+ {
79
+ }
80
+
81
+ public static SignerLocation GetInstance (
80
82
object obj )
81
83
{
82
84
if ( obj == null || obj is SignerLocation )
@@ -87,15 +89,41 @@ public static SignerLocation GetInstance(
87
89
return new SignerLocation ( Asn1Sequence . GetInstance ( obj ) ) ;
88
90
}
89
91
92
+ public DirectoryString Country
93
+ {
94
+ get { return countryName ; }
95
+ }
96
+
97
+ public DirectoryString Locality
98
+ {
99
+ get { return localityName ; }
100
+ }
101
+
102
+ public DirectoryString [ ] GetPostal ( )
103
+ {
104
+ if ( postalAddress == null )
105
+ return null ;
106
+
107
+ DirectoryString [ ] dirStrings = new DirectoryString [ postalAddress . Count ] ;
108
+ for ( int i = 0 ; i != dirStrings . Length ; i ++ )
109
+ {
110
+ dirStrings [ i ] = DirectoryString . GetInstance ( postalAddress [ i ] ) ;
111
+ }
112
+
113
+ return dirStrings ;
114
+ }
115
+
116
+ [ Obsolete ( "Use 'Country' property instead" ) ]
90
117
public DerUtf8String CountryName
91
118
{
92
- get { return countryName ; }
119
+ get { return countryName == null ? null : new DerUtf8String ( countryName . GetString ( ) ) ; }
93
120
}
94
121
95
- public DerUtf8String LocalityName
96
- {
97
- get { return localityName ; }
98
- }
122
+ [ Obsolete ( "Use 'Locality' property instead" ) ]
123
+ public DerUtf8String LocalityName
124
+ {
125
+ get { return localityName == null ? null : new DerUtf8String ( localityName . GetString ( ) ) ; }
126
+ }
99
127
100
128
public Asn1Sequence PostalAddress
101
129
{
0 commit comments