]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
authtool: print encoded CryptoKey in base64
authorSage Weil <sage@newdream.net>
Tue, 27 Oct 2009 19:38:43 +0000 (12:38 -0700)
committerSage Weil <sage@newdream.net>
Tue, 27 Oct 2009 19:38:43 +0000 (12:38 -0700)
src/auth/Crypto.h
src/authtool.cc
src/common/buffer.cc
src/include/buffer.h

index 7aff492747ec7356c999f4ac9e58070d077ab759..05875298a37a92db7b63862bbdfdcf91e682aa79 100644 (file)
@@ -51,6 +51,15 @@ public:
   int set_secret(int type, bufferptr& s);
   bufferptr& get_secret() { return secret; }
 
+  void encode_base64(string& s) {
+    bufferlist bl;
+    encode(bl);
+    bufferlist e;
+    bl.encode_base64(e);
+    e.append('\0');
+    s = e.c_str();
+  }
+
   // --
   int create(int type);
   int encrypt(const bufferlist& in, bufferlist& out);
index 1eef7d2fe826357f57bac62991127cba3450ec31..9b0950f8470e16807a3303c7cbeee73c13ea29cb 100644 (file)
@@ -115,8 +115,11 @@ int main(int argc, const char **argv)
       }
     }
   } else if (print_key) {
-    if (keys_map.count(s))
-      cout << keys_map[s].key << std::endl;
+    if (keys_map.count(s)) {
+      string a;
+      keys_map[s].key.encode_base64(a);
+      cout << a << std::endl;
+    }
     else
       cerr << "entity " << s << " not found" << std::endl;
   }
index ea079ecdd1a0767e800168b3a96c892c3d310215..6fbfa06a1f9a8906665b6a1198a026725b0c4a4a 100644 (file)
 
 #include "config.h"
 #include "include/types.h"
+#include "armor.h"
 
 #include <errno.h>
 #include <fstream>
 
 atomic_t buffer_total_alloc;
 
+
+void buffer::list::encode_base64(buffer::list& o)
+{
+  bufferptr bp(length() * 4 / 3 + 1);
+  int l = ceph_armor(bp.c_str(), c_str(), c_str() + length());
+  bp.set_length(l);
+  o.push_back(bp);
+}
+
+
 int buffer::list::read_file(const char *fn, bool silent)
 {
   struct stat st;
index c0720ace3edb6d6c91c166da1b2c1280f15f4d28..08d87233fbdf81a822aa00c403b5ab80331fa180 100644 (file)
@@ -1088,6 +1088,8 @@ public:
        }*/
     }
 
+    void encode_base64(list& o);
+
     void hexdump(std::ostream &out);
     int read_file(const char *fn, bool silent=false);
     int write_file(const char *fn);