Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/corefx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFilip Navara <filip.navara@gmail.com>2018-06-10 11:40:52 +0300
committerAlexander Köplinger <alex.koeplinger@outlook.com>2018-06-10 11:40:52 +0300
commit78a03ecb6e44f2e2c1b4a9b9a35be8876db44c98 (patch)
treeb1fb4f1e96c94c6a31fe65755b0deb2bfe38a3e7
parent62eb6bea5f339913711571c14018e4e2eb790781 (diff)
Convert local function to an instance one to allow compilation with mcs. (#78)
* Convert local function to an instance one to allow compilation with mcs. * Workaround missing mcs C# 7 features.
-rw-r--r--src/Common/src/System/Security/Cryptography/AsnReader.cs45
-rw-r--r--src/Common/src/System/Security/Cryptography/AsnWriter.cs14
-rw-r--r--src/System.Security.Cryptography.Pkcs/src/Internal/Cryptography/Pal/AnyOS/ManagedPal.Asn.cs4
3 files changed, 38 insertions, 25 deletions
diff --git a/src/Common/src/System/Security/Cryptography/AsnReader.cs b/src/Common/src/System/Security/Cryptography/AsnReader.cs
index 54601ff321..52ea683e14 100644
--- a/src/Common/src/System/Security/Cryptography/AsnReader.cs
+++ b/src/Common/src/System/Security/Cryptography/AsnReader.cs
@@ -2462,6 +2462,25 @@ namespace System.Security.Cryptography.Asn1
return value;
}
+ const byte HmsState = 0;
+ const byte FracState = 1;
+ const byte SuffixState = 2;
+
+ private static byte? ParseGeneralizedTime_GetNextState(byte octet)
+ {
+ if (octet == 'Z' || octet == '-' || octet == '+')
+ {
+ return SuffixState;
+ }
+
+ if (octet == '.' || octet == ',')
+ {
+ return FracState;
+ }
+
+ return null;
+ }
+
private static DateTimeOffset ParseGeneralizedTime(
AsnEncodingRules ruleSet,
ReadOnlySpan<byte> contentOctets,
@@ -2524,32 +2543,14 @@ namespace System.Security.Cryptography.Asn1
TimeSpan? timeOffset = null;
bool isZulu = false;
- const byte HmsState = 0;
- const byte FracState = 1;
- const byte SuffixState = 2;
byte state = HmsState;
- byte? GetNextState(byte octet)
- {
- if (octet == 'Z' || octet == '-' || octet == '+')
- {
- return SuffixState;
- }
-
- if (octet == '.' || octet == ',')
- {
- return FracState;
- }
-
- return null;
- }
-
// This while loop could be rewritten to include the FracState and Suffix
// processing steps. But since there's a forward flow to the state machine
// the loop body then needs to account for that.
while (state == HmsState && contents.Length != 0)
{
- byte? nextState = GetNextState(contents[0]);
+ byte? nextState = ParseGeneralizedTime_GetNextState(contents[0]);
if (nextState == null)
{
@@ -2581,7 +2582,7 @@ namespace System.Security.Cryptography.Asn1
Debug.Assert(!contents.IsEmpty);
byte octet = contents[0];
- Debug.Assert(state == GetNextState(octet));
+ Debug.Assert(state == ParseGeneralizedTime_GetNextState(octet));
if (octet == '.')
{
@@ -2639,7 +2640,7 @@ namespace System.Security.Cryptography.Asn1
if (contents.Length != 0)
{
- byte? nextState = GetNextState(contents[0]);
+ byte? nextState = ParseGeneralizedTime_GetNextState(contents[0]);
if (nextState == null)
{
@@ -2655,7 +2656,7 @@ namespace System.Security.Cryptography.Asn1
{
Debug.Assert(!contents.IsEmpty);
byte octet = contents[0];
- Debug.Assert(state == GetNextState(octet));
+ Debug.Assert(state == ParseGeneralizedTime_GetNextState(octet));
contents = contents.Slice(1);
if (octet == 'Z')
diff --git a/src/Common/src/System/Security/Cryptography/AsnWriter.cs b/src/Common/src/System/Security/Cryptography/AsnWriter.cs
index cff5cddab2..e6de600cb4 100644
--- a/src/Common/src/System/Security/Cryptography/AsnWriter.cs
+++ b/src/Common/src/System/Security/Cryptography/AsnWriter.cs
@@ -1194,7 +1194,11 @@ namespace System.Security.Cryptography.Asn1
// We're only loading in sub-second ticks.
// Ticks are defined as 1e-7 seconds, so their printed form
// is at the longest "0.1234567", or 9 bytes.
+#if __MonoCS__
+ fraction = new byte[9];
+#else
fraction = stackalloc byte[9];
+#endif
decimal decimalTicks = floatingTicks;
decimalTicks /= TimeSpan.TicksPerSecond;
@@ -1562,8 +1566,10 @@ namespace System.Security.Cryptography.Asn1
pos = 0;
- foreach ((int offset, int length) in positions)
+ foreach (var position in positions)
{
+ var offset = position.Item1;
+ var length = position.Item2;
Buffer.BlockCopy(buffer, offset, tmp, pos, length);
pos += length;
}
@@ -1612,8 +1618,10 @@ namespace System.Security.Cryptography.Asn1
public int Compare((int, int) x, (int, int) y)
{
- (int xOffset, int xLength) = x;
- (int yOffset, int yLength) = y;
+ int xOffset = x.Item1;
+ int xLength = x.Item2;
+ int yOffset = y.Item1;
+ int yLength = y.Item2;
int value =
SetOfValueComparer.Instance.Compare(
diff --git a/src/System.Security.Cryptography.Pkcs/src/Internal/Cryptography/Pal/AnyOS/ManagedPal.Asn.cs b/src/System.Security.Cryptography.Pkcs/src/Internal/Cryptography/Pal/AnyOS/ManagedPal.Asn.cs
index bd7463c3b1..046a114f96 100644
--- a/src/System.Security.Cryptography.Pkcs/src/Internal/Cryptography/Pal/AnyOS/ManagedPal.Asn.cs
+++ b/src/System.Security.Cryptography.Pkcs/src/Internal/Cryptography/Pal/AnyOS/ManagedPal.Asn.cs
@@ -33,7 +33,11 @@ namespace Internal.Cryptography.Pal.AnyOS
const int ArbitraryStackLimit = 256;
Span<byte> tmp = stackalloc byte[ArbitraryStackLimit];
// Use stackalloc 0 so data can later hold a slice of tmp.
+#if __MonoCS__
+ ReadOnlySpan<byte> data = new byte[0];
+#else
ReadOnlySpan<byte> data = stackalloc byte[0];
+#endif
byte[] poolBytes = null;
try