mirror of
https://github.com/ZeroTier/ZeroTierOne
synced 2025-08-19 21:03:57 -07:00
Peer serialization and related changes.
This commit is contained in:
parent
72e7e36a5b
commit
5076c49210
8 changed files with 214 additions and 90 deletions
|
@ -315,78 +315,6 @@ public:
|
|||
*/
|
||||
inline const Address &signedBy() const throw() { return _signedBy; }
|
||||
|
||||
/**
|
||||
* Serialize to std::string or compatible class
|
||||
*
|
||||
* @param b String or other class supporting push_back() and append() like std::string
|
||||
*/
|
||||
template<typename T>
|
||||
inline void serialize2(T &b) const
|
||||
{
|
||||
uint64_t tmp[3];
|
||||
char tmp2[ZT_ADDRESS_LENGTH];
|
||||
b.push_back((char)COM_UINT64_ED25519);
|
||||
b.push_back((char)((_qualifiers.size() >> 8) & 0xff));
|
||||
b.push_back((char)(_qualifiers.size() & 0xff));
|
||||
for(std::vector<_Qualifier>::const_iterator q(_qualifiers.begin());q!=_qualifiers.end();++q) {
|
||||
tmp[0] = Utils::hton(q->id);
|
||||
tmp[1] = Utils::hton(q->value);
|
||||
tmp[2] = Utils::hton(q->maxDelta);
|
||||
b.append(reinterpret_cast<const char *>(reinterpret_cast<void *>(tmp)),sizeof(tmp));
|
||||
}
|
||||
_signedBy.copyTo(tmp2,ZT_ADDRESS_LENGTH);
|
||||
b.append(tmp2,ZT_ADDRESS_LENGTH);
|
||||
if (_signedBy)
|
||||
b.append((const char *)_signature.data,_signature.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserialize from std::string::iterator or compatible iterator or char* pointer
|
||||
*
|
||||
* @param p Iterator
|
||||
* @param end End of buffer
|
||||
*/
|
||||
template<typename T>
|
||||
inline void deserialize2(T &p,const T &end)
|
||||
{
|
||||
uint64_t tmp[3];
|
||||
char tmp2[ZT_ADDRESS_LENGTH];
|
||||
unsigned int qcount;
|
||||
|
||||
_qualifiers.clear();
|
||||
_signedBy.zero();
|
||||
|
||||
if (p == end) throw std::out_of_range("incomplete certificate of membership");
|
||||
if (*(p++) != (char)COM_UINT64_ED25519) throw std::invalid_argument("unknown certificate of membership type");
|
||||
|
||||
if (p == end) throw std::out_of_range("incomplete certificate of membership");
|
||||
qcount = (unsigned int)*(p++) << 8;
|
||||
if (p == end) throw std::out_of_range("incomplete certificate of membership");
|
||||
qcount |= (unsigned int)*(p++);
|
||||
|
||||
for(unsigned int i=0;i<qcount;++i) {
|
||||
char *p2 = reinterpret_cast<char *>(reinterpret_cast<void *>(tmp));
|
||||
for(unsigned int j=0;j<sizeof(tmp);++j) {
|
||||
if (p == end) throw std::out_of_range("incomplete certificate of membership");
|
||||
*(p2++) = *(p++);
|
||||
}
|
||||
_qualifiers.push_back(_Qualifier(Utils::ntoh(tmp[0]),Utils::ntoh(tmp[1]),Utils::ntoh(tmp[2])));
|
||||
}
|
||||
|
||||
for(unsigned int j=0;j<ZT_ADDRESS_LENGTH;++j) {
|
||||
if (p == end) throw std::out_of_range("incomplete certificate of membership");
|
||||
tmp2[j] = *(p++);
|
||||
}
|
||||
_signedBy.setTo(tmp2,ZT_ADDRESS_LENGTH);
|
||||
|
||||
if (_signedBy) {
|
||||
for(unsigned int j=0;j<_signature.size();++j) {
|
||||
if (p == end) throw std::out_of_range("incomplete certificate of membership");
|
||||
_signature.data[j] = (unsigned char)*(p++);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<unsigned int C>
|
||||
inline void serialize(Buffer<C> &b) const
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue