Some cleanup.

This commit is contained in:
Adam Ierymenko 2021-04-12 19:17:19 -04:00
parent 8d9067e982
commit 37d706b635
No known key found for this signature in database
GPG key ID: C8877CF2D7A5D7F3
7 changed files with 33 additions and 68 deletions

View file

@ -55,11 +55,9 @@ int CapabilityCredential::marshal(uint8_t data[ZT_CAPABILITY_MARSHAL_SIZE_MAX],
}
Utils::storeBigEndian<uint64_t>(data + p, m_nwid);
p += 8;
Utils::storeBigEndian<uint64_t>(data + p, (uint64_t) m_timestamp);
p += 8;
Utils::storeBigEndian<uint32_t>(data + p, m_id);
p += 4;
Utils::storeBigEndian<uint64_t>(data + p + 8, (uint64_t) m_timestamp);
Utils::storeBigEndian<uint32_t>(data + p + 16, m_id);
p += 20;
Utils::storeBigEndian<uint16_t>(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<uint16_t>(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)

View file

@ -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<uint64_t>(data + p, 0);
p += 8;
Utils::storeBigEndian<uint64_t>(data + p, (uint64_t) m_timestamp);
p += 8;
Utils::storeBigEndian<uint64_t>(data + p, (uint64_t) m_timestampMaxDelta);
p += 8;
Utils::storeBigEndian<uint64_t>(data + p, 1);
p += 8;
Utils::storeBigEndian<uint64_t>(data + p, m_networkId);
p += 8;
Utils::storeBigEndian<uint64_t>(data + p, 0);
p += 8;
Utils::storeBigEndian<uint64_t>(data + p, 2);
p += 8;
Utils::storeBigEndian<uint64_t>(data + p, m_issuedTo.address);
p += 8;
Utils::storeMachineEndian< uint64_t >(data + p, 0xffffffffffffffffULL);
p += 8;
Utils::storeBigEndian<uint64_t>(data + p + 8, (uint64_t) m_timestamp);
Utils::storeBigEndian<uint64_t>(data + p + 16, (uint64_t) m_timestampMaxDelta);
Utils::storeBigEndian<uint64_t>(data + p + 24, 1);
Utils::storeBigEndian<uint64_t>(data + p + 32, m_networkId);
Utils::storeBigEndian<uint64_t>(data + p + 40, 0);
Utils::storeBigEndian<uint64_t>(data + p + 48, 2);
Utils::storeBigEndian<uint64_t>(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<uint16_t>(data + 1, 9);
for (int k = 0;k < 6;++k) {
Utils::storeBigEndian<uint64_t>(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<uint16_t>(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);

View file

@ -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; }

View file

@ -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);

View file

@ -65,8 +65,7 @@ public:
m_signedBy(),
m_type(ct),
m_signatureLength(0)
{
}
{}
ZT_INLINE uint32_t id() const noexcept
{ return m_id; }

View file

@ -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);

View file

@ -69,8 +69,7 @@ public:
m_issuedTo(issuedTo),
m_signedBy(),
m_signatureLength(0)
{
}
{}
ZT_INLINE uint32_t id() const noexcept
{ return m_id; }