Skip to content

Commit 7d8d297

Browse files
committed
Use ArgumentValidator instead of custom arg validation logic
1 parent 847ed98 commit 7d8d297

File tree

3 files changed

+3
-42
lines changed

3 files changed

+3
-42
lines changed

MimeKit/Encodings/Base64Validator.cs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -75,19 +75,6 @@ public ContentEncoding Encoding {
7575
get { return ContentEncoding.Base64; }
7676
}
7777

78-
[MethodImpl (MethodImplOptions.AggressiveInlining)]
79-
static void ValidateArguments (byte[] input, int startIndex, int length)
80-
{
81-
if (input is null)
82-
throw new ArgumentNullException (nameof (input));
83-
84-
if (startIndex < 0 || startIndex > input.Length)
85-
throw new ArgumentOutOfRangeException (nameof (startIndex));
86-
87-
if (length < 0 || length > (input.Length - startIndex))
88-
throw new ArgumentOutOfRangeException (nameof (length));
89-
}
90-
9178
#if NET6_0_OR_GREATER
9279
[SkipLocalsInit]
9380
#endif
@@ -182,7 +169,7 @@ unsafe void Validate (ref byte table, byte* input, int length)
182169
/// </exception>
183170
public unsafe void Write (byte[] buffer, int startIndex, int length)
184171
{
185-
ValidateArguments (buffer, startIndex, length);
172+
ArgumentValidator.Validate (buffer, startIndex, length);
186173

187174
if (invalid)
188175
return;

MimeKit/Encodings/QuotedPrintableValidator.cs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,6 @@ public ContentEncoding Encoding {
8080
get { return ContentEncoding.QuotedPrintable; }
8181
}
8282

83-
[MethodImpl (MethodImplOptions.AggressiveInlining)]
84-
static void ValidateArguments (byte[] input, int startIndex, int length)
85-
{
86-
if (input is null)
87-
throw new ArgumentNullException (nameof (input));
88-
89-
if (startIndex < 0 || startIndex > input.Length)
90-
throw new ArgumentOutOfRangeException (nameof (startIndex));
91-
92-
if (length < 0 || length > (input.Length - startIndex))
93-
throw new ArgumentOutOfRangeException (nameof (length));
94-
}
95-
9683
#if NET6_0_OR_GREATER
9784
[SkipLocalsInit]
9885
#endif
@@ -181,7 +168,7 @@ unsafe void Validate (byte* input, int length)
181168
/// </exception>
182169
public unsafe void Write (byte[] buffer, int startIndex, int length)
183170
{
184-
ValidateArguments (buffer, startIndex, length);
171+
ArgumentValidator.Validate (buffer, startIndex, length);
185172

186173
fixed (byte* inbuf = buffer) {
187174
Validate (inbuf + startIndex, length);

MimeKit/Encodings/UUValidator.cs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -98,19 +98,6 @@ public ContentEncoding Encoding {
9898
get { return ContentEncoding.UUEncode; }
9999
}
100100

101-
[MethodImpl (MethodImplOptions.AggressiveInlining)]
102-
static void ValidateArguments (byte[] input, int startIndex, int length)
103-
{
104-
if (input is null)
105-
throw new ArgumentNullException (nameof (input));
106-
107-
if (startIndex < 0 || startIndex > input.Length)
108-
throw new ArgumentOutOfRangeException (nameof (startIndex));
109-
110-
if (length < 0 || length > (input.Length - startIndex))
111-
throw new ArgumentOutOfRangeException (nameof (length));
112-
}
113-
114101
[MethodImpl (MethodImplOptions.AggressiveInlining)]
115102
unsafe byte ReadByte (ref byte* inptr)
116103
{
@@ -495,7 +482,7 @@ unsafe void Validate (byte* input, int length)
495482
/// </exception>
496483
public unsafe void Write (byte[] buffer, int startIndex, int length)
497484
{
498-
ValidateArguments (buffer, startIndex, length);
485+
ArgumentValidator.Validate (buffer, startIndex, length);
499486

500487
if (state == UUValidatorState.Invalid)
501488
return;

0 commit comments

Comments
 (0)