Skip to content

Commit

Permalink
Initial version
Browse files Browse the repository at this point in the history
  • Loading branch information
josesimoes committed Oct 27, 2023
1 parent a828dd3 commit 0957209
Show file tree
Hide file tree
Showing 27 changed files with 741 additions and 12 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/pr-checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright (c) .NET Foundation and Contributors
# See LICENSE file in the project root for full license information.

name: PR Checks

on:
pull_request:

jobs:
check_package_lock:
name: nanoFramework
uses: nanoframework/nf-tools/.github/workflows/check-package-lock.yml@main
check_nuget_latest:
name: nanoFramework
uses: nanoframework/nf-tools/.github/workflows/check-packages-updated.yml@main
secrets: inherit
with:
solution: 'nanoFramework.System.IO.Hashing.sln'
21 changes: 21 additions & 0 deletions .github/workflows/update-dependencies.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright (c) .NET Foundation and Contributors
# See LICENSE file in the project root for full license information.

# This workflow will periodically check .NET nanoFramework dependencies and updates them in the repository it's running.

name: Daily update dependencies

on:
schedule:
# At 00:10 UTC.
- cron: '00 10 * * Mon,Thu'
repository_dispatch:
types: update-dependencies

jobs:
update-dependencies:
name: nanoFramework
uses: nanoframework/nf-tools/.github/workflows/update-dependencies.yml@main
secrets: inherit
with:
solutionsToCheck: 'nanoFramework.System.IO.Hashing.sln'
13 changes: 13 additions & 0 deletions .github_changelog_generator
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
user=nanoframework
project=nanoFramework.System.IO.Hashing
issues=true
add_issues_wo_labels=false
add_pr_wo_labels=false
add_issues_wo_labels=false
filter_issues_by_milestone=false
exclude_labels=Area: Config-and-Build,Area: Infrastructure-and-Organization,reverted
enhancement_labels=Type: enhancement
bug_labels=Type: bug
merge_prefix=**Documentation and other chores:**
unreleased_label=**Changes available only in 'Preview' NuGet packages:**
author=false
17 changes: 17 additions & 0 deletions .runsettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
<!-- Configurations that affect the Test Framework -->
<RunConfiguration>
<ResultsDirectory>.\TestResults</ResultsDirectory><!-- Path relative to solution directory -->
<TestSessionTimeout>120000</TestSessionTimeout><!-- Milliseconds -->
<TargetFrameworkVersion>net48</TargetFrameworkVersion>
<TargetPlatform>x64</TargetPlatform>
</RunConfiguration>
<nanoFrameworkAdapter>
<Logging>None</Logging> <!--Set to the desired level of logging for Unit Test execution. Possible values are: None, Detailed, Verbose, Error. -->
<IsRealHardware>True</IsRealHardware><!--Set to true to run tests on real hardware. -->
<RealHardwarePort>COM15</RealHardwarePort><!--Specify the COM port to use to connect to a nanoDevice. If none is specified, a device detection is performed and the 1st available one will be used. -->
<CLRVersion></CLRVersion><!--Specify the nanoCLR version to use. If not specified, the latest available will be used. -->
<PathToLocalCLRInstance></PathToLocalCLRInstance><!--Specify the path to a local nanoCLR instance. If not specified, the default one installed with nanoclr CLR witll be used. -->
</nanoFrameworkAdapter>
</RunSettings>
Empty file added CHANGELOG.md
Empty file.
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) .NET Foundation and Contributors

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.
7 changes: 7 additions & 0 deletions NuGet.Config
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="NuGet" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="Azure Artifacts nanoFramework dev" value="https://pkgs.dev.azure.com/nanoframework/feed/_packaging/sandbox/nuget/v3/index.json" protocolVersion="3" />
</packageSources>
</configuration>
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=nanoframework_System.IO.Hashing&metric=alert_status)](https://sonarcloud.io/dashboard?id=nanoframework_System.IO.Hashing) [![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=nanoframework_System.IO.Hashing&metric=reliability_rating)](https://sonarcloud.io/dashboard?id=nanoframework_System.IO.Hashing) [![NuGet](https://img.shields.io/nuget/dt/nanoFramework.System.IO.Hashing.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.System.IO.Hashing/) [![#yourfirstpr](https://img.shields.io/badge/first--timers--only-friendly-blue.svg)](https://github.com/nanoframework/Home/blob/main/CONTRIBUTING.md) [![Discord](https://img.shields.io/discord/478725473862549535.svg?logo=discord&logoColor=white&label=Discord&color=7289DA)](https://discord.gg/gCyBu8T)

![nanoFramework logo](https://raw.githubusercontent.com/nanoframework/Home/main/resources/logo/nanoFramework-repo-logo.png)

-----

### Welcome to the .NET **nanoFramework** System.IO.Hashing Library repository

This repository contains the nanoFramework System.IO.Hashing class library.

## Build status

| Component | Build Status | NuGet Package |
|:-|---|---|
| System.IO.Hashing | [![Build Status](https://dev.azure.com/nanoframework/System.IO.Hashing/_apis/build/status%2Fnanoframework.System.IO.Hashing?branchName=main)](https://dev.azure.com/nanoframework/System.IO.Hashing/_build/latest?definitionId=102&branchName=main) | [![NuGet](https://img.shields.io/nuget/v/nanoFramework.System.IO.Hashing.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.System.IO.Hashing/) |

## System.IO.Hashing usage

## Feedback and documentation

For documentation, providing feedback, issues and finding out how to contribute please refer to the [Home repo](https://github.com/nanoframework/Home).

Join our Discord community [here](https://discord.gg/gCyBu8T).

## Credits

The list of contributors to this project can be found at [CONTRIBUTORS](https://github.com/nanoframework/Home/blob/main/CONTRIBUTORS.md).

## License

The **nanoFramework** Class Libraries are licensed under the [MIT license](LICENSE.md).

## Code of Conduct

This project has adopted the code of conduct defined by the Contributor Covenant to clarify expected behaviour in our community.
For more information see the [.NET Foundation Code of Conduct](https://dotnetfoundation.org/code-of-conduct).

### .NET Foundation

This project is supported by the [.NET Foundation](https://dotnetfoundation.org).
100 changes: 100 additions & 0 deletions System.IO.Hashing/Crc32.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
//
// Copyright (c) .NET Foundation and Contributors
// Portions Copyright (c) Microsoft Corporation. All rights reserved.
// See LICENSE file in the project root for full license information.
//

using System.Runtime.CompilerServices;

namespace System.IO.Hashing
{
/// <summary>
/// Provides an implementation of the CRC-32 algorithm, as used in
/// ITU-T V.42 and IEEE 802.3.
/// </summary>
/// <remarks>
/// <para>
/// If the platform or target doesn't support Hardware Crc32 computation it will offer a software implementation.
/// </para>
/// <para>
/// For methods that return byte arrays or that write into spans of bytes, this implementation
/// emits the answer in the Little Endian byte order so that the CRC residue relationship
/// (CRC(message concat CRC(message))) is a fixed value) holds.
/// For CRC-32 this stable output is the byte sequence <c>{ 0x1C, 0xDF, 0x44, 0x21 }</c>,
/// the Little Endian representation of <c>0x2144DF1C</c>.
/// </para>
/// <para>
/// There are multiple, incompatible, definitions of a 32-bit cyclic redundancy
/// check (CRC) algorithm. When interoperating with another system, ensure that you
/// are using the same definition. The definition used by this implementation is not
/// compatible with the cyclic redundancy check described in ITU-T I.363.5.
/// </para>
/// </remarks>
public class Crc32
{
private const uint InitialState = 0xFFFF_FFFF;
private uint _crc = InitialState;

/// <summary>
/// Initializes a new instance of the <see cref="Crc32"/> class.
/// </summary>
public Crc32()
{
}

/// <summary>
/// Appends the contents of <paramref name="source"/> to the data already processed for the current hash computation.
/// </summary>
/// <param name="source">The data to process.</param>
public void Append(SpanByte source)
{
_crc = ComputeHash(
_crc,
source);
}

/// <summary>
/// Appends the contents of <paramref name="source"/> to the data already processed for the current hash computation.
/// </summary>
/// <param name="source">The data to process.</param>
public void Append(byte[] source)
{
_crc = ComputeHash(
_crc,
new SpanByte(source));
}

/// <summary>
/// Appends <paramref name="value"/> to the data already processed for the current hash computation.
/// </summary>
/// <param name="value">The <see langword="byte"/> to process.</param>
public void Append(byte value)
{
_crc = ComputeHash(
_crc,
new byte[] { value });
}

/// <summary>
/// Resets the hash computation to the initial state.
/// </summary>
public void Reset()
{
_crc = InitialState;
}

/// <summary>Gets the current computed hash value without modifying accumulated state.</summary>
/// <returns>The hash value for the data already provided.</returns>
public uint GetCurrentHashAsUInt32() => _crc ^ InitialState;

/// <summary>Computes the CRC-32 hash of the provided data.</summary>
/// <param name="source">The data to hash.</param>
/// <returns>The computed CRC-32 hash.</returns>
public static uint HashToUInt32(SpanByte source) => ComputeHash(InitialState, source) ^ InitialState;

[MethodImpl(MethodImplOptions.InternalCall)]
extern private static uint ComputeHash(
uint crc,
SpanByte source);
}
}
22 changes: 22 additions & 0 deletions System.IO.Hashing/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("nanoFramework.System.IO.Hashing")]
[assembly: AssemblyCompany("nanoFramework Contributors")]
[assembly: AssemblyProduct("nanoFramework.System.IO.Hashing")]
[assembly: AssemblyCopyright("Copyright (c) .NET Foundation and Contributors")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

/////////////////////////////////////////////////////////////////
// This attribute is mandatory when building Interop libraries //
// update this whenever the native assembly signature changes //
[assembly: AssemblyNativeVersion("100.0.0.1")]
/////////////////////////////////////////////////////////////////
72 changes: 72 additions & 0 deletions System.IO.Hashing/System.IO.Hashing.nfproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\Nerdbank.GitVersioning.3.6.133\build\Nerdbank.GitVersioning.props" Condition="Exists('..\packages\Nerdbank.GitVersioning.3.6.133\build\Nerdbank.GitVersioning.props')" />
<PropertyGroup Label="Globals">
<NanoFrameworkProjectSystemPath>$(MSBuildExtensionsPath)\nanoFramework\v1.0\</NanoFrameworkProjectSystemPath>
</PropertyGroup>
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.Default.props" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.Default.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectTypeGuids>{11A8DD76-328B-46DF-9F39-F559912D0360};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<ProjectGuid>a05ef804-3fb8-42d1-8e0a-4d0002502755</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<FileAlignment>512</FileAlignment>
<RootNamespace>System.IO.Hashing</RootNamespace>
<AssemblyName>nanoFramework.System.IO.Hashing</AssemblyName>
<TargetFrameworkVersion>v1.0</TargetFrameworkVersion>
<NF_IsCoreLibrary>True</NF_IsCoreLibrary>
<DocumentationFile>bin\$(Configuration)\nanoFramework.System.IO.Hashing.xml</DocumentationFile>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
<RestoreLockedMode Condition="'$(TF_BUILD)' == 'True' or '$(ContinuousIntegrationBuild)' == 'True'">true</RestoreLockedMode>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>true</SignAssembly>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>..\key.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<PropertyGroup>
<DelaySign>false</DelaySign>
</PropertyGroup>
<PropertyGroup>
<!-- override default options for MetaDataProcessor -->
<NF_GenerateStubsDirectory>bin\$(Configuration)\Stubs</NF_GenerateStubsDirectory>
<NF_GenerateSkeletonProjectName>nf_sys_io_hashing</NF_GenerateSkeletonProjectName>
<Name>nanoFramework.System.IO.Hashing</Name>
</PropertyGroup>
<ItemGroup>
<NFMDP_PE_ExcludeClassByName Include="ThisAssembly">
<InProject>false</InProject>
</NFMDP_PE_ExcludeClassByName>
</ItemGroup>
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.props" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.props')" />
<ItemGroup>
<Compile Include="Crc32.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="mscorlib">
<HintPath>..\packages\nanoFramework.CoreLibrary.1.14.2\lib\mscorlib.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<None Include="..\key.snk" Link="key.snk" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.CSharp.targets" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.CSharp.targets')" />
<ProjectExtensions>
<ProjectCapabilities>
<ProjectConfigurationsDeclaredAsItems />
</ProjectCapabilities>
</ProjectExtensions>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105.The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Nerdbank.GitVersioning.3.6.133\build\Nerdbank.GitVersioning.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Nerdbank.GitVersioning.3.6.133\build\Nerdbank.GitVersioning.props'))" />
<Error Condition="!Exists('..\packages\Nerdbank.GitVersioning.3.6.133\build\Nerdbank.GitVersioning.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Nerdbank.GitVersioning.3.6.133\build\Nerdbank.GitVersioning.targets'))" />
</Target>
<Import Project="..\packages\Nerdbank.GitVersioning.3.6.133\build\Nerdbank.GitVersioning.targets" Condition="Exists('..\packages\Nerdbank.GitVersioning.3.6.133\build\Nerdbank.GitVersioning.targets')" />
</Project>
5 changes: 5 additions & 0 deletions System.IO.Hashing/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="nanoFramework.CoreLibrary" version="1.14.2" targetFramework="netnano1.0" />
<package id="Nerdbank.GitVersioning" version="3.6.133" developmentDependency="true" targetFramework="netnano1.0" />
</packages>
19 changes: 19 additions & 0 deletions System.IO.Hashing/packages.lock.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"version": 1,
"dependencies": {
".NETnanoFramework,Version=v1.0": {
"nanoFramework.CoreLibrary": {
"type": "Direct",
"requested": "[1.14.2, 1.14.2]",
"resolved": "1.14.2",
"contentHash": "j1mrz4mitl5LItvmHMsw1aHzCAfvTTgIkRxA0mhs5mSpctJ/BBcuNwua5j3MspfRNKreCQPy/qZy/D9ADLL/PA=="
},
"Nerdbank.GitVersioning": {
"type": "Direct",
"requested": "[3.6.133, 3.6.133]",
"resolved": "3.6.133",
"contentHash": "VZWMd5YAeDxpjWjAP/X6bAxnRMiEf6tES/ITN0X5CHJgkWLLeHGmEALivmTAfYM6P+P/3Szy6VCITUAkqjcHVw=="
}
}
}
}
Loading

0 comments on commit 0957209

Please sign in to comment.