ify_8h_source

Search for usage in LXR

classify.h
1 /* -*- mode: c++; c-basic-offset:4 -*-
2  utils/classify.h
3 
4  This file is part of Kleopatra, the KDE keymanager
5  SPDX-FileCopyrightText: 2007 Klarälvdalens Datakonsult AB
6 
7  SPDX-License-Identifier: GPL-2.0-or-later
8 */
9 
10 #pragma once
11 
12 #include "kleo_export.h"
13 
14 #include <QStringList>
15 
16 #include <gpgme++/global.h>
17 
18 class QByteArray;
19 class QString;
20 
21 namespace Kleo
22 {
23 
24 namespace Class
25 {
26 enum {
27  // clang-format off
28  NoClass = 0,
29 
30  // protocol:
31  CMS = 0x01,
32  OpenPGP = 0x02,
33 
34  AnyProtocol = OpenPGP | CMS,
35  ProtocolMask = AnyProtocol,
36 
37  // format:
38  Binary = 0x04,
39  Ascii = 0x08,
40 
41  AnyFormat = Binary | Ascii,
42  FormatMask = AnyFormat,
43 
44  // type:
45  DetachedSignature = 0x010,
46  OpaqueSignature = 0x020,
47  ClearsignedMessage = 0x040,
48 
49  AnySignature = DetachedSignature | OpaqueSignature | ClearsignedMessage,
50 
51  CipherText = 0x080,
52 
53  AnyMessageType = AnySignature | CipherText,
54 
55  Importable = 0x100,
56  Certificate = 0x200 | Importable,
57  ExportedPSM = 0x400 | Importable,
58 
59  AnyCertStoreType = Certificate | ExportedPSM,
60 
61  CertificateRequest = 0x800,
62 
63  CertificateRevocationList = 0x1000,
64 
65  MimeFile = 0x2000,
66 
67  AnyType = AnyMessageType | AnyCertStoreType | CertificateRequest | CertificateRevocationList,
68  TypeMask = AnyType | MimeFile
69  // clang-format on
70 };
71 }
72 
73 KLEO_EXPORT unsigned int classify(const QString &filename);
74 KLEO_EXPORT unsigned int classify(const QStringList &fileNames);
75 KLEO_EXPORT unsigned int classifyContent(const QByteArray &data);
76 
77 KLEO_EXPORT QString findSignedData(const QString &signatureFileName);
78 KLEO_EXPORT QStringList findSignatures(const QString &signedDataFileName);
79 KLEO_EXPORT QString outputFileName(const QString &input);
80 
81 /** Check if a string looks like a fingerprint (SHA1 sum) */
82 KLEO_EXPORT bool isFingerprint(const QString &fpr);
83 
84 /** Check if a filename matches a ChecksumDefinition pattern */
85 KLEO_EXPORT bool isChecksumFile(const QString &file);
86 
87 KLEO_EXPORT QString outputFileExtension(unsigned int classification, bool usePGPFileExt);
88 
89 KLEO_EXPORT QString printableClassification(unsigned int classification);
90 
91 inline bool isCMS(const QString &filename)
92 {
93  return (classify(filename) & Class::ProtocolMask) == Class::CMS;
94 }
95 inline bool isCMS(const unsigned int classification)
96 {
97  return (classification & Class::ProtocolMask) == Class::CMS;
98 }
99 inline bool mayBeCMS(const QString &filename)
100 {
101  return classify(filename) & Class::CMS;
102 }
103 inline bool mayBeCMS(const unsigned int classification)
104 {
105  return classification & Class::CMS;
106 }
107 
108 inline bool isOpenPGP(const QString &filename)
109 {
110  return (classify(filename) & Class::ProtocolMask) == Class::OpenPGP;
111 }
112 inline bool isOpenPGP(const unsigned int classification)
113 {
114  return (classification & Class::ProtocolMask) == Class::OpenPGP;
115 }
116 inline bool mayBeOpenPGP(const QString &filename)
117 {
118  return classify(filename) & Class::OpenPGP;
119 }
120 inline bool mayBeOpenPGP(const unsigned int classification)
121 {
122  return classification & Class::OpenPGP;
123 }
124 
125 inline bool isBinary(const QString &filename)
126 {
127  return (classify(filename) & Class::FormatMask) == Class::Binary;
128 }
129 inline bool isBinary(const unsigned int classification)
130 {
131  return (classification & Class::FormatMask) == Class::Binary;
132 }
133 inline bool mayBeBinary(const QString &filename)
134 {
135  return classify(filename) & Class::Binary;
136 }
137 inline bool mayBeBinary(const unsigned int classification)
138 {
139  return classification & Class::Binary;
140 }
141 
142 inline bool isAscii(const QString &filename)
143 {
144  return (classify(filename) & Class::FormatMask) == Class::Ascii;
145 }
146 inline bool isAscii(const unsigned int classification)
147 {
148  return (classification & Class::FormatMask) == Class::Ascii;
149 }
150 inline bool mayBeAscii(const QString &filename)
151 {
152  return classify(filename) & Class::Ascii;
153 }
154 inline bool mayBeAscii(const unsigned int classification)
155 {
156  return classification & Class::Ascii;
157 }
158 
159 inline bool isDetachedSignature(const QString &filename)
160 {
161  return (classify(filename) & Class::TypeMask) == Class::DetachedSignature;
162 }
163 inline bool isDetachedSignature(const unsigned int classification)
164 {
165  return (classification & Class::TypeMask) == Class::DetachedSignature;
166 }
167 inline bool mayBeDetachedSignature(const QString &filename)
168 {
169  return classify(filename) & Class::DetachedSignature;
170 }
171 inline bool mayBeDetachedSignature(const unsigned int classification)
172 {
173  return classification & Class::DetachedSignature;
174 }
175 
176 inline bool isOpaqueSignature(const QString &filename)
177 {
178  return (classify(filename) & Class::TypeMask) == Class::OpaqueSignature;
179 }
180 inline bool isOpaqueSignature(const unsigned int classification)
181 {
182  return (classification & Class::TypeMask) == Class::OpaqueSignature;
183 }
184 inline bool mayBeOpaqueSignature(const QString &filename)
185 {
186  return classify(filename) & Class::OpaqueSignature;
187 }
188 inline bool mayBeOpaqueSignature(const unsigned int classification)
189 {
190  return classification & Class::OpaqueSignature;
191 }
192 
193 inline bool isCipherText(const QString &filename)
194 {
195  return (classify(filename) & Class::TypeMask) == Class::CipherText;
196 }
197 inline bool isCipherText(const unsigned int classification)
198 {
199  return (classification & Class::TypeMask) == Class::CipherText;
200 }
201 inline bool mayBeCipherText(const QString &filename)
202 {
203  return classify(filename) & Class::CipherText;
204 }
205 inline bool mayBeCipherText(const unsigned int classification)
206 {
207  return classification & Class::CipherText;
208 }
209 
210 inline bool isAnyMessageType(const QString &filename)
211 {
212  return (classify(filename) & Class::TypeMask) == Class::AnyMessageType;
213 }
214 inline bool isAnyMessageType(const unsigned int classification)
215 {
216  return (classification & Class::TypeMask) == Class::AnyMessageType;
217 }
218 inline bool mayBeAnyMessageType(const QString &filename)
219 {
220  return classify(filename) & Class::AnyMessageType;
221 }
222 inline bool mayBeAnyMessageType(const unsigned int classification)
223 {
224  return classification & Class::AnyMessageType;
225 }
226 
227 inline bool isCertificateRevocationList(const QString &filename)
228 {
229  return (classify(filename) & Class::TypeMask) == Class::CertificateRevocationList;
230 }
231 inline bool isCertificateRevocationList(const unsigned int classification)
232 {
233  return (classification & Class::TypeMask) == Class::CertificateRevocationList;
234 }
235 inline bool mayBeCertificateRevocationList(const QString &filename)
236 {
237  return classify(filename) & Class::CertificateRevocationList;
238 }
239 inline bool mayBeCertificateRevocationList(const unsigned int classification)
240 {
241  return classification & Class::CertificateRevocationList;
242 }
243 
244 inline bool isAnyCertStoreType(const QString &filename)
245 {
246  return (classify(filename) & Class::TypeMask) == Class::AnyCertStoreType;
247 }
248 inline bool isAnyCertStoreType(const unsigned int classification)
249 {
250  return (classification & Class::TypeMask) == Class::AnyCertStoreType;
251 }
252 inline bool mayBeAnyCertStoreType(const QString &filename)
253 {
254  return classify(filename) & Class::AnyCertStoreType;
255 }
256 inline bool mayBeAnyCertStoreType(const unsigned int classification)
257 {
258  return classification & Class::AnyCertStoreType;
259 }
260 
261 inline bool isMimeFile(const unsigned int classification)
262 {
263  return (classification & Class::TypeMask) == Class::MimeFile;
264 }
265 
266 inline bool isMimeFile(const QString &filename)
267 {
268  return (classify(filename) & Class::TypeMask) == Class::MimeFile;
269 }
270 
271 inline bool mayBeMimeFile(const QString &filename)
272 {
273  return classify(filename) & Class::MimeFile;
274 }
275 inline bool mayBeMimeFile(const unsigned int classification)
276 {
277  return classification & Class::MimeFile;
278 }
279 
280 inline GpgME::Protocol findProtocol(const unsigned int classification)
281 {
282  if (isOpenPGP(classification)) {
283  return GpgME::OpenPGP;
284  } else if (isCMS(classification)) {
285  return GpgME::CMS;
286  } else {
287  return GpgME::UnknownProtocol;
288  }
289 }
290 inline GpgME::Protocol findProtocol(const QString &filename)
291 {
292  return findProtocol(classify(filename));
293 }
294 
295 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Thu Feb 15 2024 03:56:14 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.