Test certificate copy/construct.

This commit is contained in:
Adam Ierymenko 2020-06-30 23:20:50 -07:00
parent 6af39da61a
commit 9029570452
No known key found for this signature in database
GPG key ID: C8877CF2D7A5D7F3
3 changed files with 17 additions and 14 deletions

View file

@ -185,6 +185,14 @@ void Certificate::addSubjectUpdateUrl(const char *url)
this->subject.updateUrlCount = (unsigned int)m_updateUrls.size();
}
void Certificate::setExtendedAttributes(const Dictionary &x)
{
m_extendedAttributes.clear();
x.encode(m_extendedAttributes);
this->extendedAttributes = m_extendedAttributes.data();
this->extendedAttributesSize = (unsigned int)m_extendedAttributes.size();
}
Vector< uint8_t > Certificate::encode(const bool omitSignature) const
{
Vector< uint8_t > enc;

View file

@ -48,16 +48,12 @@ namespace ZeroTier {
class Certificate : public ZT_Certificate
{
friend class SharedPtr< Certificate >;
friend class SharedPtr< const Certificate >;
public:
Certificate() noexcept;
Certificate(const ZT_Certificate &apiCert);
Certificate(const Certificate &cert);
~Certificate();
Certificate &operator=(const ZT_Certificate &cert);
@ -116,13 +112,7 @@ public:
*
* @param x Extended attributes (set by issuer)
*/
ZT_INLINE void setExtendedAttributes(const Dictionary &x)
{
m_extendedAttributes.clear();
x.encode(m_extendedAttributes);
this->extendedAttributes = m_extendedAttributes.data();
this->extendedAttributesSize = (unsigned int)m_extendedAttributes.size();
}
void setExtendedAttributes(const Dictionary &x);
/**
* Marshal this certificate in binary form

View file

@ -1161,9 +1161,14 @@ extern "C" const char *ZTT_crypto()
return "Verify decoded certificate";
}
ZT_T_PRINTF("OK" ZT_EOL_S);
cert.zero();
cert2.zero();
ZT_T_PRINTF(" Test certificate copy/construct... ");
SharedPtr<Certificate> cert3(new Certificate(*cert2));
if (!ZTT_deepCompareCertificates(*cert2, *cert3)) {
ZT_T_PRINTF("FAILED (compare copy with original)" ZT_EOL_S);
return "Certificate copy";
}
ZT_T_PRINTF("OK" ZT_EOL_S);
}
} catch (std::exception &e) {
ZT_T_PRINTF(ZT_EOL_S "[crypto] Unexpected exception: %s" ZT_EOL_S, e.what());