From 6c5d7a65899f3b322184628c2be68fd3f3fdd5da Mon Sep 17 00:00:00 2001 From: Minijackson Date: Thu, 26 Jul 2018 17:00:03 +0200 Subject: Parse Keys in SinkSH inspect --- common/storage/key.cpp | 76 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 75 insertions(+), 1 deletion(-) (limited to 'common/storage/key.cpp') diff --git a/common/storage/key.cpp b/common/storage/key.cpp index cfeb016..215e155 100644 --- a/common/storage/key.cpp +++ b/common/storage/key.cpp @@ -84,6 +84,27 @@ bool Identifier::isNull() const return uid.isNull(); } +bool Identifier::isValidInternal(const QByteArray &bytes) +{ + return !QUuid::fromRfc4122(bytes).isNull(); +} + +bool Identifier::isValidDisplay(const QByteArray &bytes) +{ + return !QUuid(bytes).isNull(); +} + +bool Identifier::isValid(const QByteArray &bytes) +{ + switch (bytes.size()) { + case Identifier::INTERNAL_REPR_SIZE: + return isValidInternal(bytes); + case Identifier::DISPLAY_REPR_SIZE: + return isValidDisplay(bytes); + } + return false; +} + bool Identifier::operator==(const Identifier &other) const { return uid == other.uid; @@ -128,6 +149,27 @@ qint64 Revision::toQint64() const return rev; } +bool Revision::isValidInternal(const QByteArray &bytes) +{ + if (bytes.size() != Revision::INTERNAL_REPR_SIZE) { + return false; + } + + bool ok; + bytes.toLongLong(&ok); + return ok; +} + +bool Revision::isValidDisplay(const QByteArray &bytes) +{ + isValidInternal(bytes); +} + +bool Revision::isValid(const QByteArray &bytes) +{ + isValidInternal(bytes); +} + bool Revision::operator==(const Revision &other) const { return rev == other.rev; @@ -191,6 +233,39 @@ bool Key::isNull() const return id.isNull(); } +bool Key::isValidInternal(const QByteArray &bytes) +{ + if (bytes.size() != Key::INTERNAL_REPR_SIZE) { + return false; + } + + auto idBytes = bytes.mid(0, Identifier::INTERNAL_REPR_SIZE); + auto revBytes = bytes.mid(Identifier::INTERNAL_REPR_SIZE); + return Identifier::isValidInternal(idBytes) && Revision::isValidInternal(revBytes); +} + +bool Key::isValidDisplay(const QByteArray &bytes) +{ + if (bytes.size() != Key::DISPLAY_REPR_SIZE) { + return false; + } + + auto idBytes = bytes.mid(0, Identifier::DISPLAY_REPR_SIZE); + auto revBytes = bytes.mid(Identifier::DISPLAY_REPR_SIZE); + return Key::isValidDisplay(idBytes) && Revision::isValidDisplay(revBytes); +} + +bool Key::isValid(const QByteArray &bytes) +{ + switch (bytes.size()) { + case Key::INTERNAL_REPR_SIZE: + return isValidInternal(bytes); + case Key::DISPLAY_REPR_SIZE: + return isValidDisplay(bytes); + } + return false; +} + bool Key::operator==(const Key &other) const { return (id == other.id) && (rev == other.rev); @@ -200,4 +275,3 @@ bool Key::operator!=(const Key &other) const { return !(*this == other); } - -- cgit v1.2.3