[*] Begin truncating mapped types

This commit is contained in:
Reece Wilson 2022-01-20 16:37:22 +00:00
parent 02aa0dfd13
commit 81bfa7fba6
19 changed files with 74 additions and 74 deletions

View File

@ -219,7 +219,7 @@ namespace Aurora::Compression
while (read < input)
{
AuUInt request = AuMin(input, AuUInt32(AuArraySize(din_)));
if (this->reader_->Read(Memory::MemoryViewStreamWrite(din_, request)) != IO::EStreamError::eErrorNone)
if (this->reader_->Read(AuMemoryViewStreamWrite(din_, request)) != IO::EStreamError::eErrorNone)
{
return AuMakePair(read, done);
}
@ -309,7 +309,7 @@ namespace Aurora::Compression
while (read < input)
{
AuUInt request = AuMin(input, AuUInt32(AuArraySize(din_)));
if (this->reader_->Read(Memory::MemoryViewStreamWrite(din_, request)) != IO::EStreamError::eErrorNone)
if (this->reader_->Read(AuMemoryViewStreamWrite(din_, request)) != IO::EStreamError::eErrorNone)
{
return AuMakePair(read, done);
}
@ -413,7 +413,7 @@ namespace Aurora::Compression
{
AuUInt request = frameSize;
if ((input < (inputStat + request)) ||
(this->reader_->Read(Memory::MemoryViewStreamWrite(bufferIn.get(), request)) != IO::EStreamError::eErrorNone) ||
(this->reader_->Read(AuMemoryViewStreamWrite(bufferIn.get(), request)) != IO::EStreamError::eErrorNone) ||
(request != frameSize))
{
ret = request == 0 && inputStat;

View File

@ -29,12 +29,12 @@ namespace Aurora::Compression
return true;
}
AUKN_SYM bool Compress(const Memory::ByteBuffer &in, Memory::ByteBuffer &out, int compressionLevel)
AUKN_SYM bool Compress(const Memory::ByteBuffer &in, AuByteBuffer &out, int compressionLevel)
{
return Compress(in.data(), in.size(), out, compressionLevel);
}
AUKN_SYM bool Decompress(const void *buffer, AuUInt32 length, Memory::ByteBuffer &out)
AUKN_SYM bool Decompress(const void *buffer, AuUInt32 length, AuByteBuffer &out)
{
AuUInt32 read = 0;
@ -80,7 +80,7 @@ namespace Aurora::Compression
return true;
}
AUKN_SYM bool Decompress(const Memory::ByteBuffer &in, Memory::ByteBuffer &out)
AUKN_SYM bool Decompress(const AuByteBuffer &in, AuByteBuffer &out)
{
return Decompress(in.data(), in.size(), out);
}

View File

@ -139,11 +139,11 @@ namespace Aurora::Crypto::AES
return true;
}
AUKN_SYM bool Encrypt(const Memory::MemoryViewRead &plainText,
const Memory::MemoryViewRead &inIv,
const Memory::MemoryViewWrite & outIv,
const Memory::MemoryViewRead &inKey,
Memory::ByteBuffer &out,
AUKN_SYM bool Encrypt(const AuMemoryViewRead &plainText,
const AuMemoryViewRead &inIv,
const AuMemoryViewWrite & outIv,
const AuMemoryViewRead &inKey,
AuByteBuffer &out,
bool auCoolCodePadding)
{
symmetric_CBC cbc;
@ -254,11 +254,11 @@ namespace Aurora::Crypto::AES
}
AUKN_SYM bool Decrypt(const Memory::MemoryViewRead &cipherText,
const Memory::MemoryViewRead &inIv,
const Memory::MemoryViewWrite &outIv,
const Memory::MemoryViewRead &inKey,
Memory::ByteBuffer &plainText,
AUKN_SYM bool Decrypt(const AuMemoryViewRead &cipherText,
const AuMemoryViewRead &inIv,
const AuMemoryViewWrite &outIv,
const AuMemoryViewRead &inKey,
AuByteBuffer &plainText,
bool safe)
{

View File

@ -56,7 +56,7 @@ namespace Aurora::Crypto::ECC
}
}
AUKN_SYM IECCPrivate *OpenPrivateECC(const Memory::MemoryViewRead &pk)
AUKN_SYM IECCPrivate *OpenPrivateECC(const AuMemoryViewRead &pk)
{
if (auto ret = NewStdECC<PrivateECCImpl>({}/*no curve assertion*/, pk, false))
{
@ -67,7 +67,7 @@ namespace Aurora::Crypto::ECC
return {};
}
AUKN_SYM IECCPublic *OpenPublicECC(const Memory::MemoryViewRead &pk)
AUKN_SYM IECCPublic *OpenPublicECC(const AuMemoryViewRead &pk)
{
if (auto ret = NewStdECC<PublicECCImpl>({}/*no curve assertion*/, pk, false))
{
@ -78,7 +78,7 @@ namespace Aurora::Crypto::ECC
return {};
}
AUKN_SYM IECCPublic *OpenPublicECCFromCert(const Memory::MemoryViewRead &certificate)
AUKN_SYM IECCPublic *OpenPublicECCFromCert(const AuMemoryViewRead &certificate)
{
if (auto ret = NewStdECC<PublicECCImpl>({}/*no curve assertion*/, certificate, true))
{

View File

@ -29,9 +29,9 @@ namespace Aurora::Crypto::ECC
return _type;
}
bool PrivateECCImpl::Sign(const Memory::MemoryViewRead &plainText,
bool PrivateECCImpl::Sign(const AuMemoryViewRead &plainText,
EHashType method,
Memory::ByteBuffer &out)
AuByteBuffer &out)
{
prng_state yarrow_prng;
const int salt = 0;
@ -55,7 +55,7 @@ namespace Aurora::Crypto::ECC
return false;
}
Memory::ByteBuffer hashVec;
AuByteBuffer hashVec;
if (!AuTryResize(hashVec, 128))
{
@ -76,8 +76,8 @@ namespace Aurora::Crypto::ECC
return Sign(hashVec, out);
}
bool PrivateECCImpl::Sign(const Memory::MemoryViewRead &hash,
Memory::ByteBuffer &out)
bool PrivateECCImpl::Sign(const AuMemoryViewRead &hash,
AuByteBuffer &out)
{
prng_state yarrow_prng;
const int salt = 0;
@ -118,9 +118,9 @@ namespace Aurora::Crypto::ECC
}
bool PrivateECCImpl::ECDH(const AuSPtr<IECCPublic> &partnerPublic,
Memory::ByteBuffer &sharedKey)
AuByteBuffer &sharedKey)
{
Memory::ByteBuffer sharedSecret;
AuByteBuffer sharedSecret;
if (!AuTryResize(sharedSecret, 128))
{
@ -151,12 +151,12 @@ namespace Aurora::Crypto::ECC
return true;
}
bool PrivateECCImpl::AsPublicECC(Memory::ByteBuffer &out)
bool PrivateECCImpl::AsPublicECC(AuByteBuffer &out)
{
return ExportECCKey(_key, true, out);
}
bool PrivateECCImpl::AsPrivateECC(Memory::ByteBuffer &out)
bool PrivateECCImpl::AsPrivateECC(AuByteBuffer &out)
{
return ExportECCKey(_key, false, out);
}

View File

@ -28,8 +28,8 @@ namespace Aurora::Crypto::ECC
return _type;
}
bool PublicECCImpl::Verify(const Memory::MemoryViewRead &hash,
const Memory::MemoryViewRead &signature)
bool PublicECCImpl::Verify(const AuMemoryViewRead &hash,
const AuMemoryViewRead &signature)
{
int ok = 0;
@ -57,8 +57,8 @@ namespace Aurora::Crypto::ECC
return ok == 1;
}
bool PublicECCImpl::Verify(const Memory::MemoryViewRead &plaintext,
const Memory::MemoryViewRead &signature,
bool PublicECCImpl::Verify(const AuMemoryViewRead &plaintext,
const AuMemoryViewRead &signature,
EHashType method)
{
if (!plaintext.HasMemory())
@ -80,7 +80,7 @@ namespace Aurora::Crypto::ECC
return false;
}
Memory::ByteBuffer hashVec;
AuByteBuffer hashVec;
if (!AuTryResize(hashVec, 128))
{
SysPushErrorMem();
@ -100,7 +100,7 @@ namespace Aurora::Crypto::ECC
return Verify({hashVec}, signature);
}
bool PublicECCImpl::AsPublicECC(Memory::ByteBuffer &out)
bool PublicECCImpl::AsPublicECC(AuByteBuffer &out)
{
return Export(true, out);
}

View File

@ -11,7 +11,7 @@
namespace Aurora::Crypto::PEM
{
static bool ParsePEM(const AuString &begin, const AuString &end, const AuString &src, Memory::ByteBuffer &buf)
static bool ParsePEM(const AuString &begin, const AuString &end, const AuString &src, AuByteBuffer &buf)
{
AuUInt lines = 0;
AuString str;
@ -44,7 +44,7 @@ namespace Aurora::Crypto::PEM
return fail ? false : finished;
}
static AuString SerializePEM(const AuString &begin, const AuString &end, const Memory::ByteBuffer &buf)
static AuString SerializePEM(const AuString &begin, const AuString &end, const AuByteBuffer &buf)
{
auto delm = AuBuild::kCurrentVendor == AuBuild::EVendor::eGenericMicrosoft ? "\r\n" : "\n";
AuString ret;

View File

@ -96,7 +96,7 @@ namespace Aurora::Crypto::RSA
bool PrivateRSA::Decrypt(const Memory::MemoryViewRead &payload,
EPaddingType type,
Memory::ByteBuffer &out)
AuByteBuffer &out)
{
if (!payload.HasMemory())
{
@ -149,7 +149,7 @@ namespace Aurora::Crypto::RSA
return AuMakeShared<PublicRSA>(key_, false);
}
bool PrivateRSA::ToKey(const RSAMeta &meta, Memory::ByteBuffer &out)
bool PrivateRSA::ToKey(const RSAMeta &meta, AuByteBuffer &out)
{
return ExportRSAKey(key_, meta.side, meta.type, out);
}

View File

@ -25,8 +25,8 @@ namespace Aurora::Crypto::RSA
}
}
bool PublicRSA::Verify(const Memory::MemoryViewRead &payload,
const Memory::MemoryViewRead &signature,
bool PublicRSA::Verify(const AuMemoryViewRead &payload,
const AuMemoryViewRead &signature,
EHashType method,
EPaddingType type)
{
@ -57,7 +57,7 @@ namespace Aurora::Crypto::RSA
return false;
}
Memory::ByteBuffer hashVec;
AuByteBuffer hashVec;
if (!AuTryResize(hashVec, 128))
{
SysPushErrorMem();
@ -90,7 +90,7 @@ namespace Aurora::Crypto::RSA
bool PublicRSA::Encrypt(const Memory::MemoryViewRead &plainText,
EPaddingType type,
Memory::ByteBuffer &out)
AuMemory::ByteBuffer &out)
{
prng_state yarrow_prng;
@ -140,7 +140,7 @@ namespace Aurora::Crypto::RSA
return true;
}
bool PublicRSA::ToKey(ERSAKeyType type, Memory::ByteBuffer &out)
bool PublicRSA::ToKey(ERSAKeyType type, AuByteBuffer &out)
{
return ExportRSAKey(key_, EKeyType::eKeyPublic, type, out);
}

View File

@ -29,7 +29,7 @@ namespace Aurora::Crypto::X509
#pragma region functions copied from mbedtls, modified to do extract the asn fields we care about
static int x509_get_crt_ext(mbedtls_x509_crt *crt, const char *oid, int oidLength, AuFunction<void(mbedtls_x509_buf &ex, unsigned char **, unsigned char *)> cb);
static int x509_get_ca_id(mbedtls_x509_crt *crt, Memory::ByteBuffer &key)
static int x509_get_ca_id(mbedtls_x509_crt *crt, AuByteBuffer &key)
{
bool ok = false;
return x509_get_crt_ext(crt, MBEDTLS_OID_AUTHORITY_KEY_IDENTIFIER, sizeof(MBEDTLS_OID_AUTHORITY_KEY_IDENTIFIER) - 1, [&](mbedtls_x509_buf &ex, unsigned char **p, unsigned char *end)
@ -64,7 +64,7 @@ namespace Aurora::Crypto::X509
}) == 0 && ok;
}
static int x509_get_subject_id(mbedtls_x509_crt *crt, Memory::ByteBuffer &key)
static int x509_get_subject_id(mbedtls_x509_crt *crt, AuByteBuffer &key)
{
bool ok = false;
return x509_get_crt_ext(crt, MBEDTLS_OID_SUBJECT_KEY_IDENTIFIER, sizeof(MBEDTLS_OID_SUBJECT_KEY_IDENTIFIER) - 1, [&](mbedtls_x509_buf &ex, unsigned char **p, unsigned char *end)

View File

@ -236,8 +236,8 @@ namespace Aurora::IO::FS
}
bool ok {};
ok = stream->Write(Memory::MemoryViewStreamRead{bom});
ok &= stream->Write(Memory::MemoryViewStreamRead{str});
ok = stream->Write(AuMemoryViewStreamRead{bom});
ok &= stream->Write(AuMemoryViewStreamRead{str});
stream->Flush();
return ok;

View File

@ -125,7 +125,7 @@ namespace Aurora::IO::FS
}
}
bool Write(const Memory::MemoryViewStreamRead & parameters) override
bool Write(const AuMemoryViewStreamRead & parameters) override
{
return false;
}
@ -140,12 +140,12 @@ namespace Aurora::IO::FS
offset_ = stream_.tellp();
}
bool Read(const Memory::MemoryViewStreamWrite &parameters) override
bool Read(const AuMemoryViewStreamWrite &parameters) override
{
return false;
}
bool Write(const Memory::MemoryViewStreamRead & parameters) override
bool Write(const AuMemoryViewStreamRead & parameters) override
{
try
{

View File

@ -127,7 +127,7 @@ namespace Aurora::Locale::Encoding
}
template<typename converter_t, typename charout_t>
static bool TranslateInUtfBuffer(const AuUInt8 *in, AuUInt length, Memory::ByteBuffer &out, bool endianLe = true)
static bool TranslateInUtfBuffer(const AuUInt8 *in, AuUInt length, AuByteBuffer &out, bool endianLe = true)
{
out.resize(length * sizeof(charout_t));
auto len = TranslateInUtfBuffer<converter_t, charout_t>(in, length, out.data(), out.size(), endianLe);
@ -180,7 +180,7 @@ namespace Aurora::Locale::Encoding
AuStreamReadWrittenPair_t DecodeUTF8Internal(const void *binary, AuUInt32 binaryLength, void *utf8, AuUInt32 utf8Max, ECodePage page)
{
AuStreamReadWrittenPair_t ret {};
Memory::ByteBuffer temp;
AuByteBuffer temp;
if (!utf8)
{
@ -189,7 +189,7 @@ namespace Aurora::Locale::Encoding
utf8Max = temp.size();
}
Memory::ByteBuffer rw(reinterpret_cast<const AuUInt8 *>(binary), reinterpret_cast<const AuUInt8 *>(binary) + binaryLength);
AuByteBuffer rw(reinterpret_cast<const AuUInt8 *>(binary), reinterpret_cast<const AuUInt8 *>(binary) + binaryLength);
auto readable = AuMin(AuUInt(binaryLength), AuUInt(utf8Max));
switch (page)

View File

@ -11,7 +11,7 @@
namespace Aurora::Locale::Encoding
{
AUKN_SYM BOM DecodeBOM(const Memory::MemoryViewRead & binary)
AUKN_SYM BOM DecodeBOM(const AuMemoryViewRead & binary)
{
#define ADD_PATTERN(str, code) {str, {ECodePage::code, AuArraySize(str) - 1}}
AuList<AuTuple<const char *, BOM>> bows =
@ -43,19 +43,19 @@ namespace Aurora::Locale::Encoding
// OLD SHIT API
AUKN_SYM AuStreamReadWrittenPair_t EncodeUTF8(const Memory::MemoryViewRead &utf8, const Memory::MemoryViewWrite & binary, ECodePage page)
AUKN_SYM AuStreamReadWrittenPair_t EncodeUTF8(const AuMemoryViewRead &utf8, const AuMemoryViewWrite & binary, ECodePage page)
{
TextStreamEncoder re(page);
return re.DecodeUTF8(utf8.ptr, utf8.length, binary.ptr, binary.length);
}
AUKN_SYM AuStreamReadWrittenPair_t DecodeUTF8(const Memory::MemoryViewRead &binary, const Memory::MemoryViewWrite & utf8, ECodePage page)
AUKN_SYM AuStreamReadWrittenPair_t DecodeUTF8(const AuMemoryViewRead &binary, const AuMemoryViewWrite & utf8, ECodePage page)
{
TextStreamProcessor re(page);
return re.EncodeUTF8(binary.ptr, binary.length, utf8.ptr, utf8.length);
}
AUKN_SYM AuStreamReadWrittenPair_t DecodeUTF8(const Memory::MemoryViewRead &binary, AuString &out, ECodePage page)
AUKN_SYM AuStreamReadWrittenPair_t DecodeUTF8(const AuMemoryViewRead &binary, AuString &out, ECodePage page)
{
auto aaa = DecodeUTF8(binary, {}, page);
out.resize(aaa.second);
@ -78,7 +78,7 @@ namespace Aurora::Locale::Encoding
/// Supporting full 6 byte UTF-8, copies or returns the available streams from @param utf8 to @param utf32
AUKN_SYM AuStreamReadWrittenPair_t ReadUTF8IntoUTF32ByteString(const Memory::MemoryViewRead &utf8, const Memory::MemoryViewWrite &utf32)
AUKN_SYM AuStreamReadWrittenPair_t ReadUTF8IntoUTF32ByteString(const AuMemoryViewRead &utf8, const AuMemoryViewWrite &utf32)
{
const char *begin = utf8.Begin<const char>();
const char *end = utf8.End<const char>();
@ -90,7 +90,7 @@ namespace Aurora::Locale::Encoding
/// Supporting full 6 byte UTF-8, copies or returns the available streams from @param utf32 to @param utf8
AUKN_SYM AuStreamReadWrittenPair_t ReadUTF32IntoUTF8ByteString(const Memory::MemoryViewRead &utf32, const Memory::MemoryViewWrite &utf8)
AUKN_SYM AuStreamReadWrittenPair_t ReadUTF32IntoUTF8ByteString(const AuMemoryViewRead &utf32, const AuMemoryViewWrite &utf8)
{
const AuUInt32 *begin = utf32.Begin<const AuUInt32>();
const AuUInt32 *end = utf32.End<const AuUInt32>();
@ -112,33 +112,33 @@ namespace Aurora::Locale::Encoding
UTF32::SwapU32(utf32.Begin<AuUInt32>(), utf32.ToCount<AuUInt32>());
}
AUKN_SYM void SwapUTF16(const Memory::MemoryViewWrite &utf32)
AUKN_SYM void SwapUTF16(const AuMemoryViewWrite &utf32)
{
UTF16::SwapU16(utf32.Begin<AuUInt32>(), utf32.ToCount<AuUInt32>());
}
AUKN_SYM AuUInt32 CountUTF32Length(const Memory::MemoryViewRead &utf32, bool bytes)
AUKN_SYM AuUInt32 CountUTF32Length(const AuMemoryViewRead &utf32, bool bytes)
{
return UTF32::Count32(utf32.ptr, utf32.length, bytes);
}
AUKN_SYM AuUInt32 CountUTF16Length(const Memory::MemoryViewRead &utf16, bool bytes)
AUKN_SYM AuUInt32 CountUTF16Length(const AuMemoryViewRead &utf16, bool bytes)
{
return UTF16::Count16(utf16.ptr, utf16.length, bytes);
}
AUKN_SYM AuUInt32 CountUTF8Length(const Memory::MemoryViewRead &utf8, bool bytes)
AUKN_SYM AuUInt32 CountUTF8Length(const AuMemoryViewRead &utf8, bool bytes)
{
auto pair = ReadUTF8IntoUTF32ByteString(utf8, {});
return bytes ? pair.first : pair.second / sizeof(AuUInt32);
}
AUKN_SYM AuUInt32 CountSJISLength(const Memory::MemoryViewRead &sjis, bool bytes)
AUKN_SYM AuUInt32 CountSJISLength(const AuMemoryViewRead &sjis, bool bytes)
{
return SJIS::CountSJIS(sjis.ptr, sjis.length, bytes);
}
AUKN_SYM AuUInt32 CountGBK16Length(const Memory::MemoryViewRead &gbk, bool bytes)
AUKN_SYM AuUInt32 CountGBK16Length(const AuMemoryViewRead &gbk, bool bytes)
{
return GBK::CountGbk(gbk.ptr, gbk.length, bytes);
}

View File

@ -32,7 +32,7 @@ namespace Aurora::Memory
// i think mimalloc has fast paths with warnings for overly large passthrough allocations. unsure.
// 32 alignment in the fastest way mimalloc can provide us memory seems adequate
// it's very easy for mimalloc to seethe at larger allocations, but it does have slowpaths to handle them
return Memory::FAlloc<void *>(length, 32);
return AuMemory::FAlloc<void *>(length, 32);
#endif
}
@ -44,7 +44,7 @@ namespace Aurora::Memory
#elif defined(AURORA_IS_POSIX_DERIVED)
munmap(buffer, length);
#else
Memory::Free(buffer);
AuMemory::Free(buffer);
mi_collect(false);
#endif
}

View File

@ -11,7 +11,7 @@
namespace Aurora::Parse
{
AUKN_SYM bool Base32Decode(const AuString &in, Memory::ByteBuffer &decoded)
AUKN_SYM bool Base32Decode(const AuString &in, AuByteBuffer &decoded)
{
unsigned long length = in.size();
try

View File

@ -11,7 +11,7 @@
namespace Aurora::Parse
{
AUKN_SYM bool Base64Decode(const AuString &in, Memory::ByteBuffer &decoded, bool url)
AUKN_SYM bool Base64Decode(const AuString &in, AuByteBuffer &decoded, bool url)
{
unsigned long length = in.size();
try

View File

@ -95,7 +95,7 @@ namespace Aurora::Parse
hex[1] = NibbleToChar(lowNibble);
}
AUKN_SYM bool DecodeHex(const AuString &in, Memory::ByteBuffer &out)
AUKN_SYM bool DecodeHex(const AuString &in, AuByteBuffer &out)
{
#define HEX_GRAMMAR_CONSUME_ALL(x) \
for (; i < in.size(); i++) \

View File

@ -60,7 +60,7 @@ namespace Aurora::Threading::Threads
return nullptr;
}
auto buf = Memory::ZAlloc<void *>(length);
auto buf = AuMemory::ZAlloc<void *>(length);
if (!buf)
{
return nullptr;
@ -69,7 +69,7 @@ namespace Aurora::Threading::Threads
auto ok = AuTryInsertNoEnd(tls_, AuMakePair(key, AuMakePair(buf, TlsCb {})));
if (!ok)
{
Memory::Free(buf);
AuMemory::Free(buf);
return nullptr;
}
@ -96,7 +96,7 @@ namespace Aurora::Threading::Threads
return value->first;
}
auto buf = Memory::ZAlloc<void *>(length);
auto buf = AuMemory::ZAlloc<void *>(length);
if (!buf)
{
return nullptr;
@ -106,7 +106,7 @@ namespace Aurora::Threading::Threads
auto ok = AuTryInsertNoEnd(tls_, AuMakePair(key, AuMakePair(buf, deinitcb)));
if (!ok)
{
Memory::Free(buf);
AuMemory::Free(buf);
return nullptr;
}