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

Address some trivial experimental items #4837

Merged
merged 1 commit into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -2,8 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using Microsoft.Shared.DiagnosticIds;

namespace Microsoft.Extensions.AsyncState;

Expand All @@ -12,7 +10,6 @@ namespace Microsoft.Extensions.AsyncState;
/// </summary>
/// <typeparam name="T">The type of the asynchronous state.</typeparam>
/// <remarks>This type is intended for internal use. Use <see cref="IAsyncContext{T}"/> instead.</remarks>
[Experimental(diagnosticId: DiagnosticIds.Experiments.AsyncState, UrlFormat = DiagnosticIds.UrlFormat)]
[EditorBrowsable(EditorBrowsableState.Never)]
#pragma warning disable S4023 // Interfaces should not be empty
public interface IAsyncLocalContext<T> : IAsyncContext<T>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@

namespace Microsoft.Extensions.Compliance.Redaction;

internal sealed class HmacRedactor : Redactor
/// <summary>
/// A redactor using HMACSHA256 to encode data being redacted.
/// </summary>
public sealed class HmacRedactor : Redactor
{
#if NET6_0_OR_GREATER
private const int SHA256HashSizeInBytes = 32;
Expand All @@ -33,18 +36,23 @@ internal sealed class HmacRedactor : Redactor
private readonly byte[] _hashKey;
private readonly string _keyId;

/// <summary>
/// Initializes a new instance of the <see cref="HmacRedactor"/> class.
/// </summary>
/// <param name="options">Controls the behavior of the redactor.</param>
public HmacRedactor(IOptions<HmacRedactorOptions> options)
{
var value = Throw.IfMemberNull(options, options.Value);
var value = Throw.IfMemberNull(options, options?.Value);

_hashKey = Convert.FromBase64String(value.Key);
_keyId = value.KeyId.HasValue ? value.KeyId.Value.ToInvariantString() + ':' : string.Empty;
_redactedLength = Base64HashLength + _keyId.Length;
}

public override int GetRedactedLength(ReadOnlySpan<char> source)
/// <inheritdoc />
public override int GetRedactedLength(ReadOnlySpan<char> input)
{
if (source.IsEmpty)
if (input.IsEmpty)
{
return 0;
}
Expand All @@ -53,6 +61,7 @@ public override int GetRedactedLength(ReadOnlySpan<char> source)
}

#if NET6_0_OR_GREATER
/// <inheritdoc />
public override int Redact(ReadOnlySpan<char> source, Span<char> destination)
{
var length = GetRedactedLength(source);
Expand Down Expand Up @@ -82,6 +91,7 @@ private static int CreateSha256Hash(ReadOnlySpan<char> source, Span<char> destin

#else

/// <inheritdoc />
public override int Redact(ReadOnlySpan<char> source, Span<char> destination)
{
const int RemainingBytesToPadForBase64Hash = BytesOfHashWeUse % 3;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics.CodeAnalysis;
using Microsoft.Shared.DiagnosticIds;

namespace Microsoft.Extensions.Compliance.Redaction;

/// <summary>
/// A redactor using HMACSHA256 to encode data being redacted.
/// Options to control the <see cref="HmacRedactor"/>.
/// </summary>
[Experimental(diagnosticId: DiagnosticIds.Experiments.Compliance, UrlFormat = DiagnosticIds.UrlFormat)]
public class HmacRedactorOptions
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"Name": "Microsoft.Extensions.Compliance.Redaction, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35",
"Name": "Microsoft.Extensions.Compliance.Redaction, Version=8.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35",
"Types": [
{
"Type": "sealed class Microsoft.Extensions.Compliance.Redaction.ErasingRedactor : Microsoft.Extensions.Compliance.Redaction.Redactor",
Expand All @@ -25,23 +25,41 @@
}
]
},
{
"Type": "sealed class Microsoft.Extensions.Compliance.Redaction.HmacRedactor : Microsoft.Extensions.Compliance.Redaction.Redactor",
"Stage": "Stable",
"Methods": [
{
"Member": "Microsoft.Extensions.Compliance.Redaction.HmacRedactor.HmacRedactor(Microsoft.Extensions.Options.IOptions<Microsoft.Extensions.Compliance.Redaction.HmacRedactorOptions> options);",
"Stage": "Stable"
},
{
"Member": "override int Microsoft.Extensions.Compliance.Redaction.HmacRedactor.GetRedactedLength(System.ReadOnlySpan<char> input);",
"Stage": "Stable"
},
{
"Member": "override int Microsoft.Extensions.Compliance.Redaction.HmacRedactor.Redact(System.ReadOnlySpan<char> source, System.Span<char> destination);",
"Stage": "Stable"
}
]
},
{
"Type": "class Microsoft.Extensions.Compliance.Redaction.HmacRedactorOptions",
"Stage": "Experimental",
"Stage": "Stable",
"Methods": [
{
"Member": "Microsoft.Extensions.Compliance.Redaction.HmacRedactorOptions.HmacRedactorOptions();",
"Stage": "Experimental"
"Stage": "Stable"
}
],
"Properties": [
{
"Member": "string Microsoft.Extensions.Compliance.Redaction.HmacRedactorOptions.Key { get; set; }",
"Stage": "Experimental"
"Stage": "Stable"
},
{
"Member": "int? Microsoft.Extensions.Compliance.Redaction.HmacRedactorOptions.KeyId { get; set; }",
"Stage": "Experimental"
"Stage": "Stable"
}
]
},
Expand All @@ -51,11 +69,11 @@
"Methods": [
{
"Member": "static Microsoft.Extensions.Compliance.Redaction.IRedactionBuilder Microsoft.Extensions.Compliance.Redaction.RedactionExtensions.SetHmacRedactor(this Microsoft.Extensions.Compliance.Redaction.IRedactionBuilder builder, System.Action<Microsoft.Extensions.Compliance.Redaction.HmacRedactorOptions> configure, params Microsoft.Extensions.Compliance.Classification.DataClassificationSet[] classifications);",
"Stage": "Experimental"
"Stage": "Stable"
},
{
"Member": "static Microsoft.Extensions.Compliance.Redaction.IRedactionBuilder Microsoft.Extensions.Compliance.Redaction.RedactionExtensions.SetHmacRedactor(this Microsoft.Extensions.Compliance.Redaction.IRedactionBuilder builder, Microsoft.Extensions.Configuration.IConfigurationSection section, params Microsoft.Extensions.Compliance.Classification.DataClassificationSet[] classifications);",
"Stage": "Experimental"
"Stage": "Stable"
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using Microsoft.Extensions.Compliance.Classification;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Shared.DiagnosticIds;
using Microsoft.Shared.Diagnostics;

namespace Microsoft.Extensions.Compliance.Redaction;
Expand All @@ -24,7 +23,6 @@ public static class RedactionExtensions
/// <param name="classifications">The data classifications for which the redactor type should be used.</param>
/// <returns>The value of <paramref name="builder" />.</returns>
/// <exception cref="ArgumentNullException"><paramref name="builder"/>, <paramref name="configure" />, or <paramref name="classifications" /> is <see langword="null"/>.</exception>
[Experimental(diagnosticId: DiagnosticIds.Experiments.Compliance, UrlFormat = DiagnosticIds.UrlFormat)]
public static IRedactionBuilder SetHmacRedactor(this IRedactionBuilder builder, Action<HmacRedactorOptions> configure, params DataClassificationSet[] classifications)
{
_ = Throw.IfNull(builder);
Expand All @@ -47,7 +45,6 @@ public static IRedactionBuilder SetHmacRedactor(this IRedactionBuilder builder,
/// <param name="classifications">The data classifications for which the redactor type should be used.</param>
/// <returns>The value of <paramref name="builder" />.</returns>
/// <exception cref="ArgumentNullException"><paramref name="builder"/>, <paramref name="section" />, or <paramref name="classifications" /> is <see langword="null"/>.</exception>
[Experimental(diagnosticId: DiagnosticIds.Experiments.Compliance, UrlFormat = DiagnosticIds.UrlFormat)]
[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(HmacRedactorOptions))]
[UnconditionalSuppressMessage(
"Trimming",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using Microsoft.Extensions.Logging;
using Microsoft.Shared.DiagnosticIds;
using Microsoft.Shared.Diagnostics;

namespace Microsoft.Extensions.Logging.Testing;
Expand Down Expand Up @@ -77,7 +75,6 @@ public FakeLogRecord(LogLevel level, EventId id, object? state, Exception? excep
/// The value associated with the key, or <see langword="null"/> if the key was not found. If the structured
/// state contains multiple entries with the same key, the value associated with the first matching key encountered is returned.
/// </returns>
[Experimental(diagnosticId: DiagnosticIds.Experiments.Telemetry, UrlFormat = DiagnosticIds.UrlFormat)]
public string? GetStructuredStateValue(string key)
{
if (StructuredState is not null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"Name": "Microsoft.Extensions.Diagnostics.Testing, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35",
"Name": "Microsoft.Extensions.Diagnostics.Testing, Version=8.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35",
"Types": [
{
"Type": "sealed class Microsoft.Extensions.Diagnostics.Metrics.Testing.CollectedMeasurement<T> where T : struct",
Expand Down Expand Up @@ -257,6 +257,10 @@
"Member": "Microsoft.Extensions.Logging.Testing.FakeLogRecord.FakeLogRecord(Microsoft.Extensions.Logging.LogLevel level, Microsoft.Extensions.Logging.EventId id, object? state, System.Exception? exception, string message, System.Collections.Generic.IReadOnlyList<object?> scopes, string? category, bool enabled, System.DateTimeOffset timestamp);",
"Stage": "Stable"
},
{
"Member": "string? Microsoft.Extensions.Logging.Testing.FakeLogRecord.GetStructuredStateValue(string key);",
"Stage": "Stable"
},
{
"Member": "override string Microsoft.Extensions.Logging.Testing.FakeLogRecord.ToString();",
"Stage": "Stable"
Expand Down