Woof.Settings.Protected 6.2.0

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package Woof.Settings.Protected --version 6.2.0                
NuGet\Install-Package Woof.Settings.Protected -Version 6.2.0                
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="Woof.Settings.Protected" Version="6.2.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Woof.Settings.Protected --version 6.2.0                
#r "nuget: Woof.Settings.Protected, 6.2.0"                
#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 Woof.Settings.Protected as a Cake Addin
#addin nuget:?package=Woof.Settings.Protected&version=6.2.0

// Install Woof.Settings.Protected as a Cake Tool
#tool nuget:?package=Woof.Settings.Protected&version=6.2.0                

Woof.Settings.Protected

A part of the Woof Tookit by CodeDog.

Distributed under MIT License. (c)2022 by CodeDog, All rights reserved.


About

The package adds a data protection to the Woof.Settings settings files. The JsonSettingsProtected class has one additional method - Protect(). When it's called the settings file gets encrypted and the file is only readable to the user who first executed the application, or for all users on the same computer. The original, unencrypted settings file is deleeted.

If the settings is already protected - call to Protect() is ignored.

To use this package on Linux additional dependency of Woof.DataProtection.Linux is required.

Also, using DataProtectionScope.LocalMachine on Linux requires root permissions.

In order for the protection to work, the settings directory must be writeable to the user. If the user doesn't have write permission to the settings directory or the original file can't be deleted, the Protect() call will throw UnauthorizedAccessException.

Usage

To create singleton (configured for the current user):

class Settings : JsonSettingsProtected<Settings> {

    public static Settings Default { get; } = new();

    private Settings() : JsonSettingsProtected(DataProtectionScope.CurrentUser) { }

    // Settings properties go here...

}

To load and protect the settings:

Settings.Default.Load().Protect();

or

await (await Settings.Default.LoadAsync()).ProtectAsync();

Chaining the asynchronous methods looks not great, but still works.

As for the main JsonSettings module, it will not throw when the settings file doesn't exist. The properties would just have their default values.

It is the user's code responsibility either to provide sane defaults or just test whether they are set with the settings file.

For more details use the XML documentation, read the documentation for the Woof.DataProtection, Woof.DataProtectionLinux packages, check the package source code, tests and examples.


Disclaimer

Woof Toolkit is a work in progress in constant development, however it's carefully maintained with production code quality.

PLEASE report all issues on GitHub!

Describe how to reproduce an issue. Also feel free to suggest new features or improvements.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Woof.Settings.Protected:

Package Downloads
Woof.Settings.AKV

Provides application settings in a JSON file with Azure Key Vault secrets access.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
7.0.0 218 8/6/2023
6.2.0 309 2/20/2022

Woof Toolkit 6.2 first release.