Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix warnings
  • Loading branch information
huiguangjun committed Aug 15, 2025
commit 1ba1d8a258f57edee7ae927d7621e9cebf9991df
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
.cache
.vs
.vscode
build
winbuild
9 changes: 7 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ option(BUILD_TESTS "Build unit and perfermence tests" OFF)
option(ENABLE_COVERAGE "Flag to enable/disable building code with -fprofile-arcs and -ftest-coverage. Gcc only" OFF)
option(ENABLE_RTTI "Flag to enable/disable building code with RTTI information" ON)


#Platform
if (CMAKE_CROSSCOMPILING)
if (${CMAKE_SYSTEM_NAME} STREQUAL "Android")
Expand Down Expand Up @@ -99,12 +98,18 @@ else()
endif()

#Compiler flags
list(APPEND SDK_COMPILER_FLAGS "-std=c++11")
set(CMAKE_CXX_STANDARD 11 CACHE STRING "C++ standard to use")
message(STATUS "CXX Standard: ${CMAKE_CXX_STANDARD}")
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
list(APPEND SDK_COMPILER_FLAGS "/MP")
if (NOT ENABLE_RTTI)
list(APPEND SDK_COMPILER_FLAGS "/GR-")
endif()
# disable some warning
list(APPEND SDK_COMPILER_FLAGS "/D_CRT_SECURE_NO_WARNINGS")
if(CMAKE_CXX_STANDARD GREATER_EQUAL 17)
list(APPEND SDK_COMPILER_FLAGS "/D_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING")
endif()
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
list(APPEND SDK_COMPILER_FLAGS "-fno-exceptions" "-fPIC")
if (NOT ENABLE_RTTI)
Expand Down
30 changes: 15 additions & 15 deletions sdk/src/encryption/Cipher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ ByteBuffer SymmetricCipher::GenerateIV(size_t length)
{
//use openssl rand func
ByteBuffer out = ByteBuffer(length);
RAND_bytes((unsigned char *)out.data(), length);
RAND_bytes((unsigned char *)out.data(), static_cast<int>(length));
return out;
}

ByteBuffer SymmetricCipher::GenerateKey(size_t length)
{
//use openssl rand func
ByteBuffer out = ByteBuffer(length);
RAND_bytes((unsigned char *)out.data(), length);
RAND_bytes((unsigned char *)out.data(), static_cast<int>(length));
return out;
}

Expand All @@ -78,19 +78,19 @@ bswap(T i, T j = 0u, std::size_t n = 0u)
ByteBuffer SymmetricCipher::IncCTRCounter(const ByteBuffer& counter, uint64_t numberOfBlocks)
{
ByteBuffer ctrCounter(counter);
uint64_t *ctrPtr = (uint64_t*)(ctrCounter.data() + ctrCounter.size() - sizeof(uint64_t));

uint64_t n = 1;
if (*(char *)&n) {
//little
*ctrPtr = bswap<uint64_t>(bswap<uint64_t>(*ctrPtr) + numberOfBlocks);
}
else {
//big
*ctrPtr += numberOfBlocks;
}

return ctrCounter;
uint64_t *ctrPtr = (uint64_t*)(ctrCounter.data() + ctrCounter.size() - sizeof(uint64_t));
uint64_t n = 1;
if (*(char *)&n) {
//little
*ctrPtr = bswap<uint64_t>(bswap<uint64_t>(*ctrPtr) + numberOfBlocks);
}
else {
//big
*ctrPtr += numberOfBlocks;
}
return ctrCounter;
}

std::shared_ptr<SymmetricCipher> SymmetricCipher::CreateAES128_CTRImpl()
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/encryption/CipherOpenssl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ ByteBuffer AsymmetricCipherOpenssl::Encrypt(const ByteBuffer& data)
int rsa_len = RSA_size(rsa);
enc.resize(rsa_len, 0);

