// ---------------------------------------------------
-
void CryptoKey::encode(bufferlist& bl) const
{
using ceph::encode;
+ const bufferptr &secret = get_secret();
encode(type, bl);
encode(created, bl);
__u16 len = secret.length();
int CryptoKey::_set_secret(int t, const bufferptr& s)
{
if (s.length() == 0) {
- secret = s;
+// secret = s;
ckh.reset();
return 0;
}
return -EOPNOTSUPP;
}
type = t;
- secret = s;
+// secret = s;
return 0;
}
void CryptoKey::to_str(std::string& s) const
{
+ const bufferptr &secret = get_secret();
int len = secret.length() * 4;
char buf[len];
hex2str(secret.c_str(), secret.length(), buf, len);
bl.append(encode_base64());
}
+static bufferptr z;
+
+const bufferptr& CryptoKey::get_secret() const
+{
+ const bufferptr &secret = ckh ? ckh->secret : z;
+ return secret;
+}
+
// ------------------
virtual ~CryptoKeyHandler() {}
+ operator bool()const {
+ return secret.length() > 0;
+ }
+
+ bool operator==(const CryptoKeyHandler &rhs) const {
+ return 0 == secret.cmp(rhs.secret);
+ }
+
virtual int encrypt(CephContext *cct,
const ceph::buffer::list& in,
ceph::buffer::list& out, std::string *error) const {
protected:
__u16 type;
utime_t created;
- ceph::buffer::ptr secret; // must set this via set_secret()!
+// ceph::buffer::ptr secret; // must set this via set_secret()!
// cache a pointer to the implementation-specific key handler, so we
// don't have to create it for every crypto operation.
~CryptoKey() {
}
+ operator bool()const {
+ return ckh && *ckh;
+ }
+ bool operator==(const CryptoKey &rhs) const {
+ return !ckh ? !rhs.ckh
+ : rhs.ckh && *ckh == *rhs.ckh;
+ }
void encode(ceph::buffer::list& bl) const;
void decode(ceph::buffer::list::const_iterator& bl);
void dump(ceph::Formatter *f) const;
void print(std::ostream& out) const;
int set_secret(int type, const ceph::buffer::ptr& s, utime_t created);
- const ceph::buffer::ptr& get_secret() { return secret; }
- const ceph::buffer::ptr& get_secret() const { return secret; }
+// const ceph::buffer::ptr& get_secret() { return secret; }
+// const ceph::buffer::ptr& get_secret() const { return secret; }
bool empty() const { return ckh.get() == nullptr; }
}
void to_str(std::string& s) const;
+private:
+ const ceph::bufferptr& get_secret() const;
};
WRITE_CLASS_ENCODER(CryptoKey)