Skip to content

Commit e9e8e5a

Browse files
authored
Improvements in X.509 constructors (#258)
***NO_CI***
1 parent dce7b7e commit e9e8e5a

File tree

2 files changed

+30
-16
lines changed

2 files changed

+30
-16
lines changed

nanoFramework.System.Net/X509Certificates/X509Certificate.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// See LICENSE file in the project root for full license information.
55
//
66

7-
namespace System.Security.Cryptography.X509Certificates
7+
namespace System.Security.Cryptography.X509Certificates
88
{
99
using System;
1010
using System.Runtime.CompilerServices;
@@ -61,7 +61,7 @@ public X509Certificate()
6161
/// ASN.1 DER is the only certificate format supported by this class.
6262
/// </remarks>
6363
public X509Certificate(byte[] certificate)
64-
: this(certificate, "")
64+
: this(certificate, null)
6565
{
6666
}
6767

@@ -76,7 +76,7 @@ public X509Certificate(byte[] certificate)
7676
public X509Certificate(byte[] certificate, string password)
7777
{
7878
_certificate = certificate;
79-
_password = password;
79+
_password = password;
8080

8181
ParseCertificate(certificate, password, ref _issuer, ref _subject, ref _effectiveDate, ref _expirationDate);
8282
}
@@ -101,8 +101,6 @@ public X509Certificate(string certificate)
101101
Array.Copy(tempCertificate, _certificate, tempCertificate.Length);
102102
_certificate[_certificate.Length - 1] = 0;
103103

104-
_password = "";
105-
106104
ParseCertificate(_certificate, _password, ref _issuer, ref _subject, ref _effectiveDate, ref _expirationDate);
107105
}
108106

nanoFramework.System.Net/X509Certificates/X509Certificate2.cs

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace System.Security.Cryptography.X509Certificates
1515
public class X509Certificate2 : X509Certificate
1616
{
1717
#pragma warning disable S3459 // Unassigned members should be removed
18-
// these fields are required and set in native code
18+
// field required to be accessible by native code
1919
private readonly byte[] _privateKey;
2020
#pragma warning restore S3459 // Unassigned members should be removed
2121

@@ -25,6 +25,7 @@ public class X509Certificate2 : X509Certificate
2525
public X509Certificate2()
2626
: base()
2727
{
28+
2829
}
2930

3031
/// <summary>
@@ -75,14 +76,19 @@ public X509Certificate2(string certificate, string password)
7576
/// <summary>
7677
/// Initializes a new instance of the <see cref="X509Certificate2"/> class using a string with the content of an X.509 public certificate, the private key and a password used to access the certificate.
7778
/// </summary>
78-
/// <param name="certificate">A string containing a X.509 certificate.</param>
79+
/// <param name="rawData">A string containing a X.509 certificate.</param>
7980
/// <param name="key">A string containing a PEM private key.</param>
80-
/// <param name="password">The password required to access the X.509 certificate data.</param>
81+
/// <param name="password">The password required to access the X.509 certificate data. Set to <see langword="null"/> if the <paramref name="rawData"/> or <paramref name="key"/> are not encrypted and do not require a password.</param>
8182
/// <remarks>
8283
/// This methods is exclusive of nanoFramework. There is no equivalent in .NET framework.
8384
/// </remarks>
84-
public X509Certificate2(string certificate, string key, string password)
85-
: base(certificate, password)
85+
public X509Certificate2(
86+
string rawData,
87+
string key,
88+
string password)
89+
: base(
90+
rawData,
91+
password)
8692
{
8793
var tempKey = Encoding.UTF8.GetBytes(key);
8894

@@ -104,12 +110,17 @@ public X509Certificate2(string certificate, string key, string password)
104110
/// </summary>
105111
/// <param name="rawData">A byte array containing data from an X.509 certificate.</param>
106112
/// <param name="key">A string containing a PEM private key.</param>
107-
/// <param name="password">The password required to access the X.509 certificate data.</param>
113+
/// <param name="password">The password required to access the X.509 certificate data. Set to <see langword="null"/> if the <paramref name="rawData"/> or <paramref name="key"/> are not encrypted and do not require a password.</param>
108114
/// <remarks>
109115
/// This methods is exclusive of nanoFramework. There is no equivalent in .NET framework.
110116
/// </remarks>
111-
public X509Certificate2(byte[] rawData, string key, string password)
112-
: base(rawData, password)
117+
public X509Certificate2(
118+
byte[] rawData,
119+
string key,
120+
string password)
121+
: base(
122+
rawData,
123+
password)
113124
{
114125
var tempKey = Encoding.UTF8.GetBytes(key);
115126

@@ -131,12 +142,17 @@ public X509Certificate2(byte[] rawData, string key, string password)
131142
/// </summary>
132143
/// <param name="rawData">A byte array containing data from an X.509 certificate.</param>
133144
/// <param name="key">A byte array containing a PEM private key.</param>
134-
/// <param name="password">The password required to access the X.509 certificate data.</param>
145+
/// <param name="password">The password required to access the X.509 certificate data. <see langword="null"/> if the <paramref name="rawData"/> or <paramref name="key"/> are not encrypted.</param>
135146
/// <remarks>
136147
/// This methods is exclusive of nanoFramework. There is no equivalent in .NET framework.
137148
/// </remarks>
138-
public X509Certificate2(byte[] rawData, byte[] key, string password)
139-
: base(rawData, password)
149+
public X509Certificate2(
150+
byte[] rawData,
151+
byte[] key,
152+
string password)
153+
: base(
154+
rawData,
155+
password)
140156
{
141157
_privateKey = key;
142158

0 commit comments

Comments
 (0)