if (RSA_public_encrypt(data.size(), (unsigned char*)data.data(), (unsigned char*)enc.data(), rsa, RSA_PKCS1_PADDING) < 0) {
if (RSA_public_encrypt((int)data.size(), (unsigned char*)data.data(), (unsigned char*)enc.data(), rsa, RSA_PKCS1_PADDING) < 0) {
enc.resize(0);
}

Expand Down
4 changes: 2 additions & 2 deletions sdk/src/encryption/CryptoModule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,11 @@ void CryptoModule::addMetaData(const ContentCryptoMaterial& content, ObjectMetaD
{
//x-oss-meta-client-side-encryption-key
meta.addUserHeader("client-side-encryption-key",
Base64Encode((const char*)content.EncryptedContentKey().data(), content.EncryptedContentKey().size()));
Base64Encode((const char*)content.EncryptedContentKey().data(), static_cast<int>(content.EncryptedContentKey().size())));

//x-oss-meta-client-side-encryption-start //iv
meta.addUserHeader("client-side-encryption-start",
Base64Encode((const char*)content.EncryptedContentIV().data(), content.EncryptedContentIV().size()));
Base64Encode((const char*)content.EncryptedContentIV().data(), static_cast<int>(content.EncryptedContentIV().size())));

//x-oss-meta-client-side-encryption-cek-alg
meta.addUserHeader("client-side-encryption-cek-alg", content.CipherName());
Expand Down
166 changes: 83 additions & 83 deletions sdk/src/encryption/OssEncryptionClient.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,19 @@ static PutObjectRequest ConvertToPutObjectRequest(const UploadObjectRequest& req
return pRequest;
}

class EncryptionResumableDownloader : public ResumableDownloader
{
public:
EncryptionResumableDownloader(const DownloadObjectRequest& request, const ObjectMetaData& meta,
const OssEncryptionClient* enClient, const OssClientImpl *client, uint64_t objectSize)
: ResumableDownloader(request, client, objectSize)
, encryptionClient_(enClient)
, metaData_(meta)
{
//16 bytes alignment
partSize_ = (partSize_ >> 4) << 4;
}
protected:
class EncryptionResumableDownloader : public ResumableDownloader
{
public:
EncryptionResumableDownloader(const DownloadObjectRequest& request, const ObjectMetaData& meta,
const OssEncryptionClient* enClient, const OssClientImpl *client, uint64_t objectSize)
: ResumableDownloader(request, client, objectSize)
, encryptionClient_(enClient)
, metaData_(meta)
{
//16 bytes alignment
partSize_ = (partSize_ >> 4) << 4;
}
protected:
virtual GetObjectOutcome GetObjectWrap(const GetObjectRequest &request) const
{
return encryptionClient_->GetObjectInternal(request, metaData_);
Expand All @@ -92,77 +92,77 @@ class EncryptionResumableDownloader : public ResumableDownloader

class EncryptionResumableUploader : public ResumableUploader
{
public:
EncryptionResumableUploader(const UploadObjectRequest& request,
const OssEncryptionClient* enClient, const OssClientImpl *client)
: ResumableUploader(request, client)
, encryptionClient_(enClient)
{
//16 bytes alignment
partSize_ = (partSize_ >> 4) << 4;
}
protected:
virtual void initRecordInfo()
{
ResumableUploader::initRecordInfo();
encryptionCheckData_ = cryptoContext_.ContentMaterial().ContentIV();
}

virtual void buildRecordInfo(const Json::Value& value)
{
ResumableUploader::buildRecordInfo(value);
ContentCryptoMaterial material;
material.setEncryptedContentKey(Base64Decode(value["encryption-key"].asString()));
material.setEncryptedContentIV(Base64Decode(value["encryption-iv"].asString()));
material.setKeyWrapAlgorithm(value["encryption-wrap-alg"].asString());
material.setDescription(JsonStringToMap(value["encryption-matdesc"].asString()));
public:
EncryptionResumableUploader(const UploadObjectRequest& request,
const OssEncryptionClient* enClient, const OssClientImpl *client)
: ResumableUploader(request, client)
, encryptionClient_(enClient)
{
//16 bytes alignment
partSize_ = (partSize_ >> 4) << 4;
}
protected:
virtual void initRecordInfo()
{
ResumableUploader::initRecordInfo();
encryptionCheckData_ = cryptoContext_.ContentMaterial().ContentIV();
}
virtual void buildRecordInfo(const Json::Value& value)
{
ResumableUploader::buildRecordInfo(value);
ContentCryptoMaterial material;
material.setEncryptedContentKey(Base64Decode(value["encryption-key"].asString()));
material.setEncryptedContentIV(Base64Decode(value["encryption-iv"].asString()));
material.setKeyWrapAlgorithm(value["encryption-wrap-alg"].asString());
material.setDescription(JsonStringToMap(value["encryption-matdesc"].asString()));
encryptionClient_->encryptionMaterials_->DecryptCEK(material);

material.setCipherName(value["encryption-cek-alg"].asString());

cryptoContext_.setUploadId(value["uploadID"].asString());
cryptoContext_.setDataSize(value["size"].asInt64());
cryptoContext_.setPartSize(value["partSize"].asInt64());
cryptoContext_.setContentMaterial(material);

encryptionCheckData_ = Base64Decode(value["encryption-check-data"].asString());
}

virtual void dumpRecordInfo(Json::Value& value)
{
ResumableUploader::dumpRecordInfo(value);
const ByteBuffer& buff1 = cryptoContext_.ContentMaterial().EncryptedContentKey();
value["encryption-key"] = Base64Encode((const char*)buff1.data(), buff1.size());
const ByteBuffer& buff2 = cryptoContext_.ContentMaterial().EncryptedContentIV();
value["encryption-iv"] = Base64Encode((const char*)buff2.data(), buff2.size());
value["encryption-cek-alg"] = cryptoContext_.ContentMaterial().CipherName();
value["encryption-wrap-alg"] = cryptoContext_.ContentMaterial().KeyWrapAlgorithm();
value["encryption-matdesc"] = MapToJsonString(cryptoContext_.ContentMaterial().Description());

const ByteBuffer& buff3 = cryptoContext_.ContentMaterial().ContentIV();
value["encryption-check-data"] = Base64Encode((const char*)buff3.data(), buff3.size());
}

virtual int validateRecord()
{
int ret = ResumableUploader::validateRecord();
if (ret != 0) {
return ret;
}

if (cryptoContext_.ContentMaterial().ContentKey().empty()||
cryptoContext_.ContentMaterial().ContentIV().empty() ||
cryptoContext_.ContentMaterial().CipherName().empty()) {
return -2;
}

if (encryptionCheckData_ != cryptoContext_.ContentMaterial().ContentIV()) {
return -2;
}

return 0;
}

material.setCipherName(value["encryption-cek-alg"].asString());
cryptoContext_.setUploadId(value["uploadID"].asString());
cryptoContext_.setDataSize(value["size"].asInt64());
cryptoContext_.setPartSize(value["partSize"].asInt64());
cryptoContext_.setContentMaterial(material);
encryptionCheckData_ = Base64Decode(value["encryption-check-data"].asString());
}
virtual void dumpRecordInfo(Json::Value& value)
{
ResumableUploader::dumpRecordInfo(value);
const ByteBuffer& buff1 = cryptoContext_.ContentMaterial().EncryptedContentKey();
value["encryption-key"] = Base64Encode((const char*)buff1.data(), (int)buff1.size());
const ByteBuffer& buff2 = cryptoContext_.ContentMaterial().EncryptedContentIV();
value["encryption-iv"] = Base64Encode((const char*)buff2.data(), (int)buff2.size());
value["encryption-cek-alg"] = cryptoContext_.ContentMaterial().CipherName();
value["encryption-wrap-alg"] = cryptoContext_.ContentMaterial().KeyWrapAlgorithm();
value["encryption-matdesc"] = MapToJsonString(cryptoContext_.ContentMaterial().Description());
const ByteBuffer& buff3 = cryptoContext_.ContentMaterial().ContentIV();
value["encryption-check-data"] = Base64Encode((const char*)buff3.data(), (int)buff3.size());
}
virtual int validateRecord()
{
int ret = ResumableUploader::validateRecord();
if (ret != 0) {
return ret;
}
if (cryptoContext_.ContentMaterial().ContentKey().empty()||
cryptoContext_.ContentMaterial().ContentIV().empty() ||
cryptoContext_.ContentMaterial().CipherName().empty()) {
return -2;
}
if (encryptionCheckData_ != cryptoContext_.ContentMaterial().ContentIV()) {
return -2;
}
return 0;
}
virtual InitiateMultipartUploadOutcome InitiateMultipartUploadWrap(const InitiateMultipartUploadRequest &request) const
{
cryptoContext_.setPartSize(static_cast<int64_t>(partSize_));
Expand Down
4 changes: 4 additions & 0 deletions sdk/src/external/json/jsoncpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,10 @@ static inline void fixNumericLocaleInput(char* begin, char* end) {
#pragma warning(disable : 4996)
#endif

#if defined(__GNUG__) && __GNUC__ > 8
#pragma GCC diagnostic ignored "-Wstringop-overflow"
#endif

// Define JSONCPP_DEPRECATED_STACK_LIMIT as an appropriate integer at compile time to change the stack limit
#if !defined(JSONCPP_DEPRECATED_STACK_LIMIT)
#define JSONCPP_DEPRECATED_STACK_LIMIT 1000
Expand Down
6 changes: 3 additions & 3 deletions sdk/src/model/CreateSelectObjectMetaResult.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "../utils/Crc32.h"

#define FRAME_HEADER_LEN (12+8)
#define PARSE_FOUR_BYTES(a, b, c, d) (((uint64_t)(a) << 24)|((uint64_t)(b) << 16)|((uint64_t)(c) << 8)|(d))
#define PARSE_FOUR_BYTES(a, b, c, d) (((uint32_t)(a) << 24)|((uint32_t)(b) << 16)|((uint32_t)(c) << 8)|(d))
#define PARSE_EIGHT_BYTES(a, b, c, d, e, f, g, h) (((uint64_t)(a)<<56)|((uint64_t)(b)<<48)| ((uint64_t)(c)<<40)| ((uint64_t)(d)<<32)| ((uint64_t)(e)<<24)| ((uint64_t)(f)<<16)| ((uint64_t)(g)<<8)| (h))

using namespace AlibabaCloud::OSS;
Expand Down Expand Up @@ -62,7 +62,7 @@ CreateSelectObjectMetaResult& CreateSelectObjectMetaResult::operator=(const std:
int type = 0;
type = (buffer[1] << 16) | (buffer[2] << 8) | buffer[3];
// payload length 4 bytes
int length = PARSE_FOUR_BYTES(buffer[4], buffer[5], buffer[6], buffer[7]);
uint32_t length = PARSE_FOUR_BYTES(buffer[4], buffer[5], buffer[6], buffer[7]);
// header checksum

// payload
Expand All @@ -72,7 +72,7 @@ CreateSelectObjectMetaResult& CreateSelectObjectMetaResult::operator=(const std:
case 0x800007:
{
uint32_t payloadCrc32 = 0;
int messageLength = length - 32;
uint32_t messageLength = length - 32;
data->read(reinterpret_cast<char*>(buffer), 32);
payloadCrc32 = CRC32::CalcCRC(payloadCrc32, buffer, 32);
// offset 8 bytes
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/model/SelectObjectRequest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ SelectObjectRequest::SelectObjectRequest(const std::string& bucket, const std::s
void SelectObjectRequest::setResponseStreamFactory(const IOStreamFactory& factory)
{
upperResponseStreamFactory_ = factory;
ServiceRequest::setResponseStreamFactory([=]() {
ServiceRequest::setResponseStreamFactory([this]() {
streamBuffer_ = nullptr;
auto content = upperResponseStreamFactory_();
if (!outputFormat_->OutputRawData()) {
Expand Down
2 changes: 0 additions & 2 deletions sdk/src/model/UploadPartCopyResult.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
using namespace AlibabaCloud::OSS;
using namespace tinyxml2;

static const std::string EMPTY;

UploadPartCopyResult::UploadPartCopyResult() :
OssObjectResult()
{
Expand Down
Loading