From: Dan Mick Date: Wed, 10 Jul 2013 23:31:19 +0000 (-0700) Subject: auth: Crypto: add encode_formatted/plaintext() functions X-Git-Tag: v0.67-rc1~107 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=92d5eb08b420a727d5adde9cd7e422ff00841f51;p=ceph.git auth: Crypto: add encode_formatted/plaintext() functions Signed-off-by: Joao Eduardo Luis --- diff --git a/src/auth/Crypto.cc b/src/auth/Crypto.cc index cf2a75d61265..7c74b80e81d7 100644 --- a/src/auth/Crypto.cc +++ b/src/auth/Crypto.cc @@ -373,9 +373,7 @@ void CryptoKey::decrypt(CephContext *cct, const bufferlist& in, bufferlist& out, void CryptoKey::print(std::ostream &out) const { - string a; - encode_base64(a); - out << a; + out << encode_base64(); } void CryptoKey::to_str(std::string& s) const @@ -385,3 +383,16 @@ void CryptoKey::to_str(std::string& s) const hex2str(secret.c_str(), secret.length(), buf, len); s = buf; } + +void CryptoKey::encode_formatted(string label, Formatter *f, bufferlist &bl) +{ + f->open_object_section(label.c_str()); + f->dump_string("key", encode_base64()); + f->close_section(); + f->flush(bl); +} + +void CryptoKey::encode_plaintext(bufferlist &bl) +{ + bl.append(encode_base64()); +} diff --git a/src/auth/Crypto.h b/src/auth/Crypto.h index d984d6a08981..f0fc97b59345 100644 --- a/src/auth/Crypto.h +++ b/src/auth/Crypto.h @@ -18,6 +18,9 @@ #include "include/types.h" #include "include/utime.h" +#include "common/Formatter.h" +#include "include/buffer.h" + #include class CephContext; @@ -72,6 +75,11 @@ public: e.append('\0'); s = e.c_str(); } + string encode_base64() const { + string s; + encode_base64(s); + return s; + } void decode_base64(const string& s) { bufferlist e; e.append(s); @@ -81,6 +89,9 @@ public: decode(p); } + void encode_formatted(string label, Formatter *f, bufferlist &bl); + void encode_plaintext(bufferlist &bl); + // -- int create(CephContext *cct, int type); void encrypt(CephContext *cct, const bufferlist& in, bufferlist& out, std::string &error) const;