[*] eradicate AuList<AuUInt8> abuse, switch over to AuByteBuffer

This commit is contained in:
Reece Wilson 2022-01-20 16:04:53 +00:00
parent 46d5eed4c8
commit 02aa0dfd13
42 changed files with 324 additions and 106 deletions

View File

@ -12,20 +12,20 @@ namespace Aurora::Compression
/**
Compresses an in memory blob with zstandard
*/
AUKN_SYM bool Compress(const void *buffer, AuUInt32 length, AuList<AuUInt8> &out, int compressionLevel = 3);
AUKN_SYM bool Compress(const void *buffer, AuUInt32 length, Memory::ByteBuffer &out, int compressionLevel = 3);
/**
Compresses an in memory blob with zstandard
*/
AUKN_SYM bool Compress(const AuList<AuUInt8> &in, AuList<AuUInt8> &out, int compressionLevel = 3);
AUKN_SYM bool Compress(const Memory::ByteBuffer &in, Memory::ByteBuffer &out, int compressionLevel = 3);
/**
Decompresses an in memory blob with zstandard
*/
AUKN_SYM bool Decompress(const void *buffer, AuUInt32 length, AuList<AuUInt8> &out);
AUKN_SYM bool Decompress(const void *buffer, AuUInt32 length, Memory::ByteBuffer &out);
/**
Decompresses an in memory blob with zstandard
*/
AUKN_SYM bool Decompress(const AuList<AuUInt8> &in, AuList<AuUInt8> &out);
AUKN_SYM bool Decompress(const Memory::ByteBuffer &in, Memory::ByteBuffer &out);
}

View File

@ -24,13 +24,13 @@ namespace Aurora::Crypto::AES
const Memory::MemoryViewRead &inIv,
const Memory::MemoryViewWrite &outIv,
const Memory::MemoryViewRead &inKey,
AuList<AuUInt8> &out,
Memory::ByteBuffer &out,
bool auCoolCodePadding);
AUKN_SYM bool Decrypt(const Memory::MemoryViewRead &cipherText,
const Memory::MemoryViewRead &inIv,
const Memory::MemoryViewWrite &outIv,
const Memory::MemoryViewRead &inKey,
AuList<AuUInt8> &plainText,
Memory::ByteBuffer &plainText,
bool auCoolCodePadding);
}

View File

@ -18,7 +18,7 @@ namespace Aurora::Crypto::CA
{
public:
virtual void AddSignature(const AuSPtr<RSA::IRSAPublic> &CA,
const AuList<AuUInt8> &sig,
const Memory::ByteBuffer &sig,
EHashType method,
EPaddingType type) = 0;

View File

@ -9,11 +9,11 @@
namespace Aurora::Crypto
{
using DerBuffer = AuList<AuUInt8>;
using DerBuffer = Memory::ByteBuffer;
namespace X509
{
using Certificate = AuList<AuUInt8>;
using Certificate = Memory::ByteBuffer;
}
struct RSAPair

View File

@ -14,16 +14,16 @@ namespace Aurora::Crypto::ECC
public:
virtual bool Sign(const Memory::MemoryViewRead &plainText,
EHashType method,
AuList<AuUInt8> &out) = 0;
Memory::ByteBuffer &out) = 0;
virtual bool Sign(const Memory::MemoryViewRead &hash,
AuList<AuUInt8> &out) = 0;
Memory::ByteBuffer &out) = 0;
virtual bool ECDH(const AuSPtr<IECCPublic> &partnerPublic,
AuList<AuUInt8> &sharedKey) = 0;
Memory::ByteBuffer &sharedKey) = 0;
virtual bool AsPublicECC(AuList<AuUInt8> &out) = 0;
virtual bool AsPrivateECC(AuList<AuUInt8> &out) = 0;
virtual bool AsPublicECC(Memory::ByteBuffer &out) = 0;
virtual bool AsPrivateECC(Memory::ByteBuffer &out) = 0;
virtual EECCCurve GetType() = 0;
};

View File

@ -20,7 +20,7 @@ namespace Aurora::Crypto::ECC
EHashType method) = 0;
virtual bool AsPublicECC(AuList<AuUInt8> &out) = 0;
virtual bool AsPublicECC(Memory::ByteBuffer &out) = 0;
virtual EECCCurve GetType() = 0;
};

View File

@ -16,14 +16,14 @@ namespace Aurora::Crypto::RSA
virtual bool Sign(const Memory::MemoryViewRead &payload,
EHashType method,
EPaddingType type,
AuList<AuUInt8> &out) = 0;
Memory::ByteBuffer &out) = 0;
virtual bool Decrypt(const Memory::MemoryViewRead &payload,
EPaddingType type,
AuList<AuUInt8> &out) = 0;
Memory::ByteBuffer &out) = 0;
virtual AuSPtr<IRSAPublic> ToPublic() = 0;
virtual bool ToKey(const RSAMeta &meta, AuList<AuUInt8> &out) = 0;
virtual bool ToKey(const RSAMeta &meta, Memory::ByteBuffer &out) = 0;
};
}

