SignHere 0.3.2

dotnet add package SignHere --version 0.3.2                
NuGet\Install-Package SignHere -Version 0.3.2                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SignHere" Version="0.3.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SignHere --version 0.3.2                
#r "nuget: SignHere, 0.3.2"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install SignHere as a Cake Addin
#addin nuget:?package=SignHere&version=0.3.2

// Install SignHere as a Cake Tool
#tool nuget:?package=SignHere&version=0.3.2                

SignHere

build License: MIT NuGet Badge

An implementation of file signature validation as documented in ASP.NET Core file upload document. This library can validate signatures of 518 different file types, all taken from https://filesignatures.net/, as the document suggests.

Usage

There are two main ways to use this library:

  1. SignHere.FindSignature() method

    var stream = new MemoryStream(new byte[] { 0xFF, 0xD8, 0xFF, 0xE2, 0xB7, }); // "CANNON EOS JPEG FILE"
    var signature = SignHere.FindSignature(stream);
    
    // Comes out as:
    // signature.Extension = Extension.JPEG,
    // signature.MagicBytes = new byte[] { 0xFF, 0xD8, 0xFF, 0xE2 },
    // signature.Description = "CANNON EOS JPEG FILE"
    
  2. .Is() extension method

    • stream.Is() extension: Works with any Stream object. Expects the stream content to be an byte[]. There are three different overloads to go with, all of them also have IEnumerable variants too:
      • stream.Is(Extension): Checks by Extension enum.
        var stream = new MemoryStream(new byte[] { 0xFF, 0xD8, 0xFF, 0xE2, 0xB7, })
        var isJPEG = stream.Is(Extension.JPEG); // true
        
      • stream.Is(Category): Checks by Category. A Category is a predefined constant string which is checked against Signature.Description.
        var stream = new MemoryStream(new byte[] { 0x9C, 0xCB, 0xCB, 0x8D, 0x13, 0x75, 0xD2, 0x11 })
        var whitelistedCategoryies = new List<Category>() { Category.Video, Category.Audio };
        var isVideoOrAudio = stream.Is(whitelistedCategoryies); // false
        
      • stream.Is(string): Checks by string. Matches if Signature.Description contains it.
        var stream = new MemoryStream(new byte[] { 0xE3, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00 })
        var isAmigaFile = stream.Is("Amiga"); // true
        

    There are also Is() overloads that works with IFormFile and take Extension(s), Category(s) or string(s) as parameters.

Notes

  • Files with no extension are represented as Extension.None.
  • Extensions starting with a number are escaped with an underscore (_) in Extension enum, since an enum member cannot start with a number. (eg. Extension 3GP is represented as Extension._3GP)
  • Category relies on definition field in filesignatures.net (example, JPEG extension). Until all extensions are processed and categorised manually, validating with this type might be deceiving. Category.Video will only filter the extensions with the word "video" in their descriptions.

TODO

  • Performance improvements
  • Include other file signature databases
  • Support for File type if requested
  • Manual assigning of Categories
  • More tests
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.3.2 612 5/10/2022
0.3.2-alpha 180 5/9/2022

- init