From 1bfd785307684f3fc2423f87608e4a84e374b64c Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Tue, 1 Jun 2021 22:44:08 +0800 Subject: [PATCH] auth/KeyRing: always decode keying as plaintext for three reasons: * we don't encode binary KeyRing since v0.48: the binary encoder for KeyRing was dropped in eaea7aa9b28849be612b22ce84971db671319806, which was included since v0.48 (argonaut). and we don't encode KeyRing in binary manually elsewhere since then. * we should not use exception in the normal code path. in C++, exception is not designed to be efficient or semantically a language facility to be part of the normal code path. so, from the readability perspective, we should not use exception here. as all encoded KeyRings are in plaintext. * simpler this way. Signed-off-by: Kefu Chai --- src/auth/KeyRing.cc | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/auth/KeyRing.cc b/src/auth/KeyRing.cc index 2ddc0b4ab22bc..6686fa9f51af4 100644 --- a/src/auth/KeyRing.cc +++ b/src/auth/KeyRing.cc @@ -201,17 +201,10 @@ void KeyRing::decode_plaintext(bufferlist::const_iterator& bli) } } -void KeyRing::decode(bufferlist::const_iterator& bl) { - __u8 struct_v; +void KeyRing::decode(bufferlist::const_iterator& bl) +{ auto start_pos = bl; - try { - using ceph::decode; - decode(struct_v, bl); - decode(keys, bl); - } catch (ceph::buffer::error& err) { - keys.clear(); - decode_plaintext(start_pos); - } + decode_plaintext(start_pos); } int KeyRing::load(CephContext *cct, const std::string &filename) -- 2.39.5