Skip to content

Commit 0c4ee9e

Browse files
authored
Use u8 in more places (#69995)
* Use u8 in more places Primarily replacing Encoding.UTF8/ASCII.GetBytes("literal") with "literal"u8.ToArray() * Address PR feedback (and fix some vars)
1 parent 9f654ce commit 0c4ee9e

File tree

138 files changed

+522
-578
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

138 files changed

+522
-578
lines changed

src/libraries/Common/tests/StreamConformanceTests/System/IO/StreamConformanceTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1855,7 +1855,7 @@ public virtual async Task Read_Eof_Returns0(ReadWriteMode mode, bool dataAvailab
18551855
{
18561856
write = Task.Run(async () =>
18571857
{
1858-
await writeable.WriteAsync(Encoding.UTF8.GetBytes("hello"));
1858+
await writeable.WriteAsync("hello"u8.ToArray());
18591859
await writeable.DisposeAsync();
18601860
});
18611861
}
@@ -2206,7 +2206,7 @@ public virtual async Task ZeroByteRead_BlocksUntilDataAvailableOrNops(ReadWriteM
22062206

22072207
Task write = Task.Run(async () =>
22082208
{
2209-
await writeable.WriteAsync(Encoding.UTF8.GetBytes("hello"));
2209+
await writeable.WriteAsync("hello"u8.ToArray());
22102210
if (FlushRequiredToWriteData)
22112211
{
22122212
if (FlushGuaranteesAllDataWritten)
@@ -2261,7 +2261,7 @@ public virtual async Task ZeroByteRead_BlocksUntilDataAvailableOrNops(ReadWriteM
22612261
[SkipOnPlatform(TestPlatforms.LinuxBionic, "SElinux blocks UNIX sockets")]
22622262
public virtual async Task ZeroByteWrite_OtherDataReceivedSuccessfully(ReadWriteMode mode)
22632263
{
2264-
byte[][] buffers = new[] { Array.Empty<byte>(), Encoding.UTF8.GetBytes("hello"), Array.Empty<byte>(), Encoding.UTF8.GetBytes("world") };
2264+
byte[][] buffers = new[] { Array.Empty<byte>(), "hello"u8.ToArray(), Array.Empty<byte>(), "world"u8.ToArray() };
22652265

22662266
using StreamPair streams = await CreateConnectedStreamsAsync();
22672267
foreach ((Stream writeable, Stream readable) in GetReadWritePairs(streams))
@@ -2915,7 +2915,7 @@ public virtual async Task ZeroByteRead_PerformsZeroByteReadOnUnderlyingStreamWhe
29152915
// (a) produce at least two readable bytes, so we can unblock the reader and read a single byte without clearing its buffer; and
29162916
// (b) produce no more than 1K of readable bytes, so we can clear the reader buffer below.
29172917
// If this isn't the case for some Stream(s), we can modify the data or parameterize it per Stream.
2918-
byte[] data = Encoding.UTF8.GetBytes("hello world");
2918+
byte[] data = "hello world"u8.ToArray();
29192919

29202920
using StreamPair innerStreams = ConnectedStreams.CreateBidirectional();
29212921
(Stream innerWriteable, Stream innerReadable) = GetReadWritePair(innerStreams);

src/libraries/Common/tests/System/Net/Http/Http2LoopbackConnection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ private async Task ReadPrefixAsync()
100100
// Since those tests are not set up to handle multiple retries, we instead just send back an invalid response here
101101
// so that SocketsHttpHandler will not induce retry.
102102
// The contents of what we send don't really matter, as long as it is interpreted by SocketsHttpHandler as an invalid response.
103-
await _connectionStream.WriteAsync(Encoding.ASCII.GetBytes("HTTP/2.0 400 Bad Request\r\n\r\n"));
103+
await _connectionStream.WriteAsync("HTTP/2.0 400 Bad Request\r\n\r\n"u8.ToArray());
104104
_connectionSocket.Shutdown(SocketShutdown.Send);
105105
// If WinHTTP doesn't support streaming a request without a length then it will fallback
106106
// to HTTP/1.1. Throwing an exception to detect this case in WinHttpHandler tests.

src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/DSA/DSAKeyFileTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public static void ReadWriteDsa1024EncryptedPkcs8_PasswordBytes()
182182
qE3Db1UI4anCCnyEj/jDA8R6hZTFDjxu6bG0Z66g7I2GBDEYaaB+8x0vtiyu5LXo
183183
6UZ53SX6S+jfIqJoF5YME9zVMoO2kwS/EGvc64+epCGcee1Nx4SGgUcr5HJYz1P4
184184
CU+l4wPQR0rRmYHIJJIvFh5OXk84pV0crsOrekw7tHeNU6DMzw==",
185-
Encoding.UTF8.GetBytes("Password > cipher"),
185+
"Password > cipher"u8.ToArray(),
186186
new PbeParameters(
187187
PbeEncryptionAlgorithm.Aes192Cbc,
188188
HashAlgorithmName.SHA256,

src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/DSA/DSAKeyPemTests.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ public static void ImportFromEncryptedPem_Pkcs8_Encrypted_Byte_Simple()
287287
xTL6VO9mx52x6h5WDAQAisMVeMkBoxQUWLANXiw1zSfVbsmB7mDknsRcvD3tcgMs
288288
7YLD7LQMiPAIjDlOP8XP/w==
289289
-----END ENCRYPTED PRIVATE KEY-----";
290-
byte[] passwordBytes = Encoding.UTF8.GetBytes("test");
290+
byte[] passwordBytes = "test"u8.ToArray();
291291
dsa.ImportFromEncryptedPem(pem, passwordBytes);
292292
DSAParameters dsaParameters = dsa.ExportParameters(true);
293293

@@ -319,9 +319,8 @@ public static void ImportFromEncryptedPem_Pkcs8_Encrypted_AmbiguousPem()
319319
dVYwfovccu8ktEAwk5XAOo0r+5CCw2lDDw/hbDeO87BToC5Cc5nu3F5LxAUj8Flc
320320
v8pi3w==
321321
-----END ENCRYPTED PRIVATE KEY-----";
322-
byte[] passwordBytes = Encoding.UTF8.GetBytes("test");
323322
ArgumentException ae = AssertExtensions.Throws<ArgumentException>("input", () =>
324-
dsa.ImportFromEncryptedPem(pem, passwordBytes));
323+
dsa.ImportFromEncryptedPem(pem, "test"u8));
325324
Assert.Contains(AmbiguousExceptionMarker, ae.Message);
326325
}
327326
}
@@ -332,9 +331,8 @@ public static void ImportFromEncryptedPem_Pkcs8_Byte_NoPem()
332331
using (DSA dsa = DSAFactory.Create())
333332
{
334333
string pem = "";
335-
byte[] passwordBytes = Encoding.UTF8.GetBytes("test");
336334
ArgumentException ae = AssertExtensions.Throws<ArgumentException>("input", () =>
337-
dsa.ImportFromEncryptedPem(pem, passwordBytes));
335+
dsa.ImportFromEncryptedPem(pem, "test"u8));
338336
Assert.Contains(NoPemExceptionMarker, ae.Message);
339337
}
340338
}

src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/DSA/DSATestData.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ internal static void GetDSA1024_186_2(out DSAParameters parameters, out byte[] s
171171
"41e2345f1f56df2458f426d155b4ba2db6dcd8c8"
172172
).HexToByteArray();
173173

174-
data = Encoding.ASCII.GetBytes("abc");
174+
data = "abc"u8.ToArray();
175175
}
176176
}
177177
}

src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/EC/ECKeyFileTests.LimitedPrivate.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public void ReadNistP521EncryptedPkcs8_Pbes2_Aes128_LimitedPrivateKey_PasswordBy
8383

8484
ReadWriteBase64EncryptedPkcs8(
8585
base64,
86-
Encoding.UTF8.GetBytes("qwerty"),
86+
"qwerty"u8.ToArray(),
8787
new PbeParameters(
8888
PbeEncryptionAlgorithm.Aes256Cbc,
8989
HashAlgorithmName.SHA1,

src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/EC/ECKeyFileTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ public void ReadNistP521EncryptedPkcs8_Pbes2_Aes128_Sha384_PasswordBytes()
195195

196196
ReadWriteBase64EncryptedPkcs8(
197197
base64,
198-
Encoding.UTF8.GetBytes("qwerty"),
198+
"qwerty"u8.ToArray(),
199199
new PbeParameters(
200200
PbeEncryptionAlgorithm.Aes256Cbc,
201201
HashAlgorithmName.SHA1,

src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/EC/ECKeyPemTests.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,7 @@ public void ImportFromEncryptedPem_Pkcs8_Byte_Simple()
342342
/OMt/tWvtMSj17+dJvShsu/NYJXF5fsfpSJbd3e50Y3AisW0Ob7mmF54KBfg6Y+4
343343
aATwwQdUIKVzUZsQctsHPjbriQKKn7GKSyUOikBUNQ+TozojX8/g7JAsl+T9jGM=
344344
-----END ENCRYPTED PRIVATE KEY-----";
345-
byte[] passwordBytes = Encoding.UTF8.GetBytes("test");
346-
key.ImportFromEncryptedPem(pem, passwordBytes);
345+
key.ImportFromEncryptedPem(pem, "test"u8);
347346
ECParameters ecParameters = key.ExportParameters(true);
348347
ECParameters expected = EccTestData.GetNistP256ReferenceKey();
349348
EccTestBase.AssertEqual(expected, ecParameters);
@@ -370,10 +369,9 @@ public void ImportFromEncryptedPem_AmbiguousPem_Byte()
370369
opSAJ/pvHONL5kyAJLeNyG9c/mR2qyrP2L9gL0Z5fB9NyPejKTLi0PXMGQWdDTH8
371370
Qh0fqdrNovgFLubbJFMQN/MwwIAfIuf0Mn0WFYYeQiBJ3kg=
372371
-----END ENCRYPTED PRIVATE KEY-----";
373-
byte[] passwordBytes = Encoding.UTF8.GetBytes("test");
374372

375373
ArgumentException ae = AssertExtensions.Throws<ArgumentException>("input", () =>
376-
key.ImportFromEncryptedPem(pem, passwordBytes));
374+
key.ImportFromEncryptedPem(pem, "test"u8));
377375

378376
Assert.Contains(AmbiguousExceptionMarker, ae.Message);
379377
}

src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/ECDsa/ECDsaTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,6 @@ public static IEnumerable<object[]> InteroperableSignatureConfigurations()
274274
[MemberData(nameof(InteroperableSignatureConfigurations))]
275275
public void SignVerify_InteroperableSameKeys_RoundTripsUnlessTampered(ECDsa ecdsa, HashAlgorithmName hashAlgorithm)
276276
{
277-
byte[] data = Encoding.UTF8.GetBytes("something to repeat and sign");
278-
279277
// large enough to make hashing work though multiple iterations and not a multiple of 4KB it uses.
280278
byte[] dataArray = new byte[33333];
281279

src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/RSA/RSAKeyFileTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ public static void ReadPbes2Rc2EncryptedDiminishedDP_PasswordBytes()
781781

782782
ReadBase64EncryptedPkcs8(
783783
base64,
784-
Encoding.UTF8.GetBytes("rc2"),
784+
"rc2"u8.ToArray(),
785785
new PbeParameters(
786786
PbeEncryptionAlgorithm.Aes192Cbc,
787787
HashAlgorithmName.SHA256,

src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/RSA/RSAKeyPemTests.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ public static void ImportFromEncryptedPem_Pkcs8Encrypted_Byte_Simple()
425425
5QSEe7EKVF0aHXBYB5SzMGVuxR/BqydDa26jlhVzO3LNvy9FYuqLKUslCrBCmPrt
426426
raZNyk8KAsLs+FJq9T2tda0=
427427
-----END ENCRYPTED PRIVATE KEY-----";
428-
rsa.ImportFromEncryptedPem(pem, Encoding.UTF8.GetBytes("test"));
428+
rsa.ImportFromEncryptedPem(pem, "test"u8);
429429
RSAParameters rsaParameters = rsa.ExportParameters(true);
430430

431431
ImportExport.AssertKeyEquals(TestData.DiminishedDPParameters, rsaParameters);
@@ -462,9 +462,8 @@ public static void ImportFromEncryptedPem_Pkcs8Encrypted_AmbiguousPem()
462462
N4lD7/hJq7b+yYPhlN3Fvvt8M9MtRg1TLAve67CA2v4TITHB06M/ELe3y42bZuLW
463463
CA7ffFk=
464464
-----END ENCRYPTED PRIVATE KEY-----";
465-
byte[] passwordBytes = Encoding.UTF8.GetBytes("test");
466465
ArgumentException ae = AssertExtensions.Throws<ArgumentException>("input", () =>
467-
rsa.ImportFromEncryptedPem(pem, passwordBytes));
466+
rsa.ImportFromEncryptedPem(pem, "test"u8));
468467
Assert.Contains(AmbiguousExceptionMarker, ae.Message);
469468
}
470469
}
@@ -475,9 +474,8 @@ public static void ImportFromEncryptedPem_Pkcs8Encrypted_Byte_NoPem()
475474
using (RSA rsa = RSAFactory.Create())
476475
{
477476
string pem = "these aren't the PEMs we're looking for.";
478-
byte[] passwordBytes = Encoding.UTF8.GetBytes("test");
479477
ArgumentException ae = AssertExtensions.Throws<ArgumentException>("input", () =>
480-
rsa.ImportFromEncryptedPem(pem, passwordBytes));
478+
rsa.ImportFromEncryptedPem(pem, "test"u8));
481479
Assert.Contains(NoPemExceptionMarker, ae.Message);
482480
}
483481
}
@@ -498,9 +496,8 @@ public static void ImportFromEncryptedPem_NoEncryptedPem()
498496
acPiMCuFTnRSFYAhozpmsqoLyTREqwIhAMLJlZTGjEB2N+sEazH5ToEczQzKqp7t
499497
9juGNbOPhoEL
500498
-----END PRIVATE KEY-----";
501-
byte[] passwordBytes = Encoding.UTF8.GetBytes("test");
502499
ArgumentException ae = AssertExtensions.Throws<ArgumentException>("input", () =>
503-
rsa.ImportFromEncryptedPem(pem, passwordBytes));
500+
rsa.ImportFromEncryptedPem(pem, "test"u8));
504501
Assert.Contains(NoPemExceptionMarker, ae.Message);
505502
}
506503
}