View File

@ -20,8 +20,8 @@ namespace Aurora::Crypto::RSA
virtual bool Encrypt(const Memory::MemoryViewRead &plainText,
EPaddingType type,
AuList<AuUInt8> &out) = 0;
Memory::ByteBuffer &out) = 0;
virtual bool ToKey(ERSAKeyType type, AuList<AuUInt8> &out) = 0;
virtual bool ToKey(ERSAKeyType type, Memory::ByteBuffer &out) = 0;
};
}

View File

@ -38,11 +38,11 @@ namespace Aurora::Crypto::X509
//SignatureAlgorithm signature;
struct Issuer : CertName
{
AuList<AuUInt8> id;
Memory::ByteBuffer id;
} issuer;
struct Subject : CertName
{
AuList<AuUInt8> id;
Memory::ByteBuffer id;
} subject;
struct Vaildity // Tbs
{ // Tbs

View File

@ -10,7 +10,7 @@
namespace Aurora::Hashing
{
AUKN_SYM void MD5(const void *buffer, AuMach length, AuArray<AuUInt8, 16> &md5);
static void MD5(const AuList<AuUInt8> &bytebuffer, AuArray<AuUInt8, 16> &md5)
static void MD5(const Memory::ByteBuffer &bytebuffer, AuArray<AuUInt8, 16> &md5)
{
return MD5(bytebuffer.data(), bytebuffer.size(), md5);
}
@ -20,7 +20,7 @@ namespace Aurora::Hashing
}
AUKN_SYM void SHA1(const void *buffer, AuMach length, AuArray<AuUInt8, 20> &sha1);
static void SHA1(const AuList<AuUInt8> &bytebuffer, AuArray<AuUInt8, 20> &sha1)
static void SHA1(const Memory::ByteBuffer &bytebuffer, AuArray<AuUInt8, 20> &sha1)
{
return SHA1(bytebuffer.data(), bytebuffer.size(), sha1);
}
@ -30,7 +30,7 @@ namespace Aurora::Hashing
}
AUKN_SYM void Tiger(const void *buffer, AuMach length, AuArray<AuUInt8, 24> &tiger);
static void Tiger(const AuList<AuUInt8> &bytebuffer, AuArray<AuUInt8, 24> &tiger)
static void Tiger(const Memory::ByteBuffer &bytebuffer, AuArray<AuUInt8, 24> &tiger)
{
return Tiger(bytebuffer.data(), bytebuffer.size(), tiger);
}
@ -40,7 +40,7 @@ namespace Aurora::Hashing
}
AUKN_SYM void SHA2(const void *buffer, AuMach length, AuArray<AuUInt8, 32> &sha2);
static void SHA2(const AuList<AuUInt8> &bytebuffer, AuArray<AuUInt8, 32> &sha2)
static void SHA2(const Memory::ByteBuffer &bytebuffer, AuArray<AuUInt8, 32> &sha2)
{
return SHA2(bytebuffer.data(), bytebuffer.size(), sha2);
}
@ -50,7 +50,7 @@ namespace Aurora::Hashing
}
AUKN_SYM void SHA2_64(const void *buffer, AuMach length, AuArray<AuUInt8, 64> &sha2);
static void SHA2_64(const AuList<AuUInt8> &bytebuffer, AuArray<AuUInt8, 64> &sha2)
static void SHA2_64(const Memory::ByteBuffer &bytebuffer, AuArray<AuUInt8, 64> &sha2)
{
return SHA2_64(bytebuffer.data(), bytebuffer.size(), sha2);
}

View File

@ -14,7 +14,7 @@ namespace Aurora::IO::Buffered
public:
AU_NO_COPY_NO_MOVE(BlobArbitraryReader)
BlobArbitraryReader(const AuList<AuUInt8> &buffer) : buffer_(buffer) {}
BlobArbitraryReader(const Memory::ByteBuffer &buffer) : buffer_(buffer) {}
BlobArbitraryReader() {}
~BlobArbitraryReader(){}
@ -45,6 +45,6 @@ namespace Aurora::IO::Buffered
}
private:
AuList<AuUInt8> buffer_;
Memory::ByteBuffer buffer_;
};
}

View File

