Skip to content

Commit e64125a

Browse files
committed
- Move globals to anonymous namespaces.
- Move private static variables to anonymous namespaces. - Remove espnow prefix from names where it is not required.
1 parent effcc3a commit e64125a

20 files changed

+249
-274
lines changed

libraries/ESP8266WiFiMesh/src/EncryptedConnectionData.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,21 @@
2828
#include "JsonTranslator.h"
2929
#include "MeshCryptoInterface.h"
3030

31-
using EspnowProtocolInterpreter::espnowHashKeyLength;
32-
namespace TypeCast = MeshTypeConversionFunctions;
31+
namespace
32+
{
33+
using EspnowProtocolInterpreter::hashKeyLength;
34+
namespace TypeCast = MeshTypeConversionFunctions;
35+
}
3336

34-
EncryptedConnectionData::EncryptedConnectionData(const uint8_t peerStaMac[6], const uint8_t peerApMac[6], const uint64_t peerSessionKey, const uint64_t ownSessionKey, const uint8_t hashKey[espnowHashKeyLength])
37+
EncryptedConnectionData::EncryptedConnectionData(const uint8_t peerStaMac[6], const uint8_t peerApMac[6], const uint64_t peerSessionKey, const uint64_t ownSessionKey, const uint8_t hashKey[hashKeyLength])
3538
: _peerSessionKey(peerSessionKey), _ownSessionKey(ownSessionKey)
3639
{
3740
std::copy_n(peerStaMac, 6, _peerStaMac);
3841
std::copy_n(peerApMac, 6, _peerApMac);
39-
std::copy_n(hashKey, espnowHashKeyLength, _hashKey);
42+
std::copy_n(hashKey, hashKeyLength, _hashKey);
4043
}
4144

42-
EncryptedConnectionData::EncryptedConnectionData(const uint8_t peerStaMac[6], const uint8_t peerApMac[6], const uint64_t peerSessionKey, const uint64_t ownSessionKey, const uint32_t duration, const uint8_t hashKey[espnowHashKeyLength])
45+
EncryptedConnectionData::EncryptedConnectionData(const uint8_t peerStaMac[6], const uint8_t peerApMac[6], const uint64_t peerSessionKey, const uint64_t ownSessionKey, const uint32_t duration, const uint8_t hashKey[hashKeyLength])
4346
: EncryptedConnectionData(peerStaMac, peerApMac, peerSessionKey, ownSessionKey, hashKey)
4447
{
4548
setRemainingDuration(duration);
@@ -106,16 +109,16 @@ bool EncryptedConnectionData::connectedTo(const uint8_t *peerMac) const
106109
return false;
107110
}
108111

109-
void EncryptedConnectionData::setHashKey(const uint8_t hashKey[espnowHashKeyLength])
112+
void EncryptedConnectionData::setHashKey(const uint8_t hashKey[hashKeyLength])
110113
{
111114
assert(hashKey != nullptr);
112115

113-
std::copy_n(hashKey, espnowHashKeyLength, _hashKey);
116+
std::copy_n(hashKey, hashKeyLength, _hashKey);
114117
}
115118

116119
uint8_t *EncryptedConnectionData::getHashKey(uint8_t *resultArray) const
117120
{
118-
std::copy_n(_hashKey, espnowHashKeyLength, resultArray);
121+
std::copy_n(_hashKey, hashKeyLength, resultArray);
119122
return resultArray;
120123
}
121124

@@ -146,7 +149,7 @@ uint64_t EncryptedConnectionData::incrementSessionKey(const uint64_t sessionKey,
146149

147150
void EncryptedConnectionData::incrementOwnSessionKey()
148151
{
149-
setOwnSessionKey(incrementSessionKey(getOwnSessionKey(), _hashKey, EspnowProtocolInterpreter::espnowHashKeyLength));
152+
setOwnSessionKey(incrementSessionKey(getOwnSessionKey(), _hashKey, EspnowProtocolInterpreter::hashKeyLength));
150153
}
151154

152155
void EncryptedConnectionData::setDesync(const bool desync) { _desync = desync; }

libraries/ESP8266WiFiMesh/src/EncryptedConnectionData.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ class EncryptedConnectionData {
3737
virtual ~EncryptedConnectionData() = default;
3838

3939
EncryptedConnectionData(const uint8_t peerStaMac[6], const uint8_t peerApMac[6], const uint64_t peerSessionKey, const uint64_t ownSessionKey,
40-
const uint8_t hashKey[EspnowProtocolInterpreter::espnowHashKeyLength]);
40+
const uint8_t hashKey[EspnowProtocolInterpreter::hashKeyLength]);
4141
EncryptedConnectionData(const uint8_t peerStaMac[6], const uint8_t peerApMac[6], const uint64_t peerSessionKey, const uint64_t ownSessionKey,
42-
const uint32_t duration, const uint8_t hashKey[EspnowProtocolInterpreter::espnowHashKeyLength]);
42+
const uint32_t duration, const uint8_t hashKey[EspnowProtocolInterpreter::hashKeyLength]);
4343