src/libraries/Common/tests/Tests/System/StringTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7418,8 +7418,7 @@ public static unsafe void Ctor_SByte_NullPointer_ReturnsEmptyString()
74187418
[Fact]
74197419
public static void CreateStringFromEncoding_0Length_EmptyStringReturned() // basic test for code coverage; more tests in encodings tests
74207420
{
7421-
byte[] bytes = Encoding.ASCII.GetBytes("hello");
7422-
Assert.Same(string.Empty, new AsciiEncodingWithZeroReturningGetCharCount().GetString(bytes, 0, 0));
7421+
Assert.Same(string.Empty, new AsciiEncodingWithZeroReturningGetCharCount().GetString("hello"u8.ToArray(), 0, 0));
74237422
}
74247423

74257424
private sealed class AsciiEncodingWithZeroReturningGetCharCount : ASCIIEncoding

src/libraries/System.Diagnostics.Process/tests/RemotelyInvokable.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public static int ReadLineWithCustomEncodingWriteLineWithUtf8(string inputEncodi
9999
public static int WriteSlowlyByByte()
100100
{
101101
var stdout = Console.OpenStandardOutput();
102-
var bytes = new byte[] { 97, 0 }; //Encoding.Unicode.GetBytes("a");
102+
var bytes = new byte[] { 97, 0 }; // Encoding.Unicode.GetBytes("a");
103103

104104
for (int i = 0; i != bytes.Length; ++i)
105105
{

src/libraries/System.DirectoryServices.Protocols/tests/DirectoryServicesProtocolsTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -479,18 +479,18 @@ private static void RunAsyncSearch(IAsyncResult asyncResult)
479479
public static IEnumerable<object[]> TestCompareRequestTheory_TestData()
480480
{
481481
yield return new object[] { "input", "input", ResultCode.CompareTrue };
482-
yield return new object[] { "input", Encoding.UTF8.GetBytes("input"), ResultCode.CompareTrue };
482+
yield return new object[] { "input", "input"u8.ToArray(), ResultCode.CompareTrue };
483483

484484
yield return new object[] { "input", "false", ResultCode.CompareFalse };
485485
yield return new object[] { "input", new byte[] { 1, 2, 3, 4, 5 }, ResultCode.CompareFalse };
486486

487487
yield return new object[] { "http://example.com/", "http://example.com/", ResultCode.CompareTrue };
488488
yield return new object[] { "http://example.com/", new Uri("http://example.com/"), ResultCode.CompareTrue };
489-
yield return new object[] { "http://example.com/", Encoding.UTF8.GetBytes("http://example.com/"), ResultCode.CompareTrue };
489+
yield return new object[] { "http://example.com/", "http://example.com/"u8.ToArray(), ResultCode.CompareTrue };
490490

491491
yield return new object[] { "http://example.com/", "http://false/", ResultCode.CompareFalse };
492492
yield return new object[] { "http://example.com/", new Uri("http://false/"), ResultCode.CompareFalse };
493-
yield return new object[] { "http://example.com/", Encoding.UTF8.GetBytes("http://false/"), ResultCode.CompareFalse };
493+
yield return new object[] { "http://example.com/", "http://false/"u8.ToArray(), ResultCode.CompareFalse };
494494
}
495495

496496
[ConditionalTheory(nameof(IsLdapConfigurationExist))]

src/libraries/System.Drawing.Common/tests/ImageTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ public void SetPropertyItem_InvokeMemoryBitmap_Success(int propid)
238238

239239
// Change data.
240240
PropertyItem item = source.GetPropertyItem(PropertyTagExifUserComment);
241-
item.Value = Encoding.ASCII.GetBytes("Hello World\0");
241+
item.Value = "Hello World\0"u8.ToArray();
242242
item.Len = item.Value.Length;
243243

244244
bitmap.SetPropertyItem(item);
@@ -253,7 +253,7 @@ public void SetPropertyItem_InvokeMemoryBitmap_Success(int propid)
253253

254254
// New data.
255255
item.Id = propid;
256-
item.Value = Encoding.ASCII.GetBytes("New Value\0");
256+
item.Value = "New Value\0"u8.ToArray();
257257
item.Len = item.Value.Length;
258258

259259
bitmap.SetPropertyItem(item);
@@ -296,7 +296,7 @@ public void SetPropertyItem_InvokeBitmapJpg_Success(int propid)
296296

297297
// Change data.
298298
PropertyItem item = bitmap.GetPropertyItem(PropertyTagExifUserComment);
299-
item.Value = Encoding.ASCII.GetBytes("Hello World\0");
299+
item.Value = "Hello World\0"u8.ToArray();
300300
item.Len = item.Value.Length;
301301

302302
bitmap.SetPropertyItem(item);
@@ -339,7 +339,7 @@ public void SetPropertyItem_InvokeBitmapJpg_Success(int propid)
339339

340340
// New data.
341341
item.Id = propid;
342-
item.Value = Encoding.ASCII.GetBytes("New Value\0");
342+
item.Value = "New Value\0"u8.ToArray();
343343
item.Len = item.Value.Length;
344344

345345
bitmap.SetPropertyItem(item);
@@ -439,7 +439,7 @@ public void SetPropertyItem_InvokeBitmapBmp_Success(int propid)
439439

440440
// Change data.
441441
PropertyItem item = source.GetPropertyItem(PropertyTagExifUserComment);
442-
item.Value = Encoding.ASCII.GetBytes("Hello World\0");
442+
item.Value = "Hello World\0"u8.ToArray();
443443
item.Len = item.Value.Length;
444444

445445
bitmap.SetPropertyItem(item);
@@ -454,7 +454,7 @@ public void SetPropertyItem_InvokeBitmapBmp_Success(int propid)
454454

455455
// New data.
456456
item.Id = propid;
457-
item.Value = Encoding.ASCII.GetBytes("New Value\0");
457+
item.Value = "New Value\0"u8.ToArray();
458458
item.Len = item.Value.Length;
459459

460460
bitmap.SetPropertyItem(item);

src/libraries/System.Formats.Asn1/tests/Reader/ReadGeneralizedTime.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ public static void MaximumEffectivePrecision(AsnEncodingRules ruleSet, string da
229229
[Fact]
230230
public static void ExcessivelyPreciseFraction()
231231
{
232-
byte[] inputData = Text.Encoding.ASCII.GetBytes("\u0018\u002A2017092118.012345678901234567890123456789Z");
232+
byte[] inputData = "\u0018\u002A2017092118.012345678901234567890123456789Z"u8.ToArray();
233233

234234
AsnReader berReader = new AsnReader(inputData, AsnEncodingRules.BER);
235235
DateTimeOffset value = berReader.ReadGeneralizedTime();
@@ -244,7 +244,7 @@ public static void ExcessivelyPreciseFraction()
244244
[Fact]
245245
public static void ExcessivelyPreciseFraction_OneTenthPlusEpsilon()
246246
{
247-
byte[] inputData = Text.Encoding.ASCII.GetBytes("\u0018\u002A20170921180044.10000000000000000000000001Z");
247+
byte[] inputData = "\u0018\u002A20170921180044.10000000000000000000000001Z"u8.ToArray();
248248

249249
AsnReader derReader = new AsnReader(inputData, AsnEncodingRules.DER);
250250
DateTimeOffset value = derReader.ReadGeneralizedTime();
@@ -287,7 +287,7 @@ public static void MultiSegmentExcessivelyPreciseFraction(AsnEncodingRules ruleS
287287
[Fact]
288288
public static void ExcessivelyPreciseFraction_OneTenthPlusEpsilonAndZero()
289289
{
290-
byte[] inputData = Text.Encoding.ASCII.GetBytes("\u0018\u002A20170921180044.10000000000000000000000010Z");
290+
byte[] inputData = "\u0018\u002A20170921180044.10000000000000000000000010Z"u8.ToArray();
291291

292292
AsnReader berReader = new AsnReader(inputData, AsnEncodingRules.BER);
293293
DateTimeOffset value = berReader.ReadGeneralizedTime();
@@ -305,7 +305,7 @@ public static void ExcessivelyPreciseFraction_OneTenthPlusEpsilonAndZero()
305305
[Fact]
306306
public static void ExcessivelyPreciseNonFraction()
307307
{
308-
byte[] inputData = Text.Encoding.ASCII.GetBytes("\u0018\u002A2017092118.012345678901234567890123Q56789Z");
308+
byte[] inputData = "\u0018\u002A2017092118.012345678901234567890123Q56789Z"u8.ToArray();
309309
AsnReader berReader = new AsnReader(inputData, AsnEncodingRules.BER);
310310

311311
Assert.Throws<AsnContentException>(() => berReader.ReadGeneralizedTime());

src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarHeader.Write.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ namespace System.Formats.Tar
1212
// Writes header attributes of a tar archive entry.
1313
internal partial struct TarHeader
1414
{
15-
private static ReadOnlySpan<byte> PaxMagicBytes => new byte[] { 0x75, 0x73, 0x74, 0x61, 0x72, 0x0 }; // "ustar\0"
16-
private static ReadOnlySpan<byte> PaxVersionBytes => new byte[] { TarHelpers.ZeroChar, TarHelpers.ZeroChar }; // "00"
15+
private static ReadOnlySpan<byte> PaxMagicBytes => "ustar\0"u8;
16+
private static ReadOnlySpan<byte> PaxVersionBytes => "00"u8;
1717

18-
private static ReadOnlySpan<byte> GnuMagicBytes => new byte[] { 0x75, 0x73, 0x74, 0x61, 0x72, TarHelpers.SpaceChar }; // "ustar "
19-
private static ReadOnlySpan<byte> GnuVersionBytes => new byte[] { TarHelpers.SpaceChar, 0x0 }; // " \0"
18+
private static ReadOnlySpan<byte> GnuMagicBytes => "ustar "u8;
19+
private static ReadOnlySpan<byte> GnuVersionBytes => " \0"u8;
2020

2121
// Extended Attribute entries have a special format in the Name field:
2222
// "{dirName}/PaxHeaders.{processId}/{fileName}{trailingSeparator}"

0 commit comments

Comments
 (0)