From c494c06109579891eacfd6f63506b0047963fde0 Mon Sep 17 00:00:00 2001 From: Michael Lotz Date: Wed, 4 Jan 2012 13:57:17 +0100 Subject: [PATCH] Add B*Key::PrintToStream() method for debugging convenience. --- headers/os/app/Key.h | 4 ++++ src/kits/app/Key.cpp | 45 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/headers/os/app/Key.h b/headers/os/app/Key.h index 147104223b..ffd66c83ea 100644 --- a/headers/os/app/Key.h +++ b/headers/os/app/Key.h @@ -73,6 +73,8 @@ public: bool operator==(const BKey& other) const; bool operator!=(const BKey& other) const; + virtual void PrintToStream(); + protected: virtual status_t _Flatten(BMessage& message) const; virtual status_t _Unflatten(const BMessage& message); @@ -108,6 +110,8 @@ public: status_t SetPassword(const char* password); const char* Password() const; + + virtual void PrintToStream(); }; #endif // _KEY_H diff --git a/src/kits/app/Key.cpp b/src/kits/app/Key.cpp index a112e74c12..b575255d18 100644 --- a/src/kits/app/Key.cpp +++ b/src/kits/app/Key.cpp @@ -6,6 +6,8 @@ #include +#include + #if 0 // TODO: move this to the KeyStore or the registrar backend if needed @@ -198,6 +200,40 @@ BKey::operator!=(const BKey& other) const } +void +BKey::PrintToStream() +{ + if (Type() == B_KEY_TYPE_GENERIC) + printf("generic key:\n"); + + const char* purposeString = "unknown"; + switch (fPurpose) { + case B_KEY_PURPOSE_ANY: + purposeString = "any"; + break; + case B_KEY_PURPOSE_GENERIC: + purposeString = "generic"; + break; + case B_KEY_PURPOSE_WEB: + purposeString = "web"; + break; + case B_KEY_PURPOSE_NETWORK: + purposeString = "network"; + break; + case B_KEY_PURPOSE_VOLUME: + purposeString = "volume"; + break; + } + + printf("\tpurpose: %s\n", purposeString); + printf("\tidentifier: \"%s\"\n", fIdentifier.String()); + printf("\tsecondary identifier: \"%s\"\n", fSecondaryIdentifier.String()); + printf("\towner: \"%s\"\n", fOwner.String()); + printf("\tcreation time: %" B_PRIu64 "\n", fCreationTime); + printf("\traw data length: %" B_PRIuSIZE "\n", fData.BufferLength()); +} + + status_t BKey::_Flatten(BMessage& message) const { @@ -290,3 +326,12 @@ BPasswordKey::Password() const { return (const char*)Data(); } + + +void +BPasswordKey::PrintToStream() +{ + printf("password key:\n"); + BKey::PrintToStream(); + printf("\tpassword: \"%s\"\n", Password()); +}