Przeglądaj źródła

Test certificate copy/construct.

Adam Ierymenko 5 lat temu
rodzic
commit
9029570452
3 zmienionych plików z 17 dodań i 14 usunięć
  1. 8 0
      core/Certificate.cpp
  2. 1 11
      core/Certificate.hpp
  3. 8 3
      core/Tests.cpp

+ 8 - 0
core/Certificate.cpp

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

+ 1 - 11
core/Certificate.hpp

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

+ 8 - 3
core/Tests.cpp

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