diff options
author | Minijackson <minijackson@riseup.net> | 2018-07-26 17:00:03 +0200 |
---|---|---|
committer | Minijackson <minijackson@riseup.net> | 2018-07-26 17:00:03 +0200 |
commit | 6c5d7a65899f3b322184628c2be68fd3f3fdd5da (patch) | |
tree | 2f28fea8c0f39f45b97e3277d75bfa457db7f939 /common/storage/key.cpp | |
parent | a49c078fde2597a05a6b9f6eb2fba5c7fa0b53c9 (diff) | |
download | sink-6c5d7a65899f3b322184628c2be68fd3f3fdd5da.tar.gz sink-6c5d7a65899f3b322184628c2be68fd3f3fdd5da.zip |
Parse Keys in SinkSH inspectkey-for-sinksh
Diffstat (limited to 'common/storage/key.cpp')
-rw-r--r-- | common/storage/key.cpp | 76 |
1 files changed, 75 insertions, 1 deletions
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 | |||
84 | return uid.isNull(); | 84 | return uid.isNull(); |
85 | } | 85 | } |
86 | 86 | ||
87 | bool Identifier::isValidInternal(const QByteArray &bytes) | ||
88 | { | ||
89 | return !QUuid::fromRfc4122(bytes).isNull(); | ||
90 | } | ||
91 | |||
92 | bool Identifier::isValidDisplay(const QByteArray &bytes) | ||
93 | { | ||
94 | return !QUuid(bytes).isNull(); | ||
95 | } | ||
96 | |||
97 | bool Identifier::isValid(const QByteArray &bytes) | ||
98 | { | ||
99 | switch (bytes.size()) { | ||
100 | case Identifier::INTERNAL_REPR_SIZE: | ||
101 | return isValidInternal(bytes); | ||
102 | case Identifier::DISPLAY_REPR_SIZE: | ||
103 | return isValidDisplay(bytes); | ||
104 | } | ||
105 | return false; | ||
106 | } | ||
107 | |||
87 | bool Identifier::operator==(const Identifier &other) const | 108 | bool Identifier::operator==(const Identifier &other) const |
88 | { | 109 | { |
89 | return uid == other.uid; | 110 | return uid == other.uid; |
@@ -128,6 +149,27 @@ qint64 Revision::toQint64() const | |||
128 | return rev; | 149 | return rev; |
129 | } | 150 | } |
130 | 151 | ||
152 | bool Revision::isValidInternal(const QByteArray &bytes) | ||
153 | { | ||
154 | if (bytes.size() != Revision::INTERNAL_REPR_SIZE) { | ||
155 | return false; | ||
156 | } | ||
157 | |||
158 | bool ok; | ||
159 | bytes.toLongLong(&ok); | ||
160 | return ok; | ||
161 | } | ||
162 | |||
163 | bool Revision::isValidDisplay(const QByteArray &bytes) | ||
164 | { | ||
165 | isValidInternal(bytes); | ||
166 | } | ||
167 | |||
168 | bool Revision::isValid(const QByteArray &bytes) | ||
169 | { | ||
170 | isValidInternal(bytes); | ||
171 | } | ||
172 | |||
131 | bool Revision::operator==(const Revision &other) const | 173 | bool Revision::operator==(const Revision &other) const |
132 | { | 174 | { |
133 | return rev == other.rev; | 175 | return rev == other.rev; |
@@ -191,6 +233,39 @@ bool Key::isNull() const | |||
191 | return id.isNull(); | 233 | return id.isNull(); |
192 | } | 234 | } |
193 | 235 | ||
236 | bool Key::isValidInternal(const QByteArray &bytes) | ||
237 | { | ||
238 | if (bytes.size() != Key::INTERNAL_REPR_SIZE) { | ||
239 | return false; | ||
240 | } | ||
241 | |||
242 | auto idBytes = bytes.mid(0, Identifier::INTERNAL_REPR_SIZE); | ||
243 | auto revBytes = bytes.mid(Identifier::INTERNAL_REPR_SIZE); | ||
244 | return Identifier::isValidInternal(idBytes) && Revision::isValidInternal(revBytes); | ||
245 | } | ||
246 | |||
247 | bool Key::isValidDisplay(const QByteArray &bytes) | ||
248 | { | ||
249 | if (bytes.size() != Key::DISPLAY_REPR_SIZE) { | ||
250 | return false; | ||
251 | } | ||
252 | |||
253 | auto idBytes = bytes.mid(0, Identifier::DISPLAY_REPR_SIZE); | ||
254 | auto revBytes = bytes.mid(Identifier::DISPLAY_REPR_SIZE); | ||
255 | return Key::isValidDisplay(idBytes) && Revision::isValidDisplay(revBytes); | ||
256 | } | ||
257 | |||
258 | bool Key::isValid(const QByteArray &bytes) | ||
259 | { | ||
260 | switch (bytes.size()) { | ||
261 | case Key::INTERNAL_REPR_SIZE: | ||
262 | return isValidInternal(bytes); | ||
263 | case Key::DISPLAY_REPR_SIZE: | ||
264 | return isValidDisplay(bytes); | ||
265 | } | ||
266 | return false; | ||
267 | } | ||
268 | |||
194 | bool Key::operator==(const Key &other) const | 269 | bool Key::operator==(const Key &other) const |
195 | { | 270 | { |
196 | return (id == other.id) && (rev == other.rev); | 271 | return (id == other.id) && (rev == other.rev); |
@@ -200,4 +275,3 @@ bool Key::operator!=(const Key &other) const | |||
200 | { | 275 | { |
201 | return !(*this == other); | 276 | return !(*this == other); |
202 | } | 277 | } |
203 | |||