Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing XML docs to System.Security.* #44461

Merged
merged 8 commits into from
Nov 20, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ public class Rfc2898DeriveBytes : DeriveBytes
private int _startIndex;
private int _endIndex;

/// <summary>
/// Gets the hash algorithm used for byte derivation
krwq marked this conversation as resolved.
Show resolved Hide resolved
/// </summary>
public HashAlgorithmName HashAlgorithm { get; }

public Rfc2898DeriveBytes(byte[] password, byte[] salt, int iterations)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

namespace System.Security.Cryptography.Pkcs
{
/// <summary>
/// Represents time stamp token info class defined in RFC3161 as TSTInfo.
krwq marked this conversation as resolved.
Show resolved Hide resolved
/// </summary>
public sealed class Rfc3161TimestampTokenInfo
{
private readonly byte[] _encodedBytes;
Expand All @@ -20,6 +23,20 @@ public sealed class Rfc3161TimestampTokenInfo
private Oid? _hashAlgorithmId;
private ReadOnlyMemory<byte>? _tsaNameBytes;

/// <summary>
/// Initializes a new instance of the Rfc3161TimestampTokenInfo class.
krwq marked this conversation as resolved.
Show resolved Hide resolved
/// </summary>
/// <param name="policyId">An OID representing TSA's policy under which the response was produced.</param>
/// <param name="hashAlgorithmId">A hash algorithm OID of the data to be time-stamped.</param>
/// <param name="messageHash">A hash value of the data to be time-stamped.</param>
/// <param name="serialNumber">An integer assigned by the TSA to the <see cref="Rfc3161TimestampTokenInfo"/>.</param>
/// <param name="timestamp">Timestamp encoded in the token.</param>
/// <param name="accuracyInMicroseconds">Accuracy with which <paramref name="timestamp"/> is compared. Also see <paramref name="isOrdering"/>.</param>
/// <param name="isOrdering">true to ensure that every time-stamp token from the same TSA can always be ordered based on the <paramref name="timestamp"/>, regardless of the accuracy; false to make <paramref name="timestamp"/> indicate when token has been created by the TSA.</param>
/// <param name="nonce">An arbitrary number that can be used only once. Using a nonce always allows to detect replays, and hence its use is recommended.</param>
/// <param name="tsaName">Hint in the TSA name identification. The actual identification of the entity that signed the response will always occur through the use of the certificate identifier.</param>
/// <param name="extensions">Collection of X509 extensions.</param>
/// <remarks>If hash OID, message hash, policy or nonce is present in the <see cref="Rfc3161TimestampRequest"/>, then the same value should be used. If <paramref name="accuracyInMicroseconds"/> is not provided, then the accuracy may be available through other means such as i.e. policy.</remarks>
krwq marked this conversation as resolved.
Show resolved Hide resolved
public Rfc3161TimestampTokenInfo(
Oid policyId,
Oid hashAlgorithmId,
Expand Down Expand Up @@ -57,17 +74,62 @@ private Rfc3161TimestampTokenInfo(byte[] copiedBytes, Rfc3161TstInfo tstInfo)
_parsedData = tstInfo;
}

/// <summary>
/// version of the Time-Stamp request.
krwq marked this conversation as resolved.
Show resolved Hide resolved
/// </summary>
public int Version => _parsedData.Version;

/// <summary>
/// An OID representing TSA's policy under which the response was produced.
krwq marked this conversation as resolved.
Show resolved Hide resolved
/// </summary>
public Oid PolicyId => (_policyOid ??= new Oid(_parsedData.Policy, null));

/// <summary>
/// An OID of the hash algorithm.
/// </summary>
public Oid HashAlgorithmId => (_hashAlgorithmId ??= new Oid(_parsedData.MessageImprint.HashAlgorithm.Algorithm, null));

/// <summary>
/// Data representing message hash.
krwq marked this conversation as resolved.
Show resolved Hide resolved
/// </summary>
public ReadOnlyMemory<byte> GetMessageHash() => _parsedData.MessageImprint.HashedMessage;

/// <summary>
/// An integer assigned by the TSA to the <see cref="Rfc3161TimestampTokenInfo"/>.
/// </summary>
public ReadOnlyMemory<byte> GetSerialNumber() => _parsedData.SerialNumber;

/// <summary>
/// Timestamp encoded in the token.
krwq marked this conversation as resolved.
Show resolved Hide resolved
/// </summary>
public DateTimeOffset Timestamp => _parsedData.GenTime;

/// <summary>
/// Accuracy with which <see cref="Timestamp"/> is compared. Also see <see cref="IsOrdering"/>.
krwq marked this conversation as resolved.
Show resolved Hide resolved
/// </summary>
public long? AccuracyInMicroseconds => _parsedData.Accuracy?.TotalMicros;

/// <summary>
/// Gets a value indicating if every time-stamp token from the same TSA can always be ordered based on the <see cref="Timestamp"/>, regardless of the accuracy; If false <see cref="Timestamp"/> indicate when token has been created by the TSA.
krwq marked this conversation as resolved.
Show resolved Hide resolved
/// </summary>
public bool IsOrdering => _parsedData.Ordering;
krwq marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// An arbitrary number that can be used only once.
krwq marked this conversation as resolved.
Show resolved Hide resolved
/// </summary>
public ReadOnlyMemory<byte>? GetNonce() => _parsedData.Nonce;
krwq marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// Gets a value indicating whether there are any X509 extensions.
krwq marked this conversation as resolved.
Show resolved Hide resolved
/// </summary>
public bool HasExtensions => _parsedData.Extensions?.Length > 0;

/// <summary>
/// Gets data representing hint in the TSA name identification.
krwq marked this conversation as resolved.
Show resolved Hide resolved
/// The actual identification of the entity that signed the response
/// will always occur through the use of the certificate identifier (ESSCertID Attribute)
/// inside a SigningCertificate attribute which is part of the signer info.
/// </summary>
public ReadOnlyMemory<byte>? GetTimestampAuthorityName()
{
if (_tsaNameBytes == null)
Expand All @@ -88,6 +150,9 @@ private Rfc3161TimestampTokenInfo(byte[] copiedBytes, Rfc3161TstInfo tstInfo)
return _tsaNameBytes.Value;
}

/// <summary>
/// Returns collection of X509 certificates.
krwq marked this conversation as resolved.
Show resolved Hide resolved
/// </summary>
public X509ExtensionCollection GetExtensions()
krwq marked this conversation as resolved.
Show resolved Hide resolved
{
var coll = new X509ExtensionCollection();
Expand Down Expand Up @@ -115,11 +180,20 @@ public X509ExtensionCollection GetExtensions()
return coll;
}

/// <summary>
/// Returns byte array representing ASN.1 encoded data.
krwq marked this conversation as resolved.
Show resolved Hide resolved
/// </summary>
public byte[] Encode()
{
return _encodedBytes.CloneByteArray();
}

/// <summary>
/// Gets ASN.1 encoded data.
/// </summary>
/// <param name="destination">Destination buffer.</param>
/// <param name="bytesWritten">Outputs bytes written to destination buffer.</param>
/// <returns>true if operation succeeded; false if buffer size was insufficient.</returns>
krwq marked this conversation as resolved.
Show resolved Hide resolved
public bool TryEncode(Span<byte> destination, out int bytesWritten)
{
if (destination.Length < _encodedBytes.Length)
Expand All @@ -133,6 +207,13 @@ public bool TryEncode(Span<byte> destination, out int bytesWritten)
return true;
}

/// <summary>
/// Decodes ASN.1 encoded data.
/// </summary>
/// <param name="source">Input or source buffer.</param>
/// <param name="timestampTokenInfo">Class representing decoded data or null when data could not be decoded.</param>
/// <param name="bytesConsumed">Number of bytes used for decoding.</param>
/// <returns>true if operation succeeded; false otherwise.</returns>
krwq marked this conversation as resolved.
Show resolved Hide resolved
public static bool TryDecode(
ReadOnlyMemory<byte> source,
[NotNullWhen(true)] out Rfc3161TimestampTokenInfo? timestampTokenInfo,
Expand Down