diff options
author | Ahson Khan <ahkha@microsoft.com> | 2017-12-21 22:05:06 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-21 22:05:06 +0300 |
commit | 40cbd5636851093309b841db4d53af369b7ef1c6 (patch) | |
tree | 640436a50078dbf78e3e1c456df2a8c85aae72c2 /src/System.Security.Cryptography.Encoding | |
parent | e29f0dc6e1996853d4c91553bad17a5e49ad9783 (diff) |
Convert uses of the Dangerous APIs to use MemoryMarshal.GetReference (#25936)
* Convert uses of the Dangerous APIs to use MemoryMarshal.GetReference
* Fix unresolved merge conflict.
* Add using directive
* Add missing using directives.
* Add references to System.Memory
Diffstat (limited to 'src/System.Security.Cryptography.Encoding')
8 files changed, 17 insertions, 10 deletions
diff --git a/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ComprehensiveReadTests.cs b/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ComprehensiveReadTests.cs index 768a56e948..0d80672dad 100644 --- a/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ComprehensiveReadTests.cs +++ b/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ComprehensiveReadTests.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; using System.Security.Cryptography.Asn1; using Test.Cryptography; using Xunit; @@ -190,7 +191,7 @@ namespace System.Security.Cryptography.Tests.Asn1 Assert.Equal(valueTag, actualTag); AssertRefSame( - ref valueSpan.DangerousGetPinnableReference(), + ref MemoryMarshal.GetReference(valueSpan), ref bytes[offset], $"{label} is at bytes[{offset}]"); @@ -207,7 +208,7 @@ namespace System.Security.Cryptography.Tests.Asn1 private static void AssertRefSame(ReadOnlyMemory<byte> a, ref byte b, string msg) { - AssertRefSame(ref a.Span.DangerousGetPinnableReference(), ref b, msg); + AssertRefSame(ref MemoryMarshal.GetReference(a.Span), ref b, msg); } private static void AssertRefSame(ref byte a, ref byte b, string msg) diff --git a/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/PeekTests.cs b/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/PeekTests.cs index c5814b41c8..f09e92095e 100644 --- a/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/PeekTests.cs +++ b/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/PeekTests.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; using System.Security.Cryptography.Asn1; using Test.Cryptography; using Xunit; @@ -172,7 +173,7 @@ namespace System.Security.Cryptography.Tests.Asn1 AsnReader reader = new AsnReader(dataBytes, AsnEncodingRules.BER); ReadOnlyMemory<byte> contents = reader.PeekContentBytes(); Assert.Equal(expectedLength, contents.Length); - Assert.True(Unsafe.AreSame(ref dataBytes[2], ref contents.Span.DangerousGetPinnableReference())); + Assert.True(Unsafe.AreSame(ref dataBytes[2], ref MemoryMarshal.GetReference(contents.Span))); } [Theory] @@ -207,7 +208,7 @@ namespace System.Security.Cryptography.Tests.Asn1 AsnReader reader = new AsnReader(dataBytes, AsnEncodingRules.BER); ReadOnlyMemory<byte> contents = reader.PeekEncodedValue(); Assert.Equal(expectedLength, contents.Length); - Assert.True(Unsafe.AreSame(ref dataBytes[0], ref contents.Span.DangerousGetPinnableReference())); + Assert.True(Unsafe.AreSame(ref dataBytes[0], ref MemoryMarshal.GetReference(contents.Span))); } } } diff --git a/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadBMPString.cs b/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadBMPString.cs index c8e8c42cea..62b8439e0a 100644 --- a/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadBMPString.cs +++ b/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadBMPString.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; using System.Security.Cryptography.Asn1; using Test.Cryptography; using Xunit; @@ -229,7 +230,7 @@ namespace System.Security.Cryptography.Tests.Asn1 Assert.True( Unsafe.AreSame( - ref contents.Span.DangerousGetPinnableReference(), + ref MemoryMarshal.GetReference(contents.Span), ref inputData[2])); } else diff --git a/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadBitString.cs b/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadBitString.cs index 2455c2efcb..7d4bae41d3 100644 --- a/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadBitString.cs +++ b/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadBitString.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; using System.Security.Cryptography.Asn1; using Test.Cryptography; using Xunit; @@ -149,7 +150,7 @@ namespace System.Security.Cryptography.Tests.Asn1 // Check that it is, in fact, the same memory. No copies with this API. Assert.True( Unsafe.AreSame( - ref contents.Span.DangerousGetPinnableReference(), + ref MemoryMarshal.GetReference(contents.Span), ref input[5])); } diff --git a/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadIA5String.cs b/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadIA5String.cs index 8319493513..42dc62a77e 100644 --- a/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadIA5String.cs +++ b/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadIA5String.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; using System.Security.Cryptography.Asn1; using Test.Cryptography; using Xunit; @@ -223,7 +224,7 @@ namespace System.Security.Cryptography.Tests.Asn1 Assert.True( Unsafe.AreSame( - ref contents.Span.DangerousGetPinnableReference(), + ref MemoryMarshal.GetReference(contents.Span), ref inputData[2])); } else diff --git a/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadOctetString.cs b/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadOctetString.cs index 4167418b43..2283f4f95a 100644 --- a/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadOctetString.cs +++ b/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadOctetString.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; using System.Security.Cryptography.Asn1; using Test.Cryptography; using Xunit; @@ -124,7 +125,7 @@ namespace System.Security.Cryptography.Tests.Asn1 // Check that it is, in fact, the same memory. No copies with this API. Assert.True( Unsafe.AreSame( - ref contents.Span.DangerousGetPinnableReference(), + ref MemoryMarshal.GetReference(contents.Span), ref input[4])); } diff --git a/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadUTF8String.cs b/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadUTF8String.cs index 8397bfc654..5ab1b6dc51 100644 --- a/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadUTF8String.cs +++ b/src/System.Security.Cryptography.Encoding/tests/Asn1/Reader/ReadUTF8String.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; using System.Security.Cryptography.Asn1; using Test.Cryptography; using Xunit; @@ -237,7 +238,7 @@ namespace System.Security.Cryptography.Tests.Asn1 Assert.True( Unsafe.AreSame( - ref contents.Span.DangerousGetPinnableReference(), + ref MemoryMarshal.GetReference(contents.Span), ref inputData[2])); } else diff --git a/src/System.Security.Cryptography.Encoding/tests/Asn1/Serializer/SimpleDeserialize.cs b/src/System.Security.Cryptography.Encoding/tests/Asn1/Serializer/SimpleDeserialize.cs index a99e323abc..6ca6a21036 100644 --- a/src/System.Security.Cryptography.Encoding/tests/Asn1/Serializer/SimpleDeserialize.cs +++ b/src/System.Security.Cryptography.Encoding/tests/Asn1/Serializer/SimpleDeserialize.cs @@ -403,7 +403,7 @@ namespace System.Security.Cryptography.Tests.Asn1 Assert.Equal("0.0", data.Id); Assert.Equal(5, data.Data.Length); - Assert.True(Unsafe.AreSame(ref data.Data.Span.DangerousGetPinnableReference(), ref inputData[5])); + Assert.True(Unsafe.AreSame(ref MemoryMarshal.GetReference(data.Data.Span), ref inputData[5])); // Change [Constructed] SEQUENCE to [Constructed] Context-Specific 0. inputData[5] = 0xA0; |