}
}
+#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
*/
#endif
#include "inline_memory.h"
+#include <boost/optional.hpp>
#if __GNUC__ >= 4
#define CEPH_BUFFER_API __attribute__ ((visibility ("default")))
}
#endif // HAVE_SEASTAR
class deleter;
+struct sha1_digest_info_t;
namespace ceph {
}
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
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
}
if (p.get_fingerprint_type() != pg_pool_t::TYPE_FINGERPRINT_NONE) {
out << " fingerprint_algorighm " << p.get_fingerprint_name();
+ }
return out;
}