From 37d706b6353ed1c7782f8e0743949bb0bcbdfc7b Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Mon, 12 Apr 2021 19:17:19 -0400 Subject: [PATCH] Some cleanup. --- core/CapabilityCredential.cpp | 17 +++++++---------- core/MembershipCredential.cpp | 36 +++++++++++++---------------------- core/Path.hpp | 11 ----------- core/RevocationCredential.cpp | 20 +++++++------------ core/RevocationCredential.hpp | 3 +-- core/TagCredential.cpp | 11 ++++------- core/TagCredential.hpp | 3 +-- 7 files changed, 33 insertions(+), 68 deletions(-) diff --git a/core/CapabilityCredential.cpp b/core/CapabilityCredential.cpp index c37afa3b4..2b855120f 100644 --- a/core/CapabilityCredential.cpp +++ b/core/CapabilityCredential.cpp @@ -55,11 +55,9 @@ int CapabilityCredential::marshal(uint8_t data[ZT_CAPABILITY_MARSHAL_SIZE_MAX], } Utils::storeBigEndian(data + p, m_nwid); - p += 8; - Utils::storeBigEndian(data + p, (uint64_t) m_timestamp); - p += 8; - Utils::storeBigEndian(data + p, m_id); - p += 4; + Utils::storeBigEndian(data + p + 8, (uint64_t) m_timestamp); + Utils::storeBigEndian(data + p + 16, m_id); + p += 20; Utils::storeBigEndian(data + p, (uint16_t) m_ruleCount); p += 2; @@ -67,18 +65,17 @@ int CapabilityCredential::marshal(uint8_t data[ZT_CAPABILITY_MARSHAL_SIZE_MAX], // LEGACY: older versions supported multiple records with this being a maximum custody // chain length. This is deprecated so set the max chain length to one. - data[p++] = (uint8_t) 1; + data[p++] = (uint8_t)1; if (!forSign) { m_issuedTo.copyTo(data + p); - p += ZT_ADDRESS_LENGTH; - m_signedBy.copyTo(data + 0); - p += ZT_ADDRESS_LENGTH; + m_signedBy.copyTo(data + p + ZT_ADDRESS_LENGTH); + p += ZT_ADDRESS_LENGTH + ZT_ADDRESS_LENGTH; data[p++] = 1; // LEGACY: old versions require a reserved byte here Utils::storeBigEndian(data + p, (uint16_t) m_signatureLength); p += 2; Utils::copy(data + p, m_signature, m_signatureLength); - p += (int) m_signatureLength; + p += (int)m_signatureLength; // LEGACY: older versions supported more than one record terminated by a zero address. for (int k = 0;k < ZT_ADDRESS_LENGTH;++k) diff --git a/core/MembershipCredential.cpp b/core/MembershipCredential.cpp index f5eac7d89..c4ae26da9 100644 --- a/core/MembershipCredential.cpp +++ b/core/MembershipCredential.cpp @@ -102,23 +102,15 @@ int MembershipCredential::marshal(uint8_t data[ZT_MEMBERSHIP_CREDENTIAL_MARSHAL_ // equality compare, and the address of the issued-to node as an informational tuple. int p = 3; Utils::storeBigEndian(data + p, 0); - p += 8; - Utils::storeBigEndian(data + p, (uint64_t) m_timestamp); - p += 8; - Utils::storeBigEndian(data + p, (uint64_t) m_timestampMaxDelta); - p += 8; - Utils::storeBigEndian(data + p, 1); - p += 8; - Utils::storeBigEndian(data + p, m_networkId); - p += 8; - Utils::storeBigEndian(data + p, 0); - p += 8; - Utils::storeBigEndian(data + p, 2); - p += 8; - Utils::storeBigEndian(data + p, m_issuedTo.address); - p += 8; - Utils::storeMachineEndian< uint64_t >(data + p, 0xffffffffffffffffULL); - p += 8; + Utils::storeBigEndian(data + p + 8, (uint64_t) m_timestamp); + Utils::storeBigEndian(data + p + 16, (uint64_t) m_timestampMaxDelta); + Utils::storeBigEndian(data + p + 24, 1); + Utils::storeBigEndian(data + p + 32, m_networkId); + Utils::storeBigEndian(data + p + 40, 0); + Utils::storeBigEndian(data + p + 48, 2); + Utils::storeBigEndian(data + p + 56, m_issuedTo.address); + Utils::storeMachineEndian< uint64_t >(data + p + 64, 0xffffffffffffffffULL); + p += 72; if (v2) { // V2 marshal format will have three tuples followed by the fingerprint hash. @@ -130,11 +122,9 @@ int MembershipCredential::marshal(uint8_t data[ZT_MEMBERSHIP_CREDENTIAL_MARSHAL_ Utils::storeBigEndian(data + 1, 9); for (int k = 0;k < 6;++k) { Utils::storeBigEndian(data + p, (uint64_t) k + 3); - p += 8; - Utils::storeMachineEndian< uint64_t >(data + p, Utils::loadMachineEndian< uint64_t >(m_issuedTo.hash + (k * 8))); - p += 8; - Utils::storeMachineEndian< uint64_t >(data + p, 0xffffffffffffffffULL); - p += 8; + Utils::storeMachineEndian< uint64_t >(data + p + 8, Utils::loadMachineEndian< uint64_t >(m_issuedTo.hash + (k * 8))); + Utils::storeMachineEndian< uint64_t >(data + p + 16, 0xffffffffffffffffULL); + p += 24; } } @@ -146,7 +136,7 @@ int MembershipCredential::marshal(uint8_t data[ZT_MEMBERSHIP_CREDENTIAL_MARSHAL_ Utils::storeBigEndian(data + p, (uint16_t) m_signatureLength); p += 2; Utils::copy(data + p, m_signature, m_signatureLength); - p += (int) m_signatureLength; + p += (int)m_signatureLength; } else { // V1 only supports 96-byte signature fields. Utils::copy<96>(data + p, m_signature); diff --git a/core/Path.hpp b/core/Path.hpp index 67b272050..5934b0c8b 100644 --- a/core/Path.hpp +++ b/core/Path.hpp @@ -55,9 +55,6 @@ public: ZT_INLINE Key() noexcept {} - ZT_INLINE Key(const Key &k) noexcept: m_hashCode(k.m_hashCode), m_v664(k.m_v664), m_port(k.m_port) - {} - ZT_INLINE Key(const InetAddress &ip) noexcept { const unsigned int family = ip.as.sa.sa_family; @@ -84,14 +81,6 @@ public: } } - ZT_INLINE Key &operator=(const Key &k) noexcept - { - m_hashCode = k.m_hashCode; - m_v664 = k.m_v664; - m_port = k.m_port; - return *this; - } - ZT_INLINE unsigned long hashCode() const noexcept { return (unsigned long)m_hashCode; } diff --git a/core/RevocationCredential.cpp b/core/RevocationCredential.cpp index fbfe49dc0..aff5f7935 100644 --- a/core/RevocationCredential.cpp +++ b/core/RevocationCredential.cpp @@ -34,19 +34,13 @@ int RevocationCredential::marshal(uint8_t data[ZT_REVOCATION_MARSHAL_SIZE_MAX], data[p++] = 0x7f; } Utils::storeBigEndian< uint32_t >(data + p, 0); - p += 4; - Utils::storeBigEndian< uint32_t >(data + p, m_id); - p += 4; - Utils::storeBigEndian< uint64_t >(data + p, m_networkId); - p += 8; - Utils::storeBigEndian< uint32_t >(data + p, 0); - p += 4; - Utils::storeBigEndian< uint32_t >(data + p, m_credentialId); - p += 4; - Utils::storeBigEndian< uint64_t >(data + p, (uint64_t)m_threshold); - p += 8; - Utils::storeBigEndian< uint64_t >(data + p, m_flags); - p += 8; + Utils::storeBigEndian< uint32_t >(data + p + 4, m_id); + Utils::storeBigEndian< uint64_t >(data + p + 8, m_networkId); + Utils::storeBigEndian< uint32_t >(data + p + 16, 0); + Utils::storeBigEndian< uint32_t >(data + p + 20, m_credentialId); + Utils::storeBigEndian< uint64_t >(data + p + 24, (uint64_t)m_threshold); + Utils::storeBigEndian< uint64_t >(data + p + 32, m_flags); + p += 40; m_target.copyTo(data + p); p += ZT_ADDRESS_LENGTH; m_signedBy.copyTo(data + p); diff --git a/core/RevocationCredential.hpp b/core/RevocationCredential.hpp index aa27c37da..bd8146d6a 100644 --- a/core/RevocationCredential.hpp +++ b/core/RevocationCredential.hpp @@ -65,8 +65,7 @@ public: m_signedBy(), m_type(ct), m_signatureLength(0) - { - } + {} ZT_INLINE uint32_t id() const noexcept { return m_id; } diff --git a/core/TagCredential.cpp b/core/TagCredential.cpp index 4ddc96ddd..3665983f6 100644 --- a/core/TagCredential.cpp +++ b/core/TagCredential.cpp @@ -34,13 +34,10 @@ int TagCredential::marshal(uint8_t data[ZT_TAG_MARSHAL_SIZE_MAX], bool forSign) data[p++] = 0x7f; } Utils::storeBigEndian< uint64_t >(data + p, m_networkId); - p += 8; - Utils::storeBigEndian< uint64_t >(data + p, (uint64_t)m_ts); - p += 8; - Utils::storeBigEndian< uint32_t >(data + p, m_id); - p += 4; - Utils::storeBigEndian< uint32_t >(data + p, m_value); - p += 4; + Utils::storeBigEndian< uint64_t >(data + p + 8, (uint64_t)m_ts); + Utils::storeBigEndian< uint32_t >(data + p + 16, m_id); + Utils::storeBigEndian< uint32_t >(data + p + 20, m_value); + p += 24; m_issuedTo.copyTo(data + p); p += ZT_ADDRESS_LENGTH; m_signedBy.copyTo(data + p); diff --git a/core/TagCredential.hpp b/core/TagCredential.hpp index fe6463d8c..60c5a04aa 100644 --- a/core/TagCredential.hpp +++ b/core/TagCredential.hpp @@ -69,8 +69,7 @@ public: m_issuedTo(issuedTo), m_signedBy(), m_signatureLength(0) - { - } + {} ZT_INLINE uint32_t id() const noexcept { return m_id; }