4444
EncryptedConnectionData(const EncryptedConnectionData &other);
4545

@@ -61,8 +61,8 @@ class EncryptedConnectionData {
6161

6262
bool connectedTo(const uint8_t *peerMac) const;
6363

64-
void setHashKey(const uint8_t hashKey[EspnowProtocolInterpreter::espnowHashKeyLength]);
65-
// @param resultArray At least size espnowHashKeyLength.
64+
void setHashKey(const uint8_t hashKey[EspnowProtocolInterpreter::hashKeyLength]);
65+
// @param resultArray At least size hashKeyLength.
6666
uint8_t *getHashKey(uint8_t *resultArray) const;
6767

6868
void setPeerSessionKey(const uint64_t sessionKey);
@@ -90,7 +90,7 @@ class EncryptedConnectionData {
9090
uint8_t _peerApMac[6] {0};
9191
uint64_t _peerSessionKey;
9292
uint64_t _ownSessionKey;
93-
uint8_t _hashKey[EspnowProtocolInterpreter::espnowHashKeyLength] {0};
93+
uint8_t _hashKey[EspnowProtocolInterpreter::hashKeyLength] {0};
9494
bool _desync = false;
9595
std::unique_ptr<ExpiringTimeTracker> _timeTracker = nullptr;
9696
};

libraries/ESP8266WiFiMesh/src/EncryptedConnectionLog.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,16 @@
2424

2525
#include "EncryptedConnectionLog.h"
2626

27-
using EspnowProtocolInterpreter::espnowHashKeyLength;
27+
namespace
28+
{
29+
using EspnowProtocolInterpreter::hashKeyLength;
30+
}
2831

29-
EncryptedConnectionLog::EncryptedConnectionLog(const uint8_t peerStaMac[6], const uint8_t peerApMac[6], const uint64_t peerSessionKey, const uint64_t ownSessionKey, const uint8_t hashKey[espnowHashKeyLength])
32+
EncryptedConnectionLog::EncryptedConnectionLog(const uint8_t peerStaMac[6], const uint8_t peerApMac[6], const uint64_t peerSessionKey, const uint64_t ownSessionKey, const uint8_t hashKey[hashKeyLength])
3033
: EncryptedConnectionData(peerStaMac, peerApMac, peerSessionKey, ownSessionKey, hashKey)
3134
{ }
3235

33-
EncryptedConnectionLog::EncryptedConnectionLog(const uint8_t peerStaMac[6], const uint8_t peerApMac[6], const uint64_t peerSessionKey, const uint64_t ownSessionKey, const uint32_t duration, const uint8_t hashKey[espnowHashKeyLength])
36+
EncryptedConnectionLog::EncryptedConnectionLog(const uint8_t peerStaMac[6], const uint8_t peerApMac[6], const uint64_t peerSessionKey, const uint64_t ownSessionKey, const uint32_t duration, const uint8_t hashKey[hashKeyLength])
3437
: EncryptedConnectionData(peerStaMac, peerApMac, peerSessionKey, ownSessionKey, duration, hashKey)
3538
{ }
3639

libraries/ESP8266WiFiMesh/src/EncryptedConnectionLog.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ class EncryptedConnectionLog : public EncryptedConnectionData {
3333
public:
3434

3535
EncryptedConnectionLog(const uint8_t peerStaMac[6], const uint8_t peerApMac[6], const uint64_t peerSessionKey, const uint64_t ownSessionKey,
36-
const uint8_t hashKey[EspnowProtocolInterpreter::espnowHashKeyLength]);
36+
const uint8_t hashKey[EspnowProtocolInterpreter::hashKeyLength]);
3737
EncryptedConnectionLog(const uint8_t peerStaMac[6], const uint8_t peerApMac[6], const uint64_t peerSessionKey, const uint64_t ownSessionKey,
38-
const uint32_t duration, const uint8_t hashKey[EspnowProtocolInterpreter::espnowHashKeyLength]);
38+
const uint32_t duration, const uint8_t hashKey[EspnowProtocolInterpreter::hashKeyLength]);
3939

4040
// Only guaranteed to expire at the latest when the soonestExpiringConnection does. Can expire before the soonestExpiringConnection since it is not updated on connection removal.
4141
// Needs to be a copy to avoid invalidation during operations on temporaryEncryptedConnections.

0 commit comments

Comments
 (0)