Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update clang format rule #923

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Language: Cpp
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignConsecutiveMacros: false
AlignConsecutiveAssignments: AcrossEmptyLinesAndComments
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Right
AlignOperands: true
Expand Down
4 changes: 2 additions & 2 deletions core/src/bytes/zarith/zarith.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ namespace ledger {
size_t id = 0, delay = 0;
uint8_t offset = 0;
while (id + delay < data.size()) {
auto byte = data[id + delay];
auto isLast = id + delay == data.size() - 1;
auto byte = data[id + delay];
auto isLast = id + delay == data.size() - 1;

// We should stop reading if most significant bit is null
auto shouldStop = !(byte & 0x80);
Expand Down
8 changes: 4 additions & 4 deletions core/src/common/AbstractExtendedPublicKey.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@ namespace ledger {
throw Exception(api::ErrorCode::INVALID_NETWORK_ADDRESS_VERSION, "Provided network parameters and address version do not match.");
}
// 1 byte of depth
auto depth = reader.readNextByte();
auto depth = reader.readNextByte();
// 4 bytes of fingerprint
auto fingerprint = reader.readNextBeUint();
// 4 bytes of child's index
auto childNum = reader.readNextBeUint();
auto childNum = reader.readNextBeUint();
// 32 bytes of chaincode
auto chainCode = reader.read(32);
auto chainCode = reader.read(32);
// 33 bytes of publicKey
auto publicKey = reader.readUntilEnd();
auto publicKey = reader.readUntilEnd();
return DeterministicPublicKey(publicKey, chainCode, childNum, depth, fingerprint, params.Identifier);
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/cosmos/CosmosLikeAddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ namespace ledger {
const Option<std::string> &derivationPath) {
auto const &params = currency.cosmosLikeNetworkParameters.value();

auto const type = [](auto const &address) {
auto const type = [](auto const &address) {
if (address.find(cosmos::getBech32Params(api::CosmosBech32Type::ADDRESS_VAL).hrp) !=
std::string::npos) {
return api::CosmosBech32Type::ADDRESS_VAL;
Expand Down
20 changes: 10 additions & 10 deletions core/src/crypto/AESCipher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ namespace ledger {
uint32_t read = input->gcount();

// Create an IVt
auto IV = _rng->getRandomBytes(AES256::BLOCK_SIZE);
auto IV = _rng->getRandomBytes(AES256::BLOCK_SIZE);
assert(IV.size() == AES256::BLOCK_SIZE);

// Encrypt
auto encrypted = AES256::encrypt(IV, _key, std::vector<uint8_t>(buffer, buffer + read));
auto encrypted = AES256::encrypt(IV, _key, std::vector<uint8_t>(buffer, buffer + read));
// Store number of blocks
uint8_t blocksCount = (encrypted.size() / AES256::BLOCK_SIZE);
(*output) << blocksCount;
Expand Down Expand Up @@ -107,11 +107,11 @@ namespace ledger {
std::vector<uint8_t> dataToEncrypt = input.read(minEncryptedRead);
uint32_t read = dataToEncrypt.size();
// Create an IVt
auto IV = _rng->getRandomBytes(AES256::BLOCK_SIZE);
auto IV = _rng->getRandomBytes(AES256::BLOCK_SIZE);
// Encrypt
auto encrypted = AES256::encrypt(IV, _key, dataToEncrypt);
auto encrypted = AES256::encrypt(IV, _key, dataToEncrypt);
// Store number of blocks
uint8_t blocksCount = (encrypted.size() / AES256::BLOCK_SIZE);
uint8_t blocksCount = (encrypted.size() / AES256::BLOCK_SIZE);
// Number of blocks of size AES256::BLOCK_SIZE in enrypted data
output.writeByte(blocksCount);
// Limit of reading (padding or string terminating before maxRead)
Expand All @@ -127,23 +127,23 @@ namespace ledger {
uint32_t maxRead = 255 * AES256::BLOCK_SIZE;
do {
// Get number of blocks in encrypted data
uint8_t blocksCount = input.readNextByte();
uint8_t blocksCount = input.readNextByte();
// Size of encrypted (chunk of) data
uint32_t encryptedDataSize = blocksCount * AES256::BLOCK_SIZE;
// Get data that we read
uint32_t dataSize = input.readNextVarInt();
uint32_t dataSize = input.readNextVarInt();
// Read IV
std::vector<uint8_t> IV = input.read(AES256::BLOCK_SIZE);
std::vector<uint8_t> IV = input.read(AES256::BLOCK_SIZE);
// Get number of bytes to read
uint32_t available = input.available();
uint32_t available = input.available();
if (available < encryptedDataSize) {
// Should not read than more available data
break;
}
// Read encrypted data
std::vector<uint8_t> encryptedData = input.read(encryptedDataSize);
// Decrypt
auto decrypted = AES256::decrypt(IV, _key, encryptedData);
auto decrypted = AES256::decrypt(IV, _key, encryptedData);
// Truncate if needed to size of encrypted data that we stored in dataSize bytes
if (dataSize < decrypted.size()) {
decrypted.resize(dataSize);
Expand Down
2 changes: 1 addition & 1 deletion core/src/crypto/DER.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ namespace ledger {

// Ensure DER encoded size match read bytes
// Length = len(rType + rSize + rSig + sType + sSize + sSig)
auto readSize = 2 /* rType + rSize */ + rSize + 2 /* rType + rSize */ + sSize;
auto readSize = 2 /* rType + rSize */ + rSize + 2 /* rType + rSize */ + sSize;
if (length != readSize) {
throw make_exception(api::ErrorCode::INVALID_ARGUMENT,
"Read size mismatch DER announced size");
Expand Down
2 changes: 1 addition & 1 deletion core/src/database/DatabaseBackend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace ledger {
const std::shared_ptr<api::PathResolver> &resolver,
const std::string &dbName,
const std::string &password,
soci::session &session) = 0;
soci::session &session) = 0;

virtual void setPassword(const std::string &password,
soci::session &session) = 0;
Expand Down
8 changes: 4 additions & 4 deletions core/src/math/BaseConverter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace ledger {
/**
* A function taking the number of missing bytes in a block and returning the padding to append to the encoding result.
*/
using PaddingPolicy = std::function<void(int, std::stringstream &)>;
using PaddingPolicy = std::function<void(int, std::stringstream &)>;

/**
* Parameters used by the algorithm to encode or decode a byte array
Expand Down Expand Up @@ -144,7 +144,7 @@ namespace ledger {
auto remainingBits = bufferSize - ValueBitSize;
if (remainingBits < 0) {
// For the sake of understanding what we are doing, we set remainingBits to a positive value
remainingBits = -remainingBits;
remainingBits = -remainingBits;
// Move the bits from the buffer to the index
auto bufferMask = (1 << bufferSize) - 1;
index = (block[offset] & bufferMask) << remainingBits;
Expand Down Expand Up @@ -174,8 +174,8 @@ namespace ledger {

template <int Base, int BlockBitSize, int ValueBitSize>
static void decodeBlock(const char *str, int size, const Params<Base, BlockBitSize, ValueBitSize> &params, std::vector<uint8_t> &out) {
int buffer = 0;
int bufferSize = 0;
int buffer = 0;
int bufferSize = 0;
// Compute extraction mask for a ValueBitSize of 5:
// (1 << 5) = 00100000
// (1 << 5) -1 = 00011111 (i.e if we mask a byte with it, it will only give the 5 last bit values)
Expand Down
2 changes: 1 addition & 1 deletion core/src/math/BigInt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ namespace ledger {
mp::cpp_dec_float_50 scale = mp::pow(mp::cpp_dec_float_50(10), (float)scaleFactor);
f = f * scale;

bool isNegative = f < 0;
bool isNegative = f < 0;

if (isNegative)
f = f * -1;
Expand Down
2 changes: 1 addition & 1 deletion core/src/math/bech32/Bech32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace ledger {
namespace core {

// The Bech32 character set for encoding.
const char *charset = "qpzry9x8gf2tvdw0s3jn54khce6mua7l";
const char *charset = "qpzry9x8gf2tvdw0s3jn54khce6mua7l";

// The Bech32 character set for decoding.
const int8_t charsetRev[128] = {
Expand Down
2 changes: 1 addition & 1 deletion core/src/math/bech32/Bech32.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ namespace ledger {
std::pair<std::string, std::vector<uint8_t>> decodeBech32Raw(const std::string &str) const;

// Find the polynomial with value coefficients mod the generator as 64-bit.
virtual uint64_t polymod(const std::vector<uint8_t> &values) const = 0;
virtual uint64_t polymod(const std::vector<uint8_t> &values) const = 0;

// Expand a HRP for use in checksum computation.
virtual std::vector<uint8_t> expandHrp(const std::string &hrp) const = 0;
Expand Down
2 changes: 1 addition & 1 deletion core/src/net/HttpClient.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ namespace ledger {
const std::vector<uint8_t> &buffer = result.data.value();
std::stringstream ss;
std::copy(buffer.begin(), buffer.end(), std::ostream_iterator<char>(ss, ""));
const std::string str = ss.str();
const std::string str = ss.str();

const int32_t statusCode = c->getStatusCode();
bool isFailure = statusCode < 200 || statusCode >= 400;
Expand Down
8 changes: 4 additions & 4 deletions core/src/tezos/TezosKey.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ namespace ledger {

const Encoding P2SIG{"p2sig", {54, 240, 44, 52}, api::TezosCurve::P256, 64, 99, "p256 signature"};

const std::vector<Encoding> ALL = {EDPK, SPPK, P2PK, XPUB, TZ1, TZ2, TZ3, KT1};
const std::vector<Encoding> ALL = {EDPK, SPPK, P2PK, XPUB, TZ1, TZ2, TZ3, KT1};

const std::vector<Encoding> PUBKEYS = {EDPK, SPPK, P2PK};
const std::vector<Encoding> PUBKEYS = {EDPK, SPPK, P2PK};

const std::vector<Encoding> LEGACY_PUBKEYS = {EDPK, SPPK, P2PK, XPUB};

const std::vector<Encoding> ADDRESSES = {TZ1, TZ2, TZ3, KT1};
const std::vector<Encoding> ADDRESSES = {TZ1, TZ2, TZ3, KT1};

const std::vector<Encoding> SIGNATURES = {EDSIG, SPSIG, P2SIG, SIG};
const std::vector<Encoding> SIGNATURES = {EDSIG, SPSIG, P2SIG, SIG};

/**
* Get the key encoding definition for a given version
Expand Down
6 changes: 3 additions & 3 deletions core/src/utils/Concurrency.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ namespace ledger {
public:
template <typename InputIter, typename UnaryFunction>
static void parallel_for_each(InputIter first, InputIter last, UnaryFunction f) {
auto range = std::distance(first, last);
size_t approxNumThreads = std::thread::hardware_concurrency();
auto range = std::distance(first, last);
size_t approxNumThreads = std::thread::hardware_concurrency();
// number of elements for one thread
size_t jobsForThread = range / approxNumThreads;
size_t jobsForThread = range / approxNumThreads;
// number of elements for one thread + remainder
size_t jobsForMainThread = range % approxNumThreads + jobsForThread;
// minus main thread
Expand Down
4 changes: 2 additions & 2 deletions core/src/utils/DerivationPath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ namespace ledger {
bool lastCharWasZero = false;
bool nextIntIsInHex = false;
std::vector<uint32_t> result;
int sepCount = 0;
int index = 0;
int sepCount = 0;
int index = 0;

auto pushSegment = [&]() {
if (currentNode.size() == 0 && sepCount > 0) {
Expand Down
Loading