]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
auth: Crypto: add encode_formatted/plaintext() functions
authorDan Mick <dan.mick@inktank.com>
Wed, 10 Jul 2013 23:31:19 +0000 (16:31 -0700)
committerDan Mick <dan.mick@inktank.com>
Thu, 11 Jul 2013 02:02:30 +0000 (19:02 -0700)
Signed-off-by: Joao Eduardo Luis <joao.luis@inktank.com>
src/auth/Crypto.cc
src/auth/Crypto.h

index cf2a75d612653f713386cb84c22c18e94dc737a8..7c74b80e81d7ea779d57c9fc47fdadb64245e7f6 100644 (file)
@@ -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());
+}
index d984d6a089812c3fcf63f00bff90ae6287f9a4c2..f0fc97b5934508669bdd61b4aa094251a77388b6 100644 (file)
@@ -18,6 +18,9 @@
 #include "include/types.h"
 #include "include/utime.h"
 
+#include "common/Formatter.h"
+#include "include/buffer.h"
+
 #include <string>
 
 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;