Skip to content

Commit 7e0fb31

Browse files
stevenawnormj
authored andcommitted
Minimize changes to the non-netcore31 path
1 parent 7d841bb commit 7e0fb31

File tree

4 files changed

+13
-10
lines changed

4 files changed

+13
-10
lines changed

sdk/src/Core/AWSSDK.Core.NetStandard.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,5 @@
7474

7575
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
7676
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="1.1.0" />
77-
<PackageReference Include="System.Buffers" Version="4.3.0" />
7877
</ItemGroup>
7978
</Project>

sdk/src/Core/Amazon.Util/CryptoUtil.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
using Amazon.Util.Internal;
1818
using AWSSDK.Runtime.Internal.Util;
1919
using System;
20+
#if NETCOREAPP3_1_OR_GREATER
2021
using System.Buffers;
22+
#endif
2123
using System.IO;
2224
using System.Security.Cryptography;
2325
using System.Text;
@@ -100,21 +102,26 @@ internal CryptoUtil()
100102
/// <returns>Computed hash code</returns>
101103
public string HMACSign(string data, string key, SigningAlgorithm algorithmName)
102104
{
105+
#if NETCOREAPP3_1_OR_GREATER
103106
Encoding encoding = Encoding.UTF8;
104107
int maxSize = encoding.GetMaxByteCount(data.Length);
105108
byte[] buffer = ArrayPool<byte>.Shared.Rent(maxSize);
106109

107110
try
108111
{
109112
int size = encoding.GetBytes(data, buffer);
110-
ArraySegment<byte> segment = new ArraySegment<byte>(buffer, 0, size);
113+
ArraySegment<byte> binaryData = new ArraySegment<byte>(buffer, 0, size);
111114

112-
return HMACSign(segment, key, algorithmName);
115+
return HMACSign(binaryData, key, algorithmName);
113116
}
114117
finally
115118
{
116119
ArrayPool<byte>.Shared.Return(buffer);
117120
}
121+
#else
122+
byte[] binaryData = Encoding.UTF8.GetBytes(data);
123+
return HMACSign(binaryData, key, algorithmName);
124+
#endif
118125
}
119126

120127
/// <summary>

sdk/src/Core/Amazon.Util/_netstandard/CryptoUtil.netstandard.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public byte[] HMACSignBinary(byte[] data, byte[] key, SigningAlgorithm algorithm
8080
}
8181
}
8282

83-
KeyedHashAlgorithm CreateKeyedHashAlgorithm(SigningAlgorithm algorithmName)
83+
static KeyedHashAlgorithm CreateKeyedHashAlgorithm(SigningAlgorithm algorithmName)
8484
{
8585
KeyedHashAlgorithm algorithm;
8686
switch (algorithmName)
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Globalization;
3-
using System.Text;
4+
using System.Linq;
5+
using System.Threading.Tasks;
46

57
namespace Amazon.Util
68
{
@@ -12,10 +14,5 @@ internal static string ToUpper(this String str, CultureInfo culture)
1214
throw new ArgumentException("The extension method ToUpper only works for invariant culture");
1315
return str.ToUpperInvariant();
1416
}
15-
16-
#if !NETCOREAPP3_1_OR_GREATER
17-
internal static int GetBytes(this Encoding encoding, string chars, byte[] bytes)
18-
=> encoding.GetBytes(chars, 0, chars.Length, bytes, 0);
19-
#endif
2017
}
2118
}

0 commit comments

Comments
 (0)