-
Notifications
You must be signed in to change notification settings - Fork 741
/
NullRedactor.cs
36 lines (29 loc) · 1.09 KB
/
NullRedactor.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using Microsoft.Shared.Diagnostics;
namespace Microsoft.Extensions.Compliance.Redaction;
/// <summary>
/// Redactor that does nothing to its input and returns it as-is.
/// </summary>
public sealed class NullRedactor : Redactor
{
/// <summary>
/// Gets the singleton instance of this class.
/// </summary>
public static NullRedactor Instance { get; } = new();
/// <inheritdoc/>
public override int GetRedactedLength(ReadOnlySpan<char> input) => input.Length;
/// <inheritdoc/>
public override int Redact(ReadOnlySpan<char> source, Span<char> destination)
{
if (!source.TryCopyTo(destination))
{
// will throw unconditionally, with a nice error message
Throw.IfBufferTooSmall(destination.Length, source.Length, nameof(destination));
}
return source.Length;
}
/// <inheritdoc/>
public override string Redact(string? source) => source ?? string.Empty;
}