]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common/buffer.cc: add sha1 fingerprint
authormyoungwon oh <omwmw@sk.com>
Wed, 22 Aug 2018 10:19:07 +0000 (19:19 +0900)
committermyoungwon oh <omwmw@sk.com>
Fri, 7 Sep 2018 11:57:07 +0000 (20:57 +0900)
Signed-off-by: Myoungwon Oh <omwmw@sk.com>
src/common/buffer.cc
src/include/buffer.h
src/include/types.h
src/osd/osd_types.cc

index ebd3aae511eee1a162dd3b3bc3d73acebd1d42c8..60359223afb0f865ee4c061669a60ad438b689dd 100644 (file)
@@ -2464,6 +2464,32 @@ void buffer::list::invalidate_crc()
   }
 }
 
+#include "common/ceph_crypto.h"
+using ceph::crypto::SHA1;
+
+boost::optional<sha1_digest_info_t> buffer::list::sha1()
+{
+  ptr nb;
+  unsigned pos = 0;
+  unsigned char fingerprint[CEPH_CRYPTO_SHA1_DIGESTSIZE];
+  if (_len == 0) {
+    return boost::none;
+  }
+  nb = buffer::create(_len);
+  for (std::list<ptr>::iterator it = _buffers.begin();
+       it != _buffers.end();
+       ++it) {
+    nb.copy_in(pos, it->length(), it->c_str(), false);
+    pos += it->length();
+  }
+  int size = length();
+  SHA1 sha1_gen;
+  sha1_gen.Update((const unsigned char *)nb.c_str(), size);
+  sha1_gen.Final(fingerprint);
+  sha1_digest_info_t fp_t(fingerprint);
+  return fp_t;
+}
+
 /**
  * Binary write all contents to a C++ stream
  */
index 15a062e21be90ee2232b437f80df3a6d0cf091af..9af7e7869a7fa444fdb93bdf3dc10b7648efdedc 100644 (file)
@@ -61,6 +61,7 @@
 #endif
 
 #include "inline_memory.h"
+#include <boost/optional.hpp>
 
 #if __GNUC__ >= 4
   #define CEPH_BUFFER_API  __attribute__ ((visibility ("default")))
@@ -81,6 +82,7 @@ class packet;
 }
 #endif // HAVE_SEASTAR
 class deleter;
+struct sha1_digest_info_t;
 
 namespace ceph {
 
@@ -954,6 +956,7 @@ namespace buffer CEPH_BUFFER_API {
     }
     uint32_t crc32c(uint32_t crc) const;
     void invalidate_crc();
+    boost::optional<sha1_digest_info_t> sha1(); 
 
     // These functions return a bufferlist with a pointer to a single
     // static buffer. They /must/ not outlive the memory they
index 1140e3f45a50154889194909eb2bb6def799ee0a..4bf8e0182c304a4a125096f86aa9e726132f3cc5 100644 (file)
@@ -541,5 +541,28 @@ WRITE_CLASS_ENCODER(errorcode32_t)
 WRITE_EQ_OPERATORS_1(errorcode32_t, code)
 WRITE_CMP_OPERATORS_1(errorcode32_t, code)
 
+struct sha1_digest_info_t {
+#define SHA1_DIGEST_SIZE 20
+  unsigned char v[SHA1_DIGEST_SIZE] = {0};
+
+  string to_str() const {
+    char str[SHA1_DIGEST_SIZE*2+1] = {0};
+    str[0] = '\0';
+    for (size_t i = 0; i < 20; i++) {
+      ::sprintf(&str[i*2], "%02x", static_cast<int>(v[i]));
+    }
+    return string(str);
+  }
+  sha1_digest_info_t(unsigned char *_v) {
+    memcpy(v, _v, 20);
+  };
+  sha1_digest_info_t() {}
+};
+
+inline ostream& operator<<(ostream& out, const sha1_digest_info_t& b)
+{
+  string str = b.to_str();
+  return out << str;
+}
 
 #endif
index 1228137baa3a4696ae379c4b2d7bb83d965b3b37..26e3a244250807bbf05f101746ee856cca685f7d 100644 (file)
@@ -1962,6 +1962,7 @@ ostream& operator<<(ostream& out, const pg_pool_t& p)
   }
   if (p.get_fingerprint_type() != pg_pool_t::TYPE_FINGERPRINT_NONE) {
     out << " fingerprint_algorighm " << p.get_fingerprint_name();
+  }
   return out;
 }