Skip to content

Commit 23d167a

Browse files
authored
Enable Nullability for important Certificate Handling classes (#2989)
* enable nrts for CertificatIdentifier&CertificateStoreIdentifier&CertificateTrustList * make RSA Utils and Certificate Stores nullable * Make Certificate validator nullable * fix nullability of CertificateTypeParameter
1 parent ba915ac commit 23d167a

14 files changed

+362
-283
lines changed

Stack/Opc.Ua.Core/Schema/ApplicationConfiguration.cs

Lines changed: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2848,6 +2848,7 @@ public ServerRegistrationCollection(int capacity) : base(capacity) { }
28482848
#endregion
28492849

28502850
#region CertificateStoreIdentifier Class
2851+
#nullable enable
28512852
/// <summary>
28522853
/// Describes a certificate store.
28532854
/// </summary>
@@ -2862,7 +2863,7 @@ public partial class CertificateStoreIdentifier
28622863
/// If the StoreName is not empty, the CertificateStoreType.X509Store is returned, otherwise the StoreType is returned.
28632864
/// </value>
28642865
[DataMember(IsRequired = false, EmitDefaultValue = false, Order = 0)]
2865-
public string StoreType
2866+
public string? StoreType
28662867
{
28672868
get
28682869
{
@@ -2889,13 +2890,13 @@ public string StoreType
28892890
/// If the StoreName is empty, the m_storePath is returned.
28902891
/// </value>
28912892
[DataMember(IsRequired = false, EmitDefaultValue = false, Order = 1)]
2892-
public string StorePath
2893+
public string? StorePath
28932894
{
28942895
get
28952896
{
2896-
if (!String.IsNullOrEmpty(m_storeName))
2897+
if (!string.IsNullOrEmpty(m_storeName))
28972898
{
2898-
if (String.IsNullOrEmpty(m_storeLocation))
2899+
if (string.IsNullOrEmpty(m_storeLocation))
28992900
{
29002901
return CurrentUser + m_storeName;
29012902
}
@@ -2925,7 +2926,7 @@ public string StorePath
29252926
/// </summary>
29262927
[DataMember(IsRequired = false, EmitDefaultValue = false, Order = 2)]
29272928
[Obsolete("Use StoreType/StorePath instead")]
2928-
public string StoreName
2929+
public string? StoreName
29292930
{
29302931
get { return m_storeName; }
29312932
set { m_storeName = value; }
@@ -2936,7 +2937,7 @@ public string StoreName
29362937
/// </summary>
29372938
[DataMember(IsRequired = false, EmitDefaultValue = false, Order = 3)]
29382939
[Obsolete("Use StoreType/StorePath instead")]
2939-
public string StoreLocation
2940+
public string? StoreLocation
29402941
{
29412942
get { return m_storeLocation; }
29422943
set { m_storeLocation = value; }
@@ -2954,16 +2955,18 @@ private int XmlEncodedValidationOptions
29542955
#endregion
29552956

29562957
#region Private Fields
2957-
private string m_storeType;
2958-
private string m_storePath;
2959-
private string m_storeLocation;
2960-
private string m_storeName;
2958+
private string? m_storeType;
2959+
private string? m_storePath;
2960+
private string? m_storeLocation;
2961+
private string? m_storeName;
29612962
private CertificateValidationOptions m_validationOptions;
29622963
#endregion
29632964
}
2965+
#nullable disable
29642966
#endregion
29652967

29662968
#region CertificateTrustList Class
2969+
#nullable enable
29672970
[DataContract(Namespace = Namespaces.OpcUaConfig)]
29682971
[KnownType(typeof(CertificateTrustList))]
29692972
public partial class CertificateTrustList : CertificateStoreIdentifier
@@ -2974,6 +2977,8 @@ public partial class CertificateTrustList : CertificateStoreIdentifier
29742977
/// </summary>
29752978
public CertificateTrustList()
29762979
{
2980+
//set in initialize
2981+
m_trustedCertificates = null!;
29772982
Initialize();
29782983
}
29792984

@@ -3024,6 +3029,7 @@ public CertificateIdentifierCollection TrustedCertificates
30243029
private CertificateIdentifierCollection m_trustedCertificates;
30253030
#endregion
30263031
}
3032+
#nullable disable
30273033
#endregion
30283034

30293035
#region CertificateIdentifierCollection Class
@@ -3049,6 +3055,7 @@ public CertificateIdentifierCollection(int capacity) : base(capacity) { }
30493055
#endregion
30503056

30513057
#region CertificateIdentifier Class
3058+
#nullable enable
30523059
[DataContract(Namespace = Namespaces.OpcUaConfig)]
30533060
public partial class CertificateIdentifier
30543061
{
@@ -3110,11 +3117,11 @@ private void Initialize()
31103117
/// </summary>
31113118
/// <value>The type of the store - defined in the <see cref="CertificateStoreType"/>.</value>
31123119
[DataMember(IsRequired = false, EmitDefaultValue = false, Order = 10)]
3113-
public string StoreType
3120+
public string? StoreType
31143121
{
31153122
get
31163123
{
3117-
if (!String.IsNullOrEmpty(m_storeName))
3124+
if (!string.IsNullOrEmpty(m_storeName))
31183125
{
31193126
return CertificateStoreType.X509Store;
31203127
}
@@ -3133,13 +3140,13 @@ public string StoreType
31333140
/// </summary>
31343141
/// <value>The store path in the form <c>StoreName\\Store Location</c> .</value>
31353142
[DataMember(IsRequired = false, EmitDefaultValue = false, Order = 15)]
3136-
public string StorePath
3143+
public string? StorePath
31373144
{
31383145
get
31393146
{
3140-
if (!String.IsNullOrEmpty(m_storeName))
3147+
if (!string.IsNullOrEmpty(m_storeName))
31413148
{
3142-
if (String.IsNullOrEmpty(m_storeLocation))
3149+
if (string.IsNullOrEmpty(m_storeLocation))
31433150
{
31443151
return Utils.Format("LocalMachine\\{0}", m_storeName);
31453152
}
@@ -3154,9 +3161,9 @@ public string StorePath
31543161
{
31553162
m_storePath = value;
31563163

3157-
if (!String.IsNullOrEmpty(m_storePath))
3164+
if (!string.IsNullOrEmpty(m_storePath))
31583165
{
3159-
if (String.IsNullOrEmpty(m_storeType))
3166+
if (string.IsNullOrEmpty(m_storeType))
31603167
{
31613168
m_storeType = CertificateStoreIdentifier.DetermineStoreType(m_storePath);
31623169
}
@@ -3171,7 +3178,7 @@ public string StorePath
31713178
/// <seealso cref="System.Security.Cryptography.X509Certificates.StoreName"/>
31723179
[DataMember(IsRequired = false, EmitDefaultValue = false, Order = 20)]
31733180
[Obsolete("Use StoreType/StorePath instead")]
3174-
public string StoreName
3181+
public string? StoreName
31753182
{
31763183
get { return m_storeName; }
31773184
set { m_storeName = value; }
@@ -3184,7 +3191,7 @@ public string StoreName
31843191
/// <seealso cref="System.Security.Cryptography.X509Certificates.StoreLocation"/>
31853192
[DataMember(IsRequired = false, EmitDefaultValue = false, Order = 30)]
31863193
[Obsolete("Use StoreType/StorePath instead")]
3187-
public string StoreLocation
3194+
public string? StoreLocation
31883195
{
31893196
get { return m_storeLocation; }
31903197
set { m_storeLocation = value; }
@@ -3238,7 +3245,7 @@ public string StoreLocation
32383245
/// <seealso cref="System.Security.Cryptography.X509Certificates.X500DistinguishedName"/>
32393246
/// <seealso cref="System.Security.Cryptography.AsnEncodedData"/>
32403247
[DataMember(IsRequired = false, EmitDefaultValue = false, Order = 40)]
3241-
public string SubjectName
3248+
public string? SubjectName
32423249
{
32433250
get
32443251
{
@@ -3270,7 +3277,7 @@ public string SubjectName
32703277
/// <value>The thumbprint of a certificate..</value>
32713278
/// <seealso cref="X509Certificate2"/>
32723279
[DataMember(IsRequired = false, EmitDefaultValue = false, Order = 50)]
3273-
public string Thumbprint
3280+
public string? Thumbprint
32743281
{
32753282
get
32763283
{
@@ -3301,7 +3308,7 @@ public string Thumbprint
33013308
/// </summary>
33023309
/// <value>A byte array containing the X.509 certificate data.</value>
33033310
[DataMember(IsRequired = false, EmitDefaultValue = false, Order = 60)]
3304-
public byte[] RawData
3311+
public byte[]? RawData
33053312
{
33063313
get
33073314
{
@@ -3344,7 +3351,7 @@ private int XmlEncodedValidationOptions
33443351
/// </summary>
33453352
/// <value>The NodeId of the certificate type, e.g. EccNistP256ApplicationCertificateType.</value>
33463353
[DataMember(IsRequired = false, EmitDefaultValue = false, Order = 80)]
3347-
public NodeId CertificateType
3354+
public NodeId? CertificateType
33483355
{
33493356
get => m_certificateType;
33503357
set => m_certificateType = value;
@@ -3355,27 +3362,27 @@ public NodeId CertificateType
33553362
/// </summary>
33563363
/// <value>Rsa, RsaMin, RsaSha256, NistP256, NistP384, BrainpoolP256r1, BrainpoolP384r1, Curve25519, Curve448</value>
33573364
[DataMember(IsRequired = false, EmitDefaultValue = false, Order = 90)]
3358-
public string CertificateTypeString
3365+
public string? CertificateTypeString
33593366
{
33603367
get => EncodeCertificateType(m_certificateType);
33613368
set => m_certificateType = DecodeCertificateType(value);
33623369
}
33633370
#endregion
33643371

33653372
#region Private Fields
3366-
private string m_storeType;
3367-
private string m_storePath;
3368-
private string m_storeLocation;
3369-
private string m_storeName;
3370-
private string m_subjectName;
3371-
private string m_thumbprint;
3372-
private X509Certificate2 m_certificate;
3373-
private NodeId m_certificateType;
3373+
private string? m_storeType;
3374+
private string? m_storePath;
3375+
private string? m_storeLocation;
3376+
private string? m_storeName;
3377+
private string? m_subjectName;
3378+
private string? m_thumbprint;
3379+
private X509Certificate2? m_certificate;
3380+
private NodeId? m_certificateType;
33743381
private CertificateValidationOptions m_validationOptions;
33753382
#endregion
33763383
}
3384+
#nullable disable
33773385
#endregion
3378-
33793386
#region ConfiguredEndpointCollection Class
33803387
/// <summary>
33813388
/// Stores a list of cached endpoints.

0 commit comments

Comments
 (0)