Skip to content

Commit

Permalink
feat: support for unity game engine (FantasticFiasco#477)
Browse files Browse the repository at this point in the history
  • Loading branch information
FantasticFiasco authored Aug 29, 2021
1 parent 85fd9a4 commit d798ad5
Show file tree
Hide file tree
Showing 9 changed files with 600 additions and 14 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ This project adheres to [Semantic Versioning](http://semver.org/) and is followi

## Unreleased

### :zap: Added

- [#476](https://github.com/FantasticFiasco/aws-signature-version-4/issues/476) Support for [Unity](https://unity.com/) game engine

## [2.0.0] - 2021-08-01

### :zap: Added
Expand Down
3 changes: 2 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup>
<VersionPrefix>2.0.0</VersionPrefix>
<VersionPrefix>2.1.0</VersionPrefix>
<VersionSuffix>beta.1</VersionSuffix>
<!--
Only increment the assembly version on major version changes to help users reduce binding
redirects, and how often they're updated. For more information, please read
Expand Down
35 changes: 28 additions & 7 deletions build/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,35 @@ Print "info" "is pull request: $is_pull_request"
# -------------------------------------------------------------------------------------------------
Print "build" "build started"
Print "build" "dotnet cli v$(dotnet --version)"
$version_suffix_arg = If ($is_tagged_build -eq $true) { "" } Else { "--version-suffix=sha-$git_sha" }

dotnet build -c Release $version_suffix_arg
AssertLastExitCode
[xml]$build_props = Get-Content -Path .\Directory.Build.props
$version_prefix = $build_props.Project.PropertyGroup.VersionPrefix
Print "info" "build props version prefix: $version_prefix"
$version_suffix = $build_props.Project.PropertyGroup.VersionSuffix
Print "info" "build props version suffix: $version_suffix"

dotnet pack -c Release -o ./artifacts --no-build $version_suffix_arg
AssertLastExitCode
if ($is_tagged_build) {
Print "build" "build"
dotnet build -c Release
AssertLastExitCode

Print "build" "pack"
dotnet pack -c Release -o .\artifacts --no-build
AssertLastExitCode
} else {
# Use git tag if version suffix isn't specified
if ($version_suffix -eq "") {
$version_suffix = $git_sha
}

Print "build" "build"
dotnet build -c Release --version-suffix=$version_suffix
AssertLastExitCode

Print "build" "pack"
dotnet pack -c Release -o .\artifacts --version-suffix=$version_suffix --no-build
AssertLastExitCode
}

# -------------------------------------------------------------------------------------------------
# TEST
Expand All @@ -59,8 +81,7 @@ if ($is_pull_request -eq $true) {
# secrets, which are omitted by AppVeyor on pull requests.
dotnet test -c Release --no-build --filter Category!=Integration
AssertLastExitCode
}
else {
} else {
dotnet test -c Release --no-build --collect:"XPlat Code Coverage"
AssertLastExitCode

Expand Down
13 changes: 7 additions & 6 deletions src/AwsSignatureVersion4.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,20 @@
<PackageReference Include="AWSSDK.Core" Version="3.3.101.9" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net45' Or '$(TargetFramework)' == 'net461'">
<ItemGroup>
<None Include="assets\aws-signature-version-4.png" Pack="true" PackagePath="" />
</ItemGroup>

<!-- .NET 4.5 -->

<ItemGroup Condition="'$(TargetFramework)' == 'net45'">
<Reference Include="System" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Web" />
<Reference Include="Microsoft.CSharp" />

<PackageReference Include="System.ValueTuple" Version="4.5.0" />
</ItemGroup>

<ItemGroup>
<None Include="assets\aws-signature-version-4.png" Pack="true" PackagePath=""/>
</ItemGroup>

<!-- SourceLink -->

<PropertyGroup>
Expand Down
162 changes: 162 additions & 0 deletions src/Private/System/Web/HttpUtility.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

// Authors:
// Patrik Torstensson (Patrik.Torstensson@labs2.com)
// Wictor Wilén (decode/encode functions) (wictor@ibizkit.se)
// Tim Coleman (tim@timcoleman.com)
// Gonzalo Paniagua Javier (gonzalo@ximian.com)
//
// Copyright (C) 2005-2010 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

#if NET45
#pragma warning disable IDE0007 // Use implicit type

using System.Collections.Specialized;
using System.Text;
using System.Web.Util;

// ReSharper disable once CheckNamespace
namespace System.Web
{
internal sealed class HttpUtility
{
private sealed class HttpQSCollection : NameValueCollection
{
internal HttpQSCollection()
: base(StringComparer.OrdinalIgnoreCase)
{
}

public override string ToString()
{
int count = Count;
if (count == 0)
{
return "";
}

StringBuilder sb = new StringBuilder();
string?[] keys = AllKeys;
for (int i = 0; i < count; i++)
{
string[]? values = GetValues(keys[i]);
if (values != null)
{
foreach (string value in values)
{
if (string.IsNullOrEmpty(keys[i]))
{
sb.AppendFormat("{0}&", UrlEncode(value));
}
else
{
sb.AppendFormat("{0}={1}&", keys[i], UrlEncode(value));
}
}
}
}

return sb.ToString(0, sb.Length - 1);
}
}

public static NameValueCollection ParseQueryString(string query) => ParseQueryString(query, Encoding.UTF8);

public static NameValueCollection ParseQueryString(string query, Encoding encoding)
{
if (query == null)
{
throw new ArgumentNullException(nameof(query));
}

if (encoding == null)
{
throw new ArgumentNullException(nameof(encoding));
}

HttpQSCollection result = new HttpQSCollection();
int queryLength = query.Length;
int namePos = queryLength > 0 && query[0] == '?' ? 1 : 0;
if (queryLength == namePos)
{
return result;
}

while (namePos <= queryLength)
{
int valuePos = -1, valueEnd = -1;
for (int q = namePos; q < queryLength; q++)
{
if (valuePos == -1 && query[q] == '=')
{
valuePos = q + 1;
}
else if (query[q] == '&')
{
valueEnd = q;
break;
}
}

string? name;
if (valuePos == -1)
{
name = null;
valuePos = namePos;
}
else
{
name = UrlDecode(query.Substring(namePos, valuePos - namePos - 1), encoding);
}

if (valueEnd < 0)
{
valueEnd = query.Length;
}

namePos = valueEnd + 1;
string value = UrlDecode(query.Substring(valuePos, valueEnd - valuePos), encoding);
result.Add(name, value);
}

return result;
}

public static string UrlEncode(string str) => UrlEncode(str, Encoding.UTF8);

public static string UrlEncode(string str, Encoding e) => Encoding.ASCII.GetString(UrlEncodeToBytes(str, e));

public static byte[]? UrlEncodeToBytes(string str, Encoding e)
{
byte[] bytes = e.GetBytes(str);
return HttpEncoder.UrlEncode(bytes, 0, bytes.Length, alwaysCreateNewReturnValue: false);
}

public static string UrlDecode(string str, Encoding e) => HttpEncoder.UrlDecode(str, e);
}
}

#pragma warning restore IDE0007 // Use implicit type
#endif
5 changes: 5 additions & 0 deletions src/Private/System/Web/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# System.Web

The following files have been copied from [corefx on GitHub](https://github.com/dotnet/corefx/tree/master/src/System.Web.HttpUtility), because the package `System.Web` is not supported on .NET 4.5 on the Unity game engine.

For more information, see [#476](https://github.com/FantasticFiasco/aws-signature-version-4/issues/476).
Loading

0 comments on commit d798ad5

Please sign in to comment.