chore: generalize base64 usage

This commit is contained in:
Jan
2024-09-22 15:10:54 +02:00
parent 3b59dad109
commit 7649e5d58f
4 changed files with 71 additions and 16 deletions

View File

@ -1,14 +1,12 @@
#include "GltfBuffer.h"
#include "Impl/Base64.h"
#include "XModel/Gltf/GltfConstants.h"
#include <cassert>
#include <cstdint>
#include <cstring>
#define LTC_NO_PROTOTYPES
#include <tomcrypt.h>
using namespace gltf;
EmbeddedBuffer::EmbeddedBuffer(const void* data, const size_t dataSize)
@ -51,15 +49,12 @@ bool DataUriBuffer::ReadDataFromUri(const std::string& uri)
return false;
const auto base64DataLength = uri.size() - URI_PREFIX_LENGTH;
m_data_size = base64::GetBase64DecodeOutputLength(base64DataLength);
m_data = std::make_unique<uint8_t[]>(m_data_size);
unsigned long outLength = base64DataLength / 4u;
m_data = std::make_unique<uint8_t[]>(outLength);
const auto result = base64_decode(&uri[URI_PREFIX_LENGTH], base64DataLength, m_data.get(), &outLength);
m_data_size = static_cast<size_t>(outLength);
m_data_size = base64::DecodeBase64(&uri[URI_PREFIX_LENGTH], base64DataLength, m_data.get(), m_data_size);
assert(result == CRYPT_OK);
return false;
return m_data_size > 0;
}
bool DataUriBuffer::ReadData(void* dest, const size_t offset, const size_t count) const