AuroraRuntime/Source/Compression/Compression.hpp
Reece Wilson 8844e8fe64 [+] AuCrypto::BCrypt
> GetForcedMinRounds
> GenSalt
> HashPW
> HashPWEx
> CheckPassword
> CheckPasswordEx
[*] Refactor AuCompression APIs
[*] Clean up AuTryConstructs
[+] Internal compression API for compression based interceptors
[+] Root-level input stream arg check for all compression apis (harden)
[*] Clean up AuCompression code
[+] Solar Designer / OpenWall blowfish crypt
[*] BlowCrypt: accept length input parameter
[*] Split locale into 2 source files
[-] Ugly comment from Open.Win32.cpp. TODO: Readd later. Might warn on empty string bc it makes sense given, "." and "/" normalizes to nothing, and memory pre-idc-if-drops are dropped siliently.
2022-09-15 20:48:50 +01:00

100 lines
2.1 KiB
C++

/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: Compression.hpp
Date: 2021-6-17
Author: Reece
***/
#pragma once
namespace Aurora::Compression
{
static const AuUInt64 kChunkSize = 32 * 1024;
/// * compression type + bits -> internal zlib windowBits
static bool CompressionLevelFromExternalApi(const DecompressInfo &info, AuInt8 &out)
{
out = 0;
if (!info.bHasWindowbits)
{
if (info.alg == ECompressionType::eGZip)
{
out = 15 | 16;
}
else if (info.alg == ECompressionType::eDeflate)
{
out = -15;
}
else
{
out = 15;
return true;
}
}
if (info.uWindowBits < 0)
{
return {};
}
if (info.uWindowBits > 15)
{
return {};
}
if (info.alg == ECompressionType::eGZip)
{
out = info.uWindowBits | 16;
}
else if (info.alg == ECompressionType::eDeflate)
{
out = 0 - info.uWindowBits;
}
else
{
out = info.uWindowBits;
}
return true;
}
/// * compression type + bits -> internal zlib windowBits
static bool CompressionLevelFromExternalApi(const CompressInfo &info, AuInt8 &out)
{
out = 0;
if (!info.uWindowBits)
{
if (info.type == ECompressionType::eGZip)
{
out = 15 | 16;
}
else if (info.type == ECompressionType::eDeflate)
{
out = -15;
}
else
{
out = 15;
return true;
}
}
if (info.type == ECompressionType::eGZip)
{
out = info.uWindowBits | 16;
}
else if (info.type == ECompressionType::eDeflate)
{
out = 0 - info.uWindowBits;
}
else
{
out = info.uWindowBits;
}
return true;
}
}