|
@@ -17,9 +17,12 @@
|
|
|
#include "Constants.hpp"
|
|
|
#include "TriviallyCopyable.hpp"
|
|
|
#include "Address.hpp"
|
|
|
+#include "Utils.hpp"
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
+#define ZT_FINGERPRINT_STRING_BUFFER_LENGTH 96
|
|
|
+
|
|
|
namespace ZeroTier {
|
|
|
|
|
|
class Identity;
|
|
@@ -54,6 +57,41 @@ public:
|
|
|
*/
|
|
|
ZT_ALWAYS_INLINE void getAPIFingerprint(ZT_Fingerprint *fp) const noexcept { memcpy(fp,&_fp,sizeof(ZT_Fingerprint)); }
|
|
|
|
|
|
+ /**
|
|
|
+ * @return Pointer to ZT_Fingerprint for API use
|
|
|
+ */
|
|
|
+ ZT_ALWAYS_INLINE const ZT_Fingerprint *apiFingerprint() const noexcept { return &_fp; }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Get a base32-encoded representation of this fingerprint
|
|
|
+ *
|
|
|
+ * @param s Base32 string
|
|
|
+ */
|
|
|
+ ZT_ALWAYS_INLINE void toString(char s[ZT_FINGERPRINT_STRING_BUFFER_LENGTH])
|
|
|
+ {
|
|
|
+ uint8_t tmp[48 + 5];
|
|
|
+ address().copyTo(tmp);
|
|
|
+ memcpy(tmp + 5,_fp.hash,48);
|
|
|
+ Utils::b32e(tmp,sizeof(tmp),s,ZT_FINGERPRINT_STRING_BUFFER_LENGTH);
|
|
|
+ s[ZT_FINGERPRINT_STRING_BUFFER_LENGTH-1] = 0; // sanity check, ensure always zero terminated
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Set this fingerprint to a base32-encoded string
|
|
|
+ *
|
|
|
+ * @param s String to decode
|
|
|
+ * @return True if string appears to be valid and of the proper length (no other checking is done)
|
|
|
+ */
|
|
|
+ ZT_ALWAYS_INLINE bool fromString(const char *s)
|
|
|
+ {
|
|
|
+ uint8_t tmp[48 + 5];
|
|
|
+ if (Utils::b32d(s,tmp,sizeof(tmp)) != sizeof(tmp))
|
|
|
+ return false;
|
|
|
+ _fp.address = Address(tmp).toInt();
|
|
|
+ memcpy(_fp.hash,tmp + 5,48);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
ZT_ALWAYS_INLINE void zero() noexcept { memoryZero(this); }
|
|
|
ZT_ALWAYS_INLINE unsigned long hashCode() const noexcept { return _fp.address; }
|
|
|
|