Skip to content

Commit b9cd985

Browse files
Mihkel Kivisildmrts
authored andcommitted
Added missing XML documentation and resolved some discrepancies in existing comments
WE2-1008 Signed-off-by: Mihkel Kivisild [email protected]
1 parent 7e76f09 commit b9cd985

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+586
-85
lines changed

src/WebEid.Security.Tests/Certificate/CertificateDataTest.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ namespace WebEid.Security.Tests.Certificate
22
{
33
using System.Security.Cryptography.X509Certificates;
44
using NUnit.Framework;
5-
using WebEid.Security.Exceptions;
65
using WebEid.Security.Tests.TestUtils;
76
using WebEid.Security.Util;
87

src/WebEid.Security.Tests/TestUtils/OcspServiceMaker.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* Copyright © 2020-2024 Estonian Information System Authority
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -37,8 +37,8 @@ public class OcspServiceMaker
3737

3838
static OcspServiceMaker() => TrustedCaCertificates = new List<X509Certificate2>
3939
{
40-
new X509Certificate2(Certificates.GetTestEsteid2015Ca()),
41-
new X509Certificate2(Certificates.GetTestEsteid2018Ca())
40+
new(Certificates.GetTestEsteid2015Ca()),
41+
new(Certificates.GetTestEsteid2018Ca())
4242
};
4343

4444
public static OcspServiceProvider GetAiaOcspServiceProvider() => new(null, GetAiaOcspServiceConfiguration());

src/WebEid.Security.Tests/Validator/Ocsp/OcspResponseValidatorTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,11 @@ namespace WebEid.Security.Tests.Validator.Ocsp
2626
using Org.BouncyCastle.Ocsp;
2727
using Security.Validator.Ocsp;
2828
using WebEid.Security.Validator;
29-
using Org.BouncyCastle.Asn1;
3029
using Org.BouncyCastle.Asn1.Ocsp;
3130
using System.Globalization;
3231
using WebEid.Security.Exceptions;
3332
using WebEid.Security.Tests.TestUtils;
3433
using WebEid.Security.Util;
35-
using System.Runtime.CompilerServices;
3634

3735
[TestFixture]
3836
public class OcspResponseValidatorTests

src/WebEid.Security.Tests/WebEid.Security.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
55

66
<IsPackable>false</IsPackable>
77

src/WebEid.Security/Challenge/ChallengeNonce.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* Copyright © 2020-2024 Estonian Information System Authority
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -23,11 +23,27 @@ namespace WebEid.Security.Challenge
2323
{
2424
using System;
2525

26+
/// <summary>
27+
/// Represents a challenge nonce used in the Web eID system.
28+
/// </summary>
2629
public class ChallengeNonce
2730
{
31+
/// <summary>
32+
/// The base64-encoded value of the nonce.
33+
/// </summary>
2834
public string Base64EncodedNonce { get; private set; }
35+
36+
/// <summary>
37+
/// The expiration time for the nonce.
38+
/// </summary>
2939
public DateTime ExpirationTime { get; private set; }
3040

41+
/// <summary>
42+
/// Initializes a new instance of the <see cref="ChallengeNonce"/> class.
43+
/// </summary>
44+
/// <param name="base64EncodedNonce">The base64-encoded value of the nonce.</param>
45+
/// <param name="expirationTime">The expiration time for the nonce.</param>
46+
/// <exception cref="ArgumentNullException">Thrown when the provided base64EncodedNonce is null.</exception>
3147
public ChallengeNonce(string base64EncodedNonce, DateTime expirationTime)
3248
{
3349
this.Base64EncodedNonce = base64EncodedNonce ?? throw new ArgumentNullException(nameof(base64EncodedNonce));

src/WebEid.Security/Challenge/ChallengeNonceGenerator.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* Copyright © 2020-2024 Estonian Information System Authority
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -25,16 +25,20 @@ namespace WebEid.Security.Challenge
2525
using System.Security.Cryptography;
2626
using Util;
2727

28+
/// <summary>
29+
/// Generates and stores cryptographic nonces for the Web eID system.
30+
/// </summary>
2831
public sealed class ChallengeNonceGenerator : IChallengeNonceGenerator
2932
{
3033
private readonly IChallengeNonceStore store;
3134
private readonly RandomNumberGenerator randomNumberGenerator;
3235

3336
/// <summary>
34-
/// Initializes a new instance of NonceGenerator
37+
/// Initializes a new instance of the <see cref="ChallengeNonceGenerator"/> class.
3538
/// </summary>
39+
/// <param name="randomNumberGenerator">The source of random bytes for generating nonces.</param>
3640
/// <param name="store">The store where generated nonce values will be stored.</param>
37-
/// <param name="randomNumberGenerator">The source of random bytes for the nonce.</param>
41+
/// <exception cref="ArgumentNullException">Thrown when either randomNumberGenerator or store is null.</exception>
3842
public ChallengeNonceGenerator(RandomNumberGenerator randomNumberGenerator, IChallengeNonceStore store)
3943
{
4044
this.randomNumberGenerator = randomNumberGenerator ?? throw new ArgumentNullException(nameof(randomNumberGenerator), "Secure random generator must not be null");
@@ -43,16 +47,18 @@ public ChallengeNonceGenerator(RandomNumberGenerator randomNumberGenerator, ICha
4347

4448
/// <summary>
4549
/// Generates a cryptographic nonce, a large random number that can be used only once,
46-
/// and stores it in a ChallengeNonceStore.
50+
/// and stores it in the specified ChallengeNonceStore.
4751
/// </summary>
48-
/// <param name="ttl">Challenge nonce time-to-live duration. When the time-to-live passes, the nonce is considered to be expired.</param>
49-
/// <returns>a ChallengeNonce that contains the Base64-encoded nonce and its expiry time</returns>
52+
/// <param name="ttl">The time-to-live duration for the nonce. When the time-to-live passes, the nonce is considered expired.</param>
53+
/// <returns>A ChallengeNonce that contains the Base64-encoded nonce and its expiry time.</returns>
54+
/// <exception cref="ArgumentOutOfRangeException">Thrown when the provided ttl is negative or zero.</exception>
5055
public ChallengeNonce GenerateAndStoreNonce(TimeSpan ttl)
5156
{
5257
if (ttl.IsNegativeOrZero())
5358
{
5459
throw new ArgumentOutOfRangeException(nameof(ttl), "Nonce time-to-live duration must be greater than zero");
5560
}
61+
5662
var nonceBytes = new byte[IChallengeNonceGenerator.NonceLength];
5763
this.randomNumberGenerator.GetBytes(nonceBytes);
5864
var base64StringNonce = Convert.ToBase64String(nonceBytes);

src/WebEid.Security/Challenge/IChallengeNonceStore.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,8 @@ public interface IChallengeNonceStore
5555
/// </remarks>
5656
ChallengeNonce GetAndRemove()
5757
{
58-
var challengeNonce = GetAndRemoveImpl();
59-
if (challengeNonce == null)
60-
{
61-
throw new ChallengeNonceNotFoundException();
62-
}
58+
var challengeNonce = GetAndRemoveImpl() ?? throw new ChallengeNonceNotFoundException();
59+
6360
if (DateTimeProvider.UtcNow >= challengeNonce.ExpirationTime)
6461
{
6562
throw new ChallengeNonceExpiredException();

src/WebEid.Security/Exceptions/AuthTokenException.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* Copyright © 2020-2024 Estonian Information System Authority
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -26,19 +26,33 @@ namespace WebEid.Security.Exceptions
2626
using System.Runtime.Serialization;
2727

2828
/// <summary>
29-
/// Base class for all authentication token validation exceptions.
29+
/// Base class for all authentication token validation exceptions in the Web eID system.
3030
/// </summary>
3131
[Serializable]
3232
public abstract class AuthTokenException : Exception
3333
{
34+
/// <summary>
35+
/// Initializes a new instance of the <see cref="AuthTokenException"/> class with the specified error message.
36+
/// </summary>
37+
/// <param name="msg">The error message.</param>
3438
protected AuthTokenException(string msg) : base(msg)
3539
{
3640
}
3741

42+
/// <summary>
43+
/// Initializes a new instance of the <see cref="AuthTokenException"/> class with the specified error message and inner exception.
44+
/// </summary>
45+
/// <param name="msg">The error message.</param>
46+
/// <param name="innerException">The inner exception.</param>
3847
protected AuthTokenException(string msg, Exception innerException) : base(msg, innerException)
3948
{
4049
}
4150

51+
/// <summary>
52+
/// Initializes a new instance of the <see cref="AuthTokenException"/> class from serialized data.
53+
/// </summary>
54+
/// <param name="info">The <see cref="SerializationInfo"/> that holds the serialized object data.</param>
55+
/// <param name="context">The <see cref="StreamingContext"/> that contains contextual information about the source or destination.</param>
4256
[ExcludeFromCodeCoverage]
4357
protected AuthTokenException(SerializationInfo info, StreamingContext context) : base(info, context) { }
4458
}

src/WebEid.Security/Exceptions/AuthTokenParseException.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* Copyright © 2020-2024 Estonian Information System Authority
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -26,23 +26,41 @@ namespace WebEid.Security.Exceptions
2626
using System.Runtime.Serialization;
2727

2828
/// <summary>
29-
/// Thrown when authentication token parsing fails.
29+
/// Represents an exception thrown when authentication token parsing fails in the Web eID system.
3030
/// </summary>
3131
[Serializable]
3232
public class AuthTokenParseException : AuthTokenException
3333
{
34+
/// <summary>
35+
/// Initializes a new instance of the <see cref="AuthTokenParseException"/> class with the specified error message.
36+
/// </summary>
37+
/// <param name="message">The error message.</param>
3438
public AuthTokenParseException(string message) : base(message)
3539
{
3640
}
3741

42+
/// <summary>
43+
/// Initializes a new instance of the <see cref="AuthTokenParseException"/> class with the specified inner exception.
44+
/// </summary>
45+
/// <param name="innerException">The inner exception.</param>
3846
public AuthTokenParseException(Exception innerException) : this("Error parsing token", innerException)
3947
{
4048
}
4149

50+
/// <summary>
51+
/// Initializes a new instance of the <see cref="AuthTokenParseException"/> class with the specified error message and inner exception.
52+
/// </summary>
53+
/// <param name="message">The error message.</param>
54+
/// <param name="innerException">The inner exception.</param>
4255
public AuthTokenParseException(string message, Exception innerException) : base(message, innerException)
4356
{
4457
}
4558

59+
/// <summary>
60+
/// Initializes a new instance of the <see cref="AuthTokenParseException"/> class from serialized data.
61+
/// </summary>
62+
/// <param name="info">The <see cref="SerializationInfo"/> that holds the serialized object data.</param>
63+
/// <param name="context">The <see cref="StreamingContext"/> that contains contextual information about the source or destination.</param>
4664
[ExcludeFromCodeCoverage]
4765
protected AuthTokenParseException(SerializationInfo info, StreamingContext context) : base(info, context) { }
4866
}

src/WebEid.Security/Exceptions/AuthTokenSignatureValidationException.cs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* Copyright © 2020-2024 Estonian Information System Authority
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -26,22 +26,37 @@ namespace WebEid.Security.Exceptions
2626
using System.Runtime.Serialization;
2727

2828
/// <summary>
29-
/// Thrown when authentication token signature validation fails.
29+
/// Represents an exception thrown when authentication token signature validation fails in the Web eID system.
3030
/// </summary>
3131
[Serializable]
3232
public class AuthTokenSignatureValidationException : AuthTokenException
3333
{
34-
public const string ErrorMessage = "Token signature validation has failed";
35-
34+
/// <summary>
35+
/// Initializes a new instance of the <see cref="AuthTokenSignatureValidationException"/> class.
36+
/// </summary>
3637
public AuthTokenSignatureValidationException() : base(ErrorMessage)
3738
{
3839
}
3940

41+
/// <summary>
42+
/// Initializes a new instance of the <see cref="AuthTokenSignatureValidationException"/> class with the specified inner exception.
43+
/// </summary>
44+
/// <param name="innerException">The inner exception.</param>
4045
public AuthTokenSignatureValidationException(Exception innerException) : base(ErrorMessage, innerException)
4146
{
4247
}
4348

49+
/// <summary>
50+
/// Initializes a new instance of the <see cref="AuthTokenSignatureValidationException"/> class from serialized data.
51+
/// </summary>
52+
/// <param name="info">The <see cref="SerializationInfo"/> that holds the serialized object data.</param>
53+
/// <param name="context">The <see cref="StreamingContext"/> that contains contextual information about the source or destination.</param>
4454
[ExcludeFromCodeCoverage]
4555
protected AuthTokenSignatureValidationException(SerializationInfo info, StreamingContext context) : base(info, context) { }
56+
57+
/// <summary>
58+
/// The error message indicating that token signature validation has failed.
59+
/// </summary>
60+
public const string ErrorMessage = "Token signature validation has failed";
4661
}
4762
}

0 commit comments

Comments
 (0)