@ -14,7 +14,7 @@ namespace Aurora::IO::Buffered
public:
AU_NO_COPY_NO_MOVE(BlobReader)
BlobReader(const AuList<AuUInt8> &buffer) : buffer_(buffer) {}
BlobReader(const Memory::ByteBuffer &buffer) : buffer_(buffer) {}
BlobReader() {}
~BlobReader() {}
@ -41,7 +41,7 @@ namespace Aurora::IO::Buffered
}
private:
AuList<AuUInt8> buffer_;
Memory::ByteBuffer buffer_;
AuUInt32 offset_ {};
};
}

View File

@ -38,12 +38,12 @@ namespace Aurora::IO::Buffered
{
}
const AuList<AuUInt8> &GetBuffer()
const Memory::ByteBuffer &GetBuffer()
{
return this->buffer_;
}
private:
AuList<AuUInt8> buffer_;
Memory::ByteBuffer buffer_;
};
}

View File

@ -16,7 +16,7 @@ namespace Aurora::IO
virtual EStreamError Read(const Memory::MemoryViewStreamWrite &paramters) = 0;
virtual void Close() = 0;
EStreamError ReadAll(AuList<AuUInt8> &buffer)
EStreamError ReadAll(Memory::ByteBuffer &buffer)
{
static const int kBufferSize = 2048;
@ -27,6 +27,8 @@ namespace Aurora::IO
len = kBufferSize;
ret = EStreamError::eErrorEndOfStream;
buffer = Memory::NewResizableBuffer();
while ((ret = Read(Memory::MemoryViewStreamWrite(temp, len))) == EStreamError::eErrorNone)
{
if (len == 0)
@ -34,7 +36,7 @@ namespace Aurora::IO
break;
}
buffer.insert(buffer.end(), temp, temp + len);
buffer.Write(temp, len);
if (len != kBufferSize)
{

View File

@ -95,7 +95,11 @@ namespace Aurora::Memory
ByteBuffer(const ByteBuffer &buffer, bool preservePointers = true)
{
this->base = FAlloc<AuUInt8 *>(buffer.length);
if (!this->base) AU_THROW_STRING("memory error");
if (!this->base)
{
Reset();
return;
}
this->length = buffer.length;
this->allocSize = buffer.length;
if (preservePointers)
@ -117,7 +121,11 @@ namespace Aurora::Memory
ByteBuffer(const void *in, AuUInt length, bool circular = false, bool expandable = false) : flagCircular(circular), flagExpandable(expandable), flagReadError(0), flagWriteError(0)
{
this->base = FAlloc<AuUInt8 *>(length);
if (!this->base) AU_THROW_STRING("memory error");
if (!this->base)
{
Reset();
return;
}
this->length = length;
this->allocSize = length;
this->readPtr = this->base;
@ -129,7 +137,11 @@ namespace Aurora::Memory
ByteBuffer(const AuList<AuUInt8> &vector, bool circular = false, bool expandable = false) : flagCircular(circular), flagExpandable(expandable), flagReadError(0), flagWriteError(0)
{
this->base = FAlloc<AuUInt8 *>(vector.size());
if (!this->base) AU_THROW_STRING("memory error");
if (!this->base)
{
Reset();
return;
}
this->length = vector.size();
this->allocSize = vector.size();
this->readPtr = this->base;
@ -140,16 +152,43 @@ namespace Aurora::Memory
ByteBuffer(AuUInt length, bool circular = false, bool expandable = false) : flagCircular(circular), flagExpandable(expandable), flagReadError(0), flagWriteError(0)
{
if (!length)
{
Reset();
return;
}
this->base = ZAlloc<AuUInt8 *>(length);
if (!this->base) AU_THROW_STRING("memory error");
if (!this->base)
{
Reset();
return;
}
this->length = length;
this->allocSize = length;
this->readPtr = this->base;
this->writePtr = this->base;
this->scaleSize = kBufferInitialPower;
}
template<typename T>
ByteBuffer(T *base, T *end, bool circular = false, bool expandable = false) : flagCircular(circular), flagExpandable(expandable), flagReadError(0), flagWriteError(0)
{
auto length = static_cast<AuUInt>(end - base) * sizeof(T);
this->base = ZAlloc<AuUInt8 *>(length);
if (!this->base)
{
Reset();
return;
}
this->length = length;
this->allocSize = length;
this->readPtr = this->base;
this->writePtr = this->base;
this->scaleSize = kBufferInitialPower;
AuMemcpy(this->base, base, length);
}
ByteBuffer() : flagCircular(0), flagExpandable(0), flagReadError(0), flagWriteError(0)
ByteBuffer() : flagCircular(0), flagExpandable(true), flagReadError(0), flagWriteError(0)
{
this->base = {};
this->length = {};
@ -176,8 +215,14 @@ namespace Aurora::Memory
}
// Iterator
inline auline AuUInt8 * data() const;
inline auline AuUInt size() const;
inline auline AuUInt8 * begin() const;
inline auline AuUInt8 * end() const;
inline auline bool empty() const;
inline void clear();
inline void resize(AuUInt size);
inline void reserve(AuUInt size);
// Utils To alternative types
inline auline AuList<AuUInt8> ToVector() const;
@ -186,6 +231,20 @@ namespace Aurora::Memory
inline operator AuList<AuUInt8>() const;
inline operator MemoryViewRead() const;
// Internal buffer comparison
inline bool operator ==(const AuList<AuUInt8> &) const;
inline bool operator ==(const MemoryViewRead &) const;
inline bool operator ==(const ByteBuffer &) const;
// Move assignment
inline ByteBuffer &operator =(ByteBuffer &&);
// &byteArray[n]
inline AuUInt8 &operator [](AuUInt idx);
// if (byteArray) -> if (byteArray->IsValid())
inline operator bool() const;
inline AuList<AuUInt8> RemainingBytesToVector(bool endAtWrite = true) const;
@ -212,6 +271,11 @@ namespace Aurora::Memory
inline auline bool SetBuffer(const AuList<AuUInt8> &buffer);
inline auline void GC();
inline void Reset();
inline void Reserve(AuUInt length);
inline auline bool IsEmpty() const;
inline auline bool HasStreamError() const;
inline auline bool IsValid() const;
inline auline bool Resize(AuUInt length);
@ -230,4 +294,14 @@ namespace Aurora::Memory
template<typename T>
bool Read(T &out);
};
static ByteBuffer NewResizableBuffer(AuUInt32 length = 0)
{
return ByteBuffer(length, false, true);
}
static ByteBuffer NewRingBuffer(AuUInt32 length = 1024 * 5)
{
return ByteBuffer(length, true, false);
}
}

View File

@ -24,7 +24,7 @@ namespace Aurora::Memory
this->length = length;
this->allocSize = length;
this->readPtr = this->base;
this->writePtr = this->readPtr + this->length;
this->writePtr = this->base;
return true;
}
@ -44,8 +44,31 @@ namespace Aurora::Memory
return SetBuffer(buffer.data(), buffer.size());
}
void ByteBuffer::Reset()
{
if (this->base)
{
Free(this->base);
}
this->base = {};
this->length = {};
this->allocSize = {};
this->readPtr = {};
this->writePtr = {};
this->scaleSize = kBufferInitialPower;
}
void ByteBuffer::Reserve(AuUInt length)
{
auto oldLength = this->length;
this->Resize(length);
this->length = AuMin(oldLength, length);
}
void ByteBuffer::GC()
{
if (this->length)
if (this->allocSize == this->length) return;
auto temp = Memory::FRealloc(this->base, this->length);
if (!temp) return;
@ -59,6 +82,17 @@ namespace Aurora::Memory
AuUInt oldWriteIdx, oldReadIdx, oldLength, newLength;
AuUInt8 *nextRead, *nextWrite, *nextPtr;
if (length == 0)
{
Reset();
return true;
}
if (!this->base)
{
return Allocate(length, false);
}
if (this->allocSize > length)
{
this->length = length;

View File

@ -24,6 +24,41 @@ namespace Aurora::Memory
return vec;
}
void ByteBuffer::clear()
{
Reset();
}
void ByteBuffer::resize(AuUInt size)
{
if (!Resize(size)) AU_THROW_STRING("ByteBuffer resize failure");
}
void ByteBuffer::reserve(AuUInt size)
{
Reserve(size);
}
AuUInt8 &ByteBuffer::operator [](AuUInt idx)
{
return *(data() + idx);
}
AuUInt8 *ByteBuffer::data() const
{
return begin();
}
AuUInt ByteBuffer::size() const
{
return length;
}
bool ByteBuffer::empty() const
{
return IsEmpty();
}
AuUInt8 *ByteBuffer::begin() const
{
SysAssert(!flagCircular, "::begin is only available for linear buffers");
@ -51,6 +86,60 @@ namespace Aurora::Memory
return MemoryViewRead(begin(), end());
}
bool ByteBuffer::operator ==(const AuList<AuUInt8> &in) const
{
if (in.size() != size()) return false;
return AuMemcmp(in.data(), base, size()) == 0;
}
bool ByteBuffer::operator ==(const MemoryViewRead & read) const
{
if (read.ToLength() != size()) return false;
return AuMemcmp(read.ToPointer(), base, size()) == 0;
}
bool ByteBuffer::operator ==(const ByteBuffer &other) const
{
if (other.size() != size()) return false;
return AuMemcmp(other.base, base, size()) == 0;
}
inline ByteBuffer::operator bool() const
{
return IsValid();
}
bool ByteBuffer::HasStreamError() const
{
return flagReadError || flagWriteError;
}
bool ByteBuffer::IsValid() const
{
return !IsEmpty() && !HasStreamError();
}
ByteBuffer &ByteBuffer::operator =(ByteBuffer && other)
{
Reset();
this->base = other.base;
this->length = other.length;
this->allocSize = other.length;
this->writePtr = this->base + (other.writePtr - other.base);
this->readPtr = this->base + (other.readPtr - other.base);
this->flagCircular = other.flagCircular;
this->flagExpandable = other.flagExpandable;
this->scaleSize = other.scaleSize;
other.base = {};
other.length = {};
other.allocSize = {};
other.writePtr = {};
other.readPtr = {};
other.flagCircular = {};
other.flagExpandable = {};
other.scaleSize = {};
}
AuList<AuUInt8> ByteBuffer::RemainingBytesToVector(bool endAtWrite) const
{
AuList<AuUInt8> vec;

View File

@ -76,9 +76,19 @@ namespace Aurora::Memory
this->length = length;
}
AuUInt ToPointer() const
AuUInt8 *ToPointer()
{
return reinterpret_cast<AuUInt>(ptr);
return reinterpret_cast<AuUInt8 *>(ptr);
}
AuUInt ToPointerValue() const
{
return reinterpret_cast<const AuUInt>(ptr);
}
const AuUInt8 *ToPointer() const
{
return reinterpret_cast<const AuUInt8 *>(ptr);
}
AuUInt ToLength() const

View File

@ -9,14 +9,14 @@
namespace Aurora::Parse
{
AUKN_SYM bool Base32Decode(const AuString &in, AuList<AuUInt8> &decoded);
AUKN_SYM bool Base32Decode(const AuString &in, Memory::ByteBuffer &decoded);
AUKN_SYM bool Base32Encode(const void *buffer, AuMach length, AuString &encoded);
static bool Base32Encode(const AuString &in, AuString &encoded)
{
return Base32Encode(in.data(), in.size(), encoded);
}
static bool Base32Encode(const AuList<AuUInt8> &in, AuString &encoded)
static bool Base32Encode(const Memory::ByteBuffer &in, AuString &encoded)
{
return Base32Encode(in.data(), in.size(), encoded);
}

View File

@ -9,14 +9,14 @@
namespace Aurora::Parse
{
AUKN_SYM bool Base64Decode(const AuString &in, AuList<AuUInt8> &decoded, bool url = false);
AUKN_SYM bool Base64Decode(const AuString &in, Memory::ByteBuffer &decoded, bool url = false);
AUKN_SYM bool Base64Encode(const void *buffer, AuMach length, AuString &encoded, bool url = false);
static bool Base64Encode(const AuString &in, AuString &encoded, bool url = false)
{
return Base64Encode(in.data(), in.size(), encoded, url);
}
static bool Base64Encode(const AuList<AuUInt8> &in, AuString &encoded, bool url = false)
static bool Base64Encode(const Memory::ByteBuffer &in, AuString &encoded, bool url = false)
{
return Base64Encode(in.data(), in.size(), encoded, url);
}

View File

@ -22,5 +22,5 @@ namespace Aurora::Parse
AUKN_SYM bool HexToInt (const char *hex, AuUInt32 length, AuUInt64 &val);
AUKN_SYM void EncodeHex(const void *pBuf, AuUInt32 length, EHexDump formatting, AuString &out);
AUKN_SYM bool DecodeHex(const AuString &in, AuList<AuUInt8> &out);
AUKN_SYM bool DecodeHex(const AuString &in, Memory::ByteBuffer &out);
}

View File

@ -102,6 +102,15 @@ namespace AuMemory = Aurora::Memory;
using AuWorkerId_t = AuAsync::WorkerId_t;
using AuWorkerPId_t = AuAsync::WorkerPId_t;
using AuByteBuffer = AuMemory::ByteBuffer;
using AuMemoryViewRead = AuMemory::MemoryViewRead;
using AuMemoryViewWrite = AuMemory::MemoryViewWrite;
using AuMemoryViewStreamRead = AuMemory::MemoryViewStreamRead;
using AuMemoryViewStreamWrite = AuMemory::MemoryViewStreamWrite;
static bool AuIsThreadRunning()
{
return !AuThreads::GetThread()->Exiting();

View File

@ -12,14 +12,14 @@
namespace Aurora::Compression
{
AUKN_SYM bool Compress(const void *buffer, AuUInt32 length, AuList<AuUInt8> &out, int compressionLevel )
AUKN_SYM bool Compress(const void *buffer, AuUInt32 length, Memory::ByteBuffer &out, int compressionLevel )
{
if (!AuTryResize(out, length))
{
return false;
}
auto ret = ZSTD_compress(&out[0], out.size(), buffer, length, compressionLevel);
auto ret = ZSTD_compress(out.data(), out.size(), buffer, length, compressionLevel);
if (ZSTD_isError(ret))
{
return false;
@ -29,12 +29,12 @@ namespace Aurora::Compression
return true;
}
AUKN_SYM bool Compress(const AuList<AuUInt8> &in, AuList<AuUInt8> &out, int compressionLevel)
AUKN_SYM bool Compress(const Memory::ByteBuffer &in, Memory::ByteBuffer &out, int compressionLevel)
{
return Compress(in.data(), in.size(), out, compressionLevel);
}
AUKN_SYM bool Decompress(const void *buffer, AuUInt32 length, AuList<AuUInt8> &out)
AUKN_SYM bool Decompress(const void *buffer, AuUInt32 length, Memory::ByteBuffer &out)
{
AuUInt32 read = 0;
@ -80,7 +80,7 @@ namespace Aurora::Compression
return true;
}
AUKN_SYM bool Decompress(const AuList<AuUInt8> &in, AuList<AuUInt8> &out)
AUKN_SYM bool Decompress(const Memory::ByteBuffer &in, Memory::ByteBuffer &out)
{
return Decompress(in.data(), in.size(), out);
}

View File

@ -19,8 +19,8 @@ namespace Aurora::Compression
{
static bool DecompressZSTD(const CompressionPipe &info)
{
AuList<AuUInt8> buffer;
AuList<AuUInt8> inflatedBuffer;
Memory::ByteBuffer buffer;
Memory::ByteBuffer inflatedBuffer;
if (!info.writePipe)
{
@ -90,8 +90,8 @@ namespace Aurora::Compression
static bool CompressZSTD(const CompressionPipe &stream, const CompressionInfo &info)
{
AuList<AuUInt8> inflatedBuffer;
AuList<AuUInt8> deflatedBuffer;
Memory::ByteBuffer inflatedBuffer;
Memory::ByteBuffer deflatedBuffer;
size_t ret;
const auto buffInSize = ZSTD_CStreamInSize();
const auto buffOutSize = ZSTD_CStreamOutSize();

View File

@ -41,7 +41,7 @@ namespace Aurora::Crypto::AES
static bool EncryptCoolCodePadding(const void *plainText, AuUInt plainTextLength,
const void *iv, void *outIv, AuUInt ivLength,
const void *key, AuUInt keyLength,
AuList<AuUInt8> &out,
Memory::ByteBuffer &out,
symmetric_CBC &cbc)
{
@ -143,7 +143,7 @@ namespace Aurora::Crypto::AES
const Memory::MemoryViewRead &inIv,
const Memory::MemoryViewWrite & outIv,
const Memory::MemoryViewRead &inKey,
AuList<AuUInt8> &out,
Memory::ByteBuffer &out,
bool auCoolCodePadding)
{
symmetric_CBC cbc;
@ -258,7 +258,7 @@ namespace Aurora::Crypto::AES
const Memory::MemoryViewRead &inIv,
const Memory::MemoryViewWrite &outIv,
const Memory::MemoryViewRead &inKey,
AuList<AuUInt8> &plainText,
Memory::ByteBuffer &plainText,
bool safe)
{

View File

@ -12,7 +12,7 @@
namespace Aurora::Crypto::ECC
{
template<typename Type_t>
Type_t *NewECC(EECCCurve curve, const AuList<AuUInt8> &pub);
Type_t *NewECC(EECCCurve curve, const Memory::ByteBuffer &pub);
bool ExportECCKey(const ecc_key &key, bool pub, DerBuffer &out);

View File

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

View File

@ -10,17 +10,17 @@ namespace Aurora::Crypto::ECC
bool Sign(const Memory::MemoryViewRead &plainText,
EHashType method,
AuList<AuUInt8> &out) override;
Memory::ByteBuffer &out) override;
bool Sign(const Memory::MemoryViewRead &hash,
AuList<AuUInt8> &out) override;
Memory::ByteBuffer &out) override;
bool ECDH(const AuSPtr<IECCPublic> &partnerPublic,
AuList<AuUInt8> &sharedKey) override;
Memory::ByteBuffer &sharedKey) override;
bool AsPublicECC(AuList<AuUInt8> &out) override;
bool AsPublicECC(Memory::ByteBuffer &out) override;
bool AsPrivateECC(AuList<AuUInt8> &out) override;
bool AsPrivateECC(Memory::ByteBuffer &out) override;
EECCCurve GetType() override;

View File

@ -80,7 +80,7 @@ namespace Aurora::Crypto::ECC
return false;
}
AuList<AuUInt8> hashVec;
Memory::ByteBuffer hashVec;
if (!AuTryResize(hashVec, 128))
{
SysPushErrorMem();
@ -100,7 +100,7 @@ namespace Aurora::Crypto::ECC
return Verify({hashVec}, signature);
}
bool PublicECCImpl::AsPublicECC(AuList<AuUInt8> &out)
bool PublicECCImpl::AsPublicECC(Memory::ByteBuffer &out)
{
return Export(true, out);
}

View File

@ -15,7 +15,7 @@ namespace Aurora::Crypto::ECC
const Memory::MemoryViewRead &signature,
EHashType method) override;
bool AsPublicECC(AuList<AuUInt8> &out) override;
bool AsPublicECC(Memory::ByteBuffer &out) override;
bool Export(bool pub, DerBuffer &out);

View File

@ -11,7 +11,7 @@
namespace Aurora::Crypto::PEM
{
static bool ParsePEM(const AuString &begin, const AuString &end, const AuString &src, AuList<AuUInt8> &buf)
static bool ParsePEM(const AuString &begin, const AuString &end, const AuString &src, Memory::ByteBuffer &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 AuList<AuUInt8> &buf)
static AuString SerializePEM(const AuString &begin, const AuString &end, const Memory::ByteBuffer &buf)
{
auto delm = AuBuild::kCurrentVendor == AuBuild::EVendor::eGenericMicrosoft ? "\r\n" : "\n";
AuString ret;

View File

@ -10,7 +10,7 @@
namespace Aurora::Crypto::RSA
{
static bool ExportRSAKey(const rsa_key &key, EKeyType side, ERSAKeyType type, AuList<AuUInt8> &out)
static bool ExportRSAKey(const rsa_key &key, EKeyType side, ERSAKeyType type, Memory::ByteBuffer &out)
{
int flags = 0;

View File

@ -26,7 +26,7 @@ namespace Aurora::Crypto::RSA
bool PrivateRSA::Sign(const Memory::MemoryViewRead & payload,
EHashType method,
EPaddingType type,
AuList<AuUInt8> &out)
Memory::ByteBuffer &out)
{
prng_state yarrow_prng;
const int salt = 0;
@ -57,7 +57,7 @@ namespace Aurora::Crypto::RSA
return false;
}
AuList<AuUInt8> hashVec;
Memory::ByteBuffer hashVec;
if (!AuTryResize(hashVec, 128))
{
@ -96,7 +96,7 @@ namespace Aurora::Crypto::RSA
bool PrivateRSA::Decrypt(const Memory::MemoryViewRead &payload,
EPaddingType type,
AuList<AuUInt8> &out)
Memory::ByteBuffer &out)
{
if (!payload.HasMemory())
{
@ -149,7 +149,7 @@ namespace Aurora::Crypto::RSA
return AuMakeShared<PublicRSA>(key_, false);
}
bool PrivateRSA::ToKey(const RSAMeta &meta, AuList<AuUInt8> &out)
bool PrivateRSA::ToKey(const RSAMeta &meta, Memory::ByteBuffer &out)
{
return ExportRSAKey(key_, meta.side, meta.type, out);
}

View File

@ -18,15 +18,15 @@ namespace Aurora::Crypto::RSA
bool Sign(const Memory::MemoryViewRead & payload,
EHashType method,
EPaddingType type,
AuList<AuUInt8> &out) override;
Memory::ByteBuffer &out) override;
bool Decrypt(const Memory::MemoryViewRead & payload,
EPaddingType type,
AuList<AuUInt8> &out) override;
Memory::ByteBuffer &out) override;
AuSPtr<IRSAPublic> ToPublic() override;
bool ToKey(const RSAMeta &meta, AuList<AuUInt8> &out) override;
bool ToKey(const RSAMeta &meta, Memory::ByteBuffer &out) override;
private:
rsa_key key_;

View File

@ -57,7 +57,7 @@ namespace Aurora::Crypto::RSA
return false;
}
AuList<AuUInt8> hashVec;
Memory::ByteBuffer hashVec;
if (!AuTryResize(hashVec, 128))
{
SysPushErrorMem();
@ -90,7 +90,7 @@ namespace Aurora::Crypto::RSA
bool PublicRSA::Encrypt(const Memory::MemoryViewRead &plainText,
EPaddingType type,
AuList<AuUInt8> &out)
Memory::ByteBuffer &out)
{
prng_state yarrow_prng;
@ -140,7 +140,7 @@ namespace Aurora::Crypto::RSA
return true;
}
bool PublicRSA::ToKey(ERSAKeyType type, AuList<AuUInt8> &out)
bool PublicRSA::ToKey(ERSAKeyType type, Memory::ByteBuffer &out)
{
return ExportRSAKey(key_, EKeyType::eKeyPublic, type, out);
}

View File

@ -23,9 +23,9 @@ namespace Aurora::Crypto::RSA
bool Encrypt(const Memory::MemoryViewRead & plainText,
EPaddingType type,
AuList<AuUInt8> &out) override;
Memory::ByteBuffer &out) override;
bool ToKey(ERSAKeyType type, AuList<AuUInt8> &out) override;
bool ToKey(ERSAKeyType type, Memory::ByteBuffer &out) override;
private:
rsa_key key_;

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, AuList<AuUInt8> &key)
static int x509_get_ca_id(mbedtls_x509_crt *crt, Memory::ByteBuffer &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, AuList<AuUInt8> &key)
static int x509_get_subject_id(mbedtls_x509_crt *crt, Memory::ByteBuffer &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

@ -46,7 +46,7 @@ namespace Aurora::IO::FS
return bytesWritten == length;
}
AUKN_SYM bool ReadFile(const AuString &path, AuList<AuUInt8> &buffer)
AUKN_SYM bool ReadFile(const AuString &path, Memory::ByteBuffer &buffer)
{
auto file = fopen(NormalizePathRet(path).c_str(), "rb");
if (!file)
@ -157,7 +157,7 @@ namespace Aurora::IO::FS
#else
// im not even going to bother writing a crt stream copy here
// what are you doing with this reference implemention?
AuList<AuUInt8> buffered;
Memory::ByteBuffer buffered;
if (!ReadFile(src, buffered))
{
return false;

View File

@ -127,14 +127,14 @@ namespace Aurora::Locale::Encoding
}
template<typename converter_t, typename charout_t>
static bool TranslateInUtfBuffer(const AuUInt8 *in, AuUInt length, AuList<AuUInt8> &out, bool endianLe = true)
static bool TranslateInUtfBuffer(const AuUInt8 *in, AuUInt length, Memory::ByteBuffer &out, bool endianLe = true)
{
out.resize(length * sizeof(charout_t));
auto len = TranslateInUtfBuffer<converter_t, charout_t>(in, length, out.data(), out.size(), endianLe);
if (len)
{
out.resize(len);
out.shrink_to_fit();
out.GC();
}
return len;
}
@ -143,7 +143,7 @@ namespace Aurora::Locale::Encoding
{
AuStreamReadWrittenPair_t ret {};
auto readable = AuMin(AuUInt(utf8Length), AuUInt(binaryLength));
AuList<AuUInt8> temp;
Memory::ByteBuffer temp;
if (!binary)
{
@ -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 {};
AuList<AuUInt8> temp;
Memory::ByteBuffer temp;
if (!utf8)
{
@ -189,7 +189,7 @@ namespace Aurora::Locale::Encoding
utf8Max = temp.size();
}
AuList<AuUInt8> rw(reinterpret_cast<const AuUInt8 *>(binary), reinterpret_cast<const AuUInt8 *>(binary) + binaryLength);
Memory::ByteBuffer rw(reinterpret_cast<const AuUInt8 *>(binary), reinterpret_cast<const AuUInt8 *>(binary) + binaryLength);
auto readable = AuMin(AuUInt(binaryLength), AuUInt(utf8Max));
switch (page)
@ -219,7 +219,7 @@ namespace Aurora::Locale::Encoding
AuStreamReadWrittenPair_t DecodeUTF8Internal(void *binary, AuUInt32 binaryLength, void *utf8, AuUInt32 utf8Max, ECodePage page)
{
AuStreamReadWrittenPair_t ret {};
AuList<AuUInt8> temp;
Memory::ByteBuffer temp;
if (!utf8)
{
@ -228,7 +228,7 @@ namespace Aurora::Locale::Encoding
utf8Max = temp.size();
}
AuList<AuUInt8> rw(reinterpret_cast<const AuUInt8 *>(binary), reinterpret_cast<const AuUInt8 *>(binary) + binaryLength);
Memory::ByteBuffer 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::Parse
{
AUKN_SYM bool Base32Decode(const AuString &in, AuList<AuUInt8> &decoded)
AUKN_SYM bool Base32Decode(const AuString &in, Memory::ByteBuffer &decoded)
{
unsigned long length = in.size();
try

View File

@ -11,7 +11,7 @@
namespace Aurora::Parse
{
AUKN_SYM bool Base64Decode(const AuString &in, AuList<AuUInt8> &decoded, bool url)
AUKN_SYM bool Base64Decode(const AuString &in, Memory::ByteBuffer &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, AuList<AuUInt8> &out)
AUKN_SYM bool DecodeHex(const AuString &in, Memory::ByteBuffer &out)
{
#define HEX_GRAMMAR_CONSUME_ALL(x) \
for (; i < in.size(); i++) \
@ -172,7 +172,7 @@ namespace Aurora::Parse
return false;
}
out.push_back(byte);
out.Write(byte);
i += 2;
}