-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from nooperation/split_into_lib
Splitting project into a lib that can be exported by other projects
- Loading branch information
Showing
22 changed files
with
980 additions
and
331 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
#include "LibUserPreferences.h" | ||
|
||
#include "../UserPreferences.Shared/Common.h" | ||
#include "../UserPreferences.Shared/Encryption.h" | ||
|
||
DllExport APIResult DecryptData( | ||
_In_ const uint8_t *encrypted_buffer, | ||
_In_ size_t encrypted_buffer_size, | ||
_In_ const char *machine_guid, | ||
_In_ const char *salt_string, | ||
_Out_ uint8_t *out_decrypted_buffer, | ||
_Inout_ size_t *out_decrypted_buffer_size) | ||
{ | ||
if (encrypted_buffer == nullptr || out_decrypted_buffer_size == nullptr) | ||
{ | ||
return kResult_GeneralFailure; | ||
} | ||
|
||
std::string guid; | ||
if (machine_guid == nullptr) | ||
{ | ||
guid = UserPreferences::Common::GetMachineGuid(); | ||
} | ||
else | ||
{ | ||
guid = machine_guid; | ||
} | ||
|
||
std::string salt; | ||
if (salt_string == nullptr) | ||
{ | ||
salt = UserPreferences::Common::GetDefaultSalt(); | ||
} | ||
else | ||
{ | ||
salt = salt_string; | ||
} | ||
|
||
const auto encrypted = std::vector<uint8_t>(&encrypted_buffer[0], &encrypted_buffer[encrypted_buffer_size]); | ||
const auto decrypted = UserPreferences::Encryption::DecryptData(encrypted, guid, salt); | ||
|
||
if (out_decrypted_buffer == nullptr || *out_decrypted_buffer_size < decrypted.size()) | ||
{ | ||
*out_decrypted_buffer_size = decrypted.size(); | ||
return kResult_BufferTooSmall; | ||
} | ||
|
||
*out_decrypted_buffer_size = decrypted.size(); | ||
memcpy(out_decrypted_buffer, &decrypted[0], *out_decrypted_buffer_size); | ||
return kResult_GeneralSuccess; | ||
} | ||
|
||
DllExport APIResult EncryptData( | ||
_In_ const uint8_t *plaintext_data, | ||
_In_ size_t plaintext_data_size, | ||
_In_ const char *machine_guid, | ||
_In_ const char *salt_string, | ||
_Out_ uint8_t *out_encrypted_buffer, | ||
_Inout_ size_t *out_encrypted_buffer_size) | ||
{ | ||
if (plaintext_data == nullptr || out_encrypted_buffer_size == nullptr) | ||
{ | ||
return kResult_GeneralFailure; | ||
} | ||
|
||
std::string guid; | ||
if (machine_guid == nullptr) | ||
{ | ||
guid = UserPreferences::Common::GetMachineGuid(); | ||
} | ||
else | ||
{ | ||
guid = machine_guid; | ||
} | ||
|
||
std::string salt; | ||
if (salt_string == nullptr) | ||
{ | ||
salt = UserPreferences::Common::GetDefaultSalt(); | ||
} | ||
else | ||
{ | ||
salt = salt_string; | ||
} | ||
|
||
const auto plaintext = std::vector<uint8_t>(&plaintext_data[0], &plaintext_data[plaintext_data_size]); | ||
const auto encrypted = UserPreferences::Encryption::EncryptData(plaintext, guid, salt); | ||
|
||
if (out_encrypted_buffer == nullptr || *out_encrypted_buffer_size < encrypted.size()) | ||
{ | ||
*out_encrypted_buffer_size = encrypted.size(); | ||
return kResult_BufferTooSmall; | ||
} | ||
|
||
*out_encrypted_buffer_size = encrypted.size(); | ||
memcpy(out_encrypted_buffer, &encrypted[0], *out_encrypted_buffer_size); | ||
return kResult_GeneralSuccess; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#pragma once | ||
#define DllExport __declspec( dllexport ) | ||
|
||
#include <sal.h> | ||
#include <cstdint> | ||
|
||
extern "C" | ||
{ | ||
enum APIResult { | ||
kResult_GeneralSuccess = 0, | ||
kResult_GeneralFailure = -1, | ||
kResult_BufferTooSmall = -2 | ||
}; | ||
|
||
/// <summary> | ||
/// Decrypts encrypted data | ||
/// </summary> | ||
/// <param name="encrypted_buffer">Encrypted bytes buffer to decrypt</param> | ||
/// <param name="encrypted_buffer_size">Encrypted bytes buffer size in bytes</param> | ||
/// <param name="machine_guid">Optional machine GUID. Defaults to current machine GUID if not supplied.</param> | ||
/// <param name="salt_string">Optional salt. Defaults to last known salt if not supplied.</param> | ||
/// <param name="out_decrypted_buffer">Optional decrypted buffer</param> | ||
/// <param name="out_encrypted_buffer_size">Decrypted buffer size in bytes. Will be set to the required size if decrypted buffer is NULL. </param> | ||
/// <returns> | ||
/// kResult_GeneralSuccess on success. | ||
/// kResult_BufferTooSmall if decrypted buffer size is too small or decrypted buffer was not provided. | ||
/// kResult_GeneralFailure on failure. | ||
///</returns> | ||
DllExport APIResult DecryptData( | ||
_In_ const uint8_t *encrypted_buffer, | ||
_In_ size_t encrypted_buffer_size, | ||
_In_opt_ const char *machine_guid, | ||
_In_opt_ const char *salt_string, | ||
_Out_opt_ uint8_t *out_decrypted_buffer, | ||
_Inout_ size_t *out_decrypted_buffer_size | ||
); | ||
|
||
/// <summary> | ||
/// Encrypts data | ||
/// </summary> | ||
/// <param name="plaintext_data">Plaintext to enctypt</param> | ||
/// <param name="plaintext_data_size">Plaintext size in bytes</param> | ||
/// <param name="machine_guid">Optional machine GUID. Defaults to current machine GUID if not supplied.</param> | ||
/// <param name="salt_string">Optional salt. Defaults to last known salt if not supplied.</param> | ||
/// <param name="out_encrypted_buffer">Optional enctypted buffer</param> | ||
/// <param name="out_encrypted_buffer_size">Encrypted buffer size in bytes. Will be set to the required size if enctypted buffer is NULL. </param> | ||
/// <returns> | ||
/// kResult_GeneralSuccess on success. | ||
/// kResult_BufferTooSmall if encrypted buffer size is too small or encrypted buffer was not provided. | ||
/// kResult_GeneralFailure on failure. | ||
///</returns> | ||
DllExport APIResult EncryptData( | ||
_In_ const uint8_t *plaintext_data, | ||
_In_ size_t plaintext_data_size, | ||
_In_opt_ const char *machine_guid, | ||
_In_opt_ const char *salt_string, | ||
_Out_opt_ uint8_t *out_encrypted_buffer, | ||
_Inout_ size_t *out_encrypted_buffer_size | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<ItemGroup Label="ProjectConfigurations"> | ||
<ProjectConfiguration Include="Debug|Win32"> | ||
<Configuration>Debug</Configuration> | ||
<Platform>Win32</Platform> | ||
</ProjectConfiguration> | ||
<ProjectConfiguration Include="Release|Win32"> | ||
<Configuration>Release</Configuration> | ||
<Platform>Win32</Platform> | ||
</ProjectConfiguration> | ||
<ProjectConfiguration Include="Debug|x64"> | ||
<Configuration>Debug</Configuration> | ||
<Platform>x64</Platform> | ||
</ProjectConfiguration> | ||
<ProjectConfiguration Include="Release|x64"> | ||
<Configuration>Release</Configuration> | ||
<Platform>x64</Platform> | ||
</ProjectConfiguration> | ||
</ItemGroup> | ||
<PropertyGroup Label="Globals"> | ||
<VCProjectVersion>15.0</VCProjectVersion> | ||
<ProjectGuid>{E8A8F157-EBAE-43E4-90AE-32A8DAC51096}</ProjectGuid> | ||
<Keyword>Win32Proj</Keyword> | ||
<RootNamespace>LibUserPreferences</RootNamespace> | ||
<WindowsTargetPlatformVersion>10.0.16299.0</WindowsTargetPlatformVersion> | ||
</PropertyGroup> | ||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> | ||
<ConfigurationType>DynamicLibrary</ConfigurationType> | ||
<UseDebugLibraries>true</UseDebugLibraries> | ||
<PlatformToolset>v141</PlatformToolset> | ||
<CharacterSet>Unicode</CharacterSet> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> | ||
<ConfigurationType>DynamicLibrary</ConfigurationType> | ||
<UseDebugLibraries>false</UseDebugLibraries> | ||
<PlatformToolset>v141</PlatformToolset> | ||
<WholeProgramOptimization>true</WholeProgramOptimization> | ||
<CharacterSet>Unicode</CharacterSet> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> | ||
<ConfigurationType>DynamicLibrary</ConfigurationType> | ||
<UseDebugLibraries>true</UseDebugLibraries> | ||
<PlatformToolset>v141</PlatformToolset> | ||
<CharacterSet>Unicode</CharacterSet> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> | ||
<ConfigurationType>DynamicLibrary</ConfigurationType> | ||
<UseDebugLibraries>false</UseDebugLibraries> | ||
<PlatformToolset>v141</PlatformToolset> | ||
<WholeProgramOptimization>true</WholeProgramOptimization> | ||
<CharacterSet>Unicode</CharacterSet> | ||
</PropertyGroup> | ||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> | ||
<ImportGroup Label="ExtensionSettings"> | ||
</ImportGroup> | ||
<ImportGroup Label="Shared"> | ||
</ImportGroup> | ||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | ||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||
</ImportGroup> | ||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | ||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||
</ImportGroup> | ||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | ||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||
</ImportGroup> | ||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | ||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||
</ImportGroup> | ||
<PropertyGroup Label="UserMacros" /> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | ||
<LinkIncremental>true</LinkIncremental> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | ||
<LinkIncremental>true</LinkIncremental> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | ||
<LinkIncremental>false</LinkIncremental> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | ||
<LinkIncremental>false</LinkIncremental> | ||
</PropertyGroup> | ||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | ||
<ClCompile> | ||
<WarningLevel>Level3</WarningLevel> | ||
<Optimization>Disabled</Optimization> | ||
<SDLCheck>true</SDLCheck> | ||
<PreprocessorDefinitions>_DEBUG;LIBUSERPREFERENCES_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||
<ConformanceMode>true</ConformanceMode> | ||
</ClCompile> | ||
<Link> | ||
<GenerateDebugInformation>true</GenerateDebugInformation> | ||
<SubSystem>Windows</SubSystem> | ||
<AdditionalLibraryDirectories>$(OutputPath);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> | ||
</Link> | ||
</ItemDefinitionGroup> | ||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | ||
<ClCompile> | ||
<WarningLevel>Level3</WarningLevel> | ||
<Optimization>Disabled</Optimization> | ||
<SDLCheck>true</SDLCheck> | ||
<PreprocessorDefinitions>WIN32;_DEBUG;LIBUSERPREFERENCES_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||
<ConformanceMode>true</ConformanceMode> | ||
</ClCompile> | ||
<Link> | ||
<GenerateDebugInformation>true</GenerateDebugInformation> | ||
<SubSystem>Windows</SubSystem> | ||
<AdditionalLibraryDirectories>$(OutputPath);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> | ||
</Link> | ||
</ItemDefinitionGroup> | ||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | ||
<ClCompile> | ||
<WarningLevel>Level3</WarningLevel> | ||
<Optimization>MaxSpeed</Optimization> | ||
<FunctionLevelLinking>true</FunctionLevelLinking> | ||
<IntrinsicFunctions>true</IntrinsicFunctions> | ||
<SDLCheck>true</SDLCheck> | ||
<PreprocessorDefinitions>WIN32;NDEBUG;LIBUSERPREFERENCES_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||
<ConformanceMode>true</ConformanceMode> | ||
</ClCompile> | ||
<Link> | ||
<EnableCOMDATFolding>true</EnableCOMDATFolding> | ||
<OptimizeReferences>true</OptimizeReferences> | ||
<GenerateDebugInformation>true</GenerateDebugInformation> | ||
<SubSystem>Windows</SubSystem> | ||
<AdditionalLibraryDirectories>$(OutputPath);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> | ||
</Link> | ||
</ItemDefinitionGroup> | ||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | ||
<ClCompile> | ||
<WarningLevel>Level3</WarningLevel> | ||
<Optimization>MaxSpeed</Optimization> | ||
<FunctionLevelLinking>true</FunctionLevelLinking> | ||
<IntrinsicFunctions>true</IntrinsicFunctions> | ||
<SDLCheck>true</SDLCheck> | ||
<PreprocessorDefinitions>NDEBUG;LIBUSERPREFERENCES_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||
<ConformanceMode>true</ConformanceMode> | ||
</ClCompile> | ||
<Link> | ||
<EnableCOMDATFolding>true</EnableCOMDATFolding> | ||
<OptimizeReferences>true</OptimizeReferences> | ||
<GenerateDebugInformation>true</GenerateDebugInformation> | ||
<SubSystem>Windows</SubSystem> | ||
<AdditionalLibraryDirectories>$(OutputPath);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> | ||
</Link> | ||
</ItemDefinitionGroup> | ||
<ItemGroup> | ||
<ClInclude Include="LibUserPreferences.h" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ClCompile Include="LibUserPreferences.cpp" /> | ||
</ItemGroup> | ||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> | ||
<ImportGroup Label="ExtensionTargets"> | ||
</ImportGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<ItemGroup> | ||
<Filter Include="Source Files"> | ||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier> | ||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions> | ||
</Filter> | ||
<Filter Include="Header Files"> | ||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier> | ||
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions> | ||
</Filter> | ||
<Filter Include="Resource Files"> | ||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier> | ||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions> | ||
</Filter> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ClInclude Include="LibUserPreferences.h"> | ||
<Filter>Header Files</Filter> | ||
</ClInclude> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ClCompile Include="LibUserPreferences.cpp"> | ||
<Filter>Source Files</Filter> | ||
</ClCompile> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.