Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
X509Store.cs
Go to the documentation of this file.
2
4
5public sealed class X509Store : IDisposable
6{
8
10 {
11 get
12 {
13 if (_storePal == null)
14 {
16 }
17 if (_storePal.SafeHandle == null)
18 {
19 return IntPtr.Zero;
20 }
21 return _storePal.SafeHandle.DangerousGetHandle();
22 }
23 }
24
25 public StoreLocation Location { get; private set; }
26
27 public string? Name { get; private set; }
28
30 {
31 get
32 {
33 X509Certificate2Collection x509Certificate2Collection = new X509Certificate2Collection();
34 if (_storePal != null)
35 {
36 _storePal.CloneTo(x509Certificate2Collection);
37 }
38 return x509Certificate2Collection;
39 }
40 }
41
42 public bool IsOpen => _storePal != null;
43
44 public X509Store()
45 : this("MY", StoreLocation.CurrentUser)
46 {
47 }
48
49 public X509Store(string storeName)
50 : this(storeName, StoreLocation.CurrentUser)
51 {
52 }
53
54 public X509Store(StoreName storeName)
55 : this(storeName, StoreLocation.CurrentUser)
56 {
57 }
58
59 public X509Store(StoreLocation storeLocation)
60 : this("MY", storeLocation)
61 {
62 }
63
64 public X509Store(StoreName storeName, StoreLocation storeLocation)
65 {
66 if (storeLocation != StoreLocation.CurrentUser && storeLocation != StoreLocation.LocalMachine)
67 {
68 throw new ArgumentException(System.SR.Format(System.SR.Arg_EnumIllegalVal, "storeLocation"));
69 }
70 Name = storeName switch
71 {
72 StoreName.AddressBook => "AddressBook",
73 StoreName.AuthRoot => "AuthRoot",
74 StoreName.CertificateAuthority => "CA",
75 StoreName.Disallowed => "Disallowed",
76 StoreName.My => "My",
77 StoreName.Root => "Root",
78 StoreName.TrustedPeople => "TrustedPeople",
79 StoreName.TrustedPublisher => "TrustedPublisher",
80 _ => throw new ArgumentException(System.SR.Format(System.SR.Arg_EnumIllegalVal, "storeName")),
81 };
82 Location = storeLocation;
83 }
84
85 public X509Store(StoreName storeName, StoreLocation storeLocation, OpenFlags flags)
86 : this(storeName, storeLocation)
87 {
88 Open(flags);
89 }
90
91 public X509Store(string storeName, StoreLocation storeLocation)
92 {
93 if (storeLocation != StoreLocation.CurrentUser && storeLocation != StoreLocation.LocalMachine)
94 {
95 throw new ArgumentException(System.SR.Format(System.SR.Arg_EnumIllegalVal, "storeLocation"));
96 }
97 Location = storeLocation;
98 Name = storeName;
99 }
100
101 public X509Store(string storeName, StoreLocation storeLocation, OpenFlags flags)
102 : this(storeName, storeLocation)
103 {
104 Open(flags);
105 }
106
107 public X509Store(IntPtr storeHandle)
108 {
109 _storePal = StorePal.FromHandle(storeHandle);
110 }
111
112 public void Open(OpenFlags flags)
113 {
114 Close();
116 }
117
118 public void Add(X509Certificate2 certificate)
119 {
120 if (certificate == null)
121 {
122 throw new ArgumentNullException("certificate");
123 }
124 if (_storePal == null)
125 {
127 }
128 if (certificate.Pal == null)
129 {
131 }
132 _storePal.Add(certificate.Pal);
133 }
134
135 public void AddRange(X509Certificate2Collection certificates)
136 {
137 if (certificates == null)
138 {
139 throw new ArgumentNullException("certificates");
140 }
141 int num = 0;
142 try
143 {
144 foreach (X509Certificate2 certificate in certificates)
145 {
146 Add(certificate);
147 num++;
148 }
149 }
150 catch
151 {
152 for (int i = 0; i < num; i++)
153 {
154 Remove(certificates[i]);
155 }
156 throw;
157 }
158 }
159
160 public void Remove(X509Certificate2 certificate)
161 {
162 if (certificate == null)
163 {
164 throw new ArgumentNullException("certificate");
165 }
166 if (_storePal == null)
167 {
169 }
170 if (certificate.Pal != null)
171 {
172 _storePal.Remove(certificate.Pal);
173 }
174 }
175
176 public void RemoveRange(X509Certificate2Collection certificates)
177 {
178 if (certificates == null)
179 {
180 throw new ArgumentNullException("certificates");
181 }
182 int num = 0;
183 try
184 {
185 foreach (X509Certificate2 certificate in certificates)
186 {
187 Remove(certificate);
188 num++;
189 }
190 }
191 catch
192 {
193 for (int i = 0; i < num; i++)
194 {
195 Add(certificates[i]);
196 }
197 throw;
198 }
199 }
200
201 public void Dispose()
202 {
203 Close();
204 }
205
206 public void Close()
207 {
208 IStorePal storePal = _storePal;
209 _storePal = null;
210 storePal?.Dispose();
211 }
212}
static IStorePal FromSystemStore(string storeName, StoreLocation storeLocation, OpenFlags openFlags)
Definition StorePal.cs:287
static IStorePal FromHandle(IntPtr storeHandle)
Definition StorePal.cs:29
static string Arg_EnumIllegalVal
Definition SR.cs:144
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string Cryptography_InvalidHandle
Definition SR.cs:72
static string Cryptography_X509_StoreNotOpen
Definition SR.cs:102
Definition SR.cs:7
X509Store(StoreName storeName, StoreLocation storeLocation)
Definition X509Store.cs:64
X509Store(StoreName storeName, StoreLocation storeLocation, OpenFlags flags)
Definition X509Store.cs:85
void RemoveRange(X509Certificate2Collection certificates)
Definition X509Store.cs:176
X509Store(string storeName, StoreLocation storeLocation)
Definition X509Store.cs:91
void Remove(X509Certificate2 certificate)
Definition X509Store.cs:160
X509Store(string storeName, StoreLocation storeLocation, OpenFlags flags)
Definition X509Store.cs:101
void AddRange(X509Certificate2Collection certificates)
Definition X509Store.cs:135
void Remove(ICertificatePal cert)
void Add(ICertificatePal cert)
void CloneTo(X509Certificate2Collection collection)
static readonly IntPtr Zero
Definition IntPtr.cs:18