From 94f897deeaa6eda4b7982a958287c5c8fa2ce435 Mon Sep 17 00:00:00 2001 From: Michael Lotz Date: Sun, 8 Jan 2012 01:17:02 +0100 Subject: [PATCH] Make Flatten/Unflatten public and remove IsRegistered(). The BKey doesn't know anything about the keyring concept, so the registered info isn't really useful. May be re-added later with keyring info as well. --- headers/os/app/Key.h | 9 ++-- src/kits/app/Key.cpp | 97 +++++++++++++++++++-------------------- src/kits/app/KeyStore.cpp | 16 +++---- 3 files changed, 59 insertions(+), 63 deletions(-) diff --git a/headers/os/app/Key.h b/headers/os/app/Key.h index 0f4110e2c5..35f166ec14 100644 --- a/headers/os/app/Key.h +++ b/headers/os/app/Key.h @@ -67,7 +67,9 @@ public: const char* Owner() const; bigtime_t CreationTime() const; - bool IsRegistered() const; + + virtual status_t Flatten(BMessage& message) const; + virtual status_t Unflatten(const BMessage& message); BKey& operator=(const BKey& other); @@ -76,10 +78,6 @@ public: virtual void PrintToStream(); -protected: - virtual status_t _Flatten(BMessage& message) const; - virtual status_t _Unflatten(const BMessage& message); - private: friend class BKeyStore; @@ -89,7 +87,6 @@ private: BString fOwner; bigtime_t fCreationTime; mutable BMallocIO fData; - bool fRegistered; }; diff --git a/src/kits/app/Key.cpp b/src/kits/app/Key.cpp index 3d0df5ffb0..a9d8d16e9e 100644 --- a/src/kits/app/Key.cpp +++ b/src/kits/app/Key.cpp @@ -52,6 +52,13 @@ BKey::~BKey() } +void +BKey::Unset() +{ + SetTo(B_KEY_PURPOSE_GENERIC, "", "", NULL, 0); +} + + status_t BKey::SetTo(BKeyPurpose purpose, const char* identifier, const char* secondaryIdentifier, const uint8* data, size_t length) @@ -157,10 +164,47 @@ BKey::CreationTime() const } -bool -BKey::IsRegistered() const +status_t +BKey::Flatten(BMessage& message) const { - return fRegistered; + if (message.MakeEmpty() != B_OK + || message.AddUInt32("type", Type()) != B_OK + || message.AddUInt32("purpose", fPurpose) != B_OK + || message.AddString("identifier", fIdentifier) != B_OK + || message.AddString("secondaryIdentifier", fSecondaryIdentifier) + != B_OK + || message.AddString("owner", fOwner) != B_OK + || message.AddInt64("creationTime", fCreationTime) != B_OK + || message.AddData("data", B_RAW_TYPE, fData.Buffer(), + fData.BufferLength()) != B_OK) { + return B_ERROR; + } + + return B_OK; +} + + +status_t +BKey::Unflatten(const BMessage& message) +{ + BKeyType type; + if (message.FindUInt32("type", (uint32*)&type) != B_OK || type != Type()) + return B_BAD_VALUE; + + const void* data = NULL; + ssize_t dataLength = 0; + if (message.FindUInt32("purpose", (uint32*)&fPurpose) != B_OK + || message.FindString("identifier", &fIdentifier) != B_OK + || message.FindString("secondaryIdentifier", &fSecondaryIdentifier) + != B_OK + || message.FindString("owner", &fOwner) != B_OK + || message.FindInt64("creationTime", &fCreationTime) != B_OK + || message.FindData("data", B_RAW_TYPE, &data, &dataLength) != B_OK + || dataLength < 0) { + return B_ERROR; + } + + return SetData((const uint8*)data, (size_t)dataLength); } @@ -173,8 +217,7 @@ BKey::operator=(const BKey& other) fIdentifier = other.fIdentifier; fSecondaryIdentifier = other.fSecondaryIdentifier; fOwner = other.fOwner; - fCreationTime = other.CreationTime(); - fRegistered = other.IsRegistered(); + fCreationTime = other.fCreationTime; return *this; } @@ -237,50 +280,6 @@ BKey::PrintToStream() } -status_t -BKey::_Flatten(BMessage& message) const -{ - if (message.MakeEmpty() != B_OK - || message.AddUInt32("type", Type()) != B_OK - || message.AddUInt32("purpose", fPurpose) != B_OK - || message.AddString("identifier", fIdentifier) != B_OK - || message.AddString("secondaryIdentifier", fSecondaryIdentifier) - != B_OK - || message.AddString("owner", fOwner) != B_OK - || message.AddInt64("creationTime", fCreationTime) != B_OK - || message.AddData("data", B_RAW_TYPE, fData.Buffer(), - fData.BufferLength()) != B_OK) { - return B_ERROR; - } - - return B_OK; -} - - -status_t -BKey::_Unflatten(const BMessage& message) -{ - BKeyType type; - if (message.FindUInt32("type", (uint32*)&type) != B_OK || type != Type()) - return B_BAD_VALUE; - - const void* data = NULL; - ssize_t dataLength = 0; - if (message.FindUInt32("purpose", (uint32*)&fPurpose) != B_OK - || message.FindString("identifier", &fIdentifier) != B_OK - || message.FindString("secondaryIdentifier", &fSecondaryIdentifier) - != B_OK - || message.FindString("owner", &fOwner) != B_OK - || message.FindInt64("creationTime", &fCreationTime) != B_OK - || message.FindData("data", B_RAW_TYPE, &data, &dataLength) != B_OK - || dataLength < 0) { - return B_ERROR; - } - - return SetData((const uint8*)data, (size_t)dataLength); -} - - // #pragma mark - BPasswordKey diff --git a/src/kits/app/KeyStore.cpp b/src/kits/app/KeyStore.cpp index 04309bb317..dea28718a1 100644 --- a/src/kits/app/KeyStore.cpp +++ b/src/kits/app/KeyStore.cpp @@ -93,7 +93,7 @@ BKeyStore::GetKey(const char* keyring, BKeyType type, BKeyPurpose purpose, if (reply.FindMessage("key", &keyMessage) != B_OK) return B_ERROR; - return key._Unflatten(keyMessage); + return key.Unflatten(keyMessage); } @@ -108,7 +108,7 @@ status_t BKeyStore::AddKey(const char* keyring, const BKey& key) { BMessage keyMessage; - if (key._Flatten(keyMessage) != B_OK) + if (key.Flatten(keyMessage) != B_OK) return B_BAD_VALUE; BMessage message(KEY_STORE_ADD_KEY); @@ -130,7 +130,7 @@ status_t BKeyStore::RemoveKey(const char* keyring, const BKey& key) { BMessage keyMessage; - if (key._Flatten(keyMessage) != B_OK) + if (key.Flatten(keyMessage) != B_OK) return B_BAD_VALUE; BMessage message(KEY_STORE_REMOVE_KEY); @@ -183,7 +183,7 @@ BKeyStore::GetNextKey(const char* keyring, BKeyType type, BKeyPurpose purpose, return B_ERROR; reply.FindUInt32("cookie", &cookie); - return key._Unflatten(keyMessage); + return key.Unflatten(keyMessage); } @@ -194,7 +194,7 @@ status_t BKeyStore::AddKeyring(const char* keyring, const BKey& key) { BMessage keyMessage; - if (key._Flatten(keyMessage) != B_OK) + if (key.Flatten(keyMessage) != B_OK) return B_BAD_VALUE; BMessage message(KEY_STORE_ADD_KEYRING); @@ -240,7 +240,7 @@ status_t BKeyStore::SetMasterKey(const BKey& key) { BMessage keyMessage; - if (key._Flatten(keyMessage) != B_OK) + if (key.Flatten(keyMessage) != B_OK) return B_BAD_VALUE; BMessage message(KEY_STORE_SET_MASTER_KEY); @@ -341,7 +341,7 @@ BKeyStore::GetNextApplication(const BKey& key, uint32& cookie, BString& signature) const { BMessage keyMessage; - if (key._Flatten(keyMessage) != B_OK) + if (key.Flatten(keyMessage) != B_OK) return B_BAD_VALUE; BMessage message(KEY_STORE_GET_NEXT_APPLICATION); @@ -365,7 +365,7 @@ status_t BKeyStore::RemoveApplication(const BKey& key, const char* signature) { BMessage keyMessage; - if (key._Flatten(keyMessage) != B_OK) + if (key.Flatten(keyMessage) != B_OK) return B_BAD_VALUE; BMessage message(KEY_STORE_REMOVE_APPLICATION);