mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
2c000b032d
* Update providers to use Microsoft.Extensions.Compliance.Redaction * Fix formatting. * Fix readme
36 lines
1.2 KiB
C#
36 lines
1.2 KiB
C#
// Copyright (c) Microsoft. All rights reserved.
|
|
|
|
using System;
|
|
using Microsoft.Extensions.Compliance.Redaction;
|
|
using Microsoft.Shared.Diagnostics;
|
|
|
|
namespace Microsoft.Agents.AI;
|
|
|
|
/// <summary>
|
|
/// A <see cref="Redactor"/> that replaces the entire input with a fixed replacement string.
|
|
/// </summary>
|
|
internal sealed class ReplacingRedactor : Redactor
|
|
{
|
|
private readonly string _replacementText;
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="ReplacingRedactor"/> class.
|
|
/// </summary>
|
|
/// <param name="replacementText">The text to substitute for any input value.</param>
|
|
/// <exception cref="ArgumentNullException">Thrown when <paramref name="replacementText"/> is <see langword="null"/>.</exception>
|
|
public ReplacingRedactor(string replacementText)
|
|
{
|
|
this._replacementText = Throw.IfNull(replacementText);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public override int GetRedactedLength(ReadOnlySpan<char> input) => this._replacementText.Length;
|
|
|
|
/// <inheritdoc />
|
|
public override int Redact(ReadOnlySpan<char> source, Span<char> destination)
|
|
{
|
|
this._replacementText.AsSpan().CopyTo(destination);
|
|
return this._replacementText.Length;
|
|
}
|
|
}
|