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
18class QByteArray;
19class QString;
20
21namespace Kleo
22{
23
24namespace Class
25{
26enum {
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
73KLEO_EXPORT unsigned int classify(const QString &filename);
74KLEO_EXPORT unsigned int classify(const QStringList &fileNames);
75KLEO_EXPORT unsigned int classifyContent(const QByteArray &data);
76
77KLEO_EXPORT QString findSignedData(const QString &signatureFileName);
78KLEO_EXPORT QStringList findSignatures(const QString &signedDataFileName);
79KLEO_EXPORT QString outputFileName(const QString &input);
80
81/** Check if a string looks like a fingerprint (SHA1 sum) */
82KLEO_EXPORT bool isFingerprint(const QString &fpr);
83
84/** Check if a filename matches a ChecksumDefinition pattern */
85KLEO_EXPORT bool isChecksumFile(const QString &file);
86
87KLEO_EXPORT QString outputFileExtension(unsigned int classification, bool usePGPFileExt);
88
89KLEO_EXPORT QString printableClassification(unsigned int classification);
90
91inline bool isCMS(const QString &filename)
92{
93 return (classify(filename) & Class::ProtocolMask) == Class::CMS;
94}
95inline bool isCMS(const unsigned int classification)
96{
97 return (classification & Class::ProtocolMask) == Class::CMS;
98}
99inline bool mayBeCMS(const QString &filename)
100{
101 return classify(filename) & Class::CMS;
102}
103inline bool mayBeCMS(const unsigned int classification)
104{
105 return classification & Class::CMS;
106}
107
108inline bool isOpenPGP(const QString &filename)
109{
110 return (classify(filename) & Class::ProtocolMask) == Class::OpenPGP;
111}
112inline bool isOpenPGP(const unsigned int classification)
113{
114 return (classification & Class::ProtocolMask) == Class::OpenPGP;
115}
116inline bool mayBeOpenPGP(const QString &filename)
117{
118 return classify(filename) & Class::OpenPGP;
119}
120inline bool mayBeOpenPGP(const unsigned int classification)
121{
122 return classification & Class::OpenPGP;
123}
124
125inline bool isBinary(const QString &filename)
126{
127 return (classify(filename) & Class::FormatMask) == Class::Binary;
128}
129inline bool isBinary(const unsigned int classification)
130{
131 return (classification & Class::FormatMask) == Class::Binary;
132}
133inline bool mayBeBinary(const QString &filename)
134{
135 return classify(filename) & Class::Binary;
136}
137inline bool mayBeBinary(const unsigned int classification)
138{
139 return classification & Class::Binary;
140}
141
142inline bool isAscii(const QString &filename)
143{
144 return (classify(filename) & Class::FormatMask) == Class::Ascii;
145}
146inline bool isAscii(const unsigned int classification)
147{
148 return (classification & Class::FormatMask) == Class::Ascii;
149}
150inline bool mayBeAscii(const QString &filename)
151{
152 return classify(filename) & Class::Ascii;
153}
154inline bool mayBeAscii(const unsigned int classification)
155{
156 return classification & Class::Ascii;
157}
158
159inline bool isDetachedSignature(const QString &filename)
160{
161 return (classify(filename) & Class::TypeMask) == Class::DetachedSignature;
162}
163inline bool isDetachedSignature(const unsigned int classification)
164{
165 return (classification & Class::TypeMask) == Class::DetachedSignature;
166}
167inline bool mayBeDetachedSignature(const QString &filename)
168{
169 return classify(filename) & Class::DetachedSignature;
170}
171inline bool mayBeDetachedSignature(const unsigned int classification)
172{
173 return classification & Class::DetachedSignature;
174}
175
176inline bool isOpaqueSignature(const QString &filename)
177{
178 return (classify(filename) & Class::TypeMask) == Class::OpaqueSignature;
179}
180inline bool isOpaqueSignature(const unsigned int classification)
181{
182 return (classification & Class::TypeMask) == Class::OpaqueSignature;
183}
184inline bool mayBeOpaqueSignature(const QString &filename)
185{
186 return classify(filename) & Class::OpaqueSignature;
187}
188inline bool mayBeOpaqueSignature(const unsigned int classification)
189{
190 return classification & Class::OpaqueSignature;
191}
192
193inline bool isCipherText(const QString &filename)
194{
195 return (classify(filename) & Class::TypeMask) == Class::CipherText;
196}
197inline bool isCipherText(const unsigned int classification)
198{
199 return (classification & Class::TypeMask) == Class::CipherText;
200}
201inline bool mayBeCipherText(const QString &filename)
202{
203 return classify(filename) & Class::CipherText;
204}
205inline bool mayBeCipherText(const unsigned int classification)
206{
207 return classification & Class::CipherText;
208}
209
210inline bool isAnyMessageType(const QString &filename)
211{
212 return (classify(filename) & Class::TypeMask) == Class::AnyMessageType;
213}
214inline bool isAnyMessageType(const unsigned int classification)
215{
216 return (classification & Class::TypeMask) == Class::AnyMessageType;
217}
218inline bool mayBeAnyMessageType(const QString &filename)
219{
220 return classify(filename) & Class::AnyMessageType;
221}
222inline bool mayBeAnyMessageType(const unsigned int classification)
223{
224 return classification & Class::AnyMessageType;
225}
226
227inline bool isCertificateRevocationList(const QString &filename)
228{
229 return (classify(filename) & Class::TypeMask) == Class::CertificateRevocationList;
230}
231inline bool isCertificateRevocationList(const unsigned int classification)
232{
233 return (classification & Class::TypeMask) == Class::CertificateRevocationList;
234}
235inline bool mayBeCertificateRevocationList(const QString &filename)
236{
237 return classify(filename) & Class::CertificateRevocationList;
238}
239inline bool mayBeCertificateRevocationList(const unsigned int classification)
240{
241 return classification & Class::CertificateRevocationList;
242}
243
244inline bool isAnyCertStoreType(const QString &filename)
245{
246 return (classify(filename) & Class::TypeMask) == Class::AnyCertStoreType;
247}
248inline bool isAnyCertStoreType(const unsigned int classification)
249{
250 return (classification & Class::TypeMask) == Class::AnyCertStoreType;
251}
252inline bool mayBeAnyCertStoreType(const QString &filename)
253{
254 return classify(filename) & Class::AnyCertStoreType;
255}
256inline bool mayBeAnyCertStoreType(const unsigned int classification)
257{
258 return classification & Class::AnyCertStoreType;
259}
260
261inline bool isMimeFile(const unsigned int classification)
262{
263 return (classification & Class::TypeMask) == Class::MimeFile;
264}
265
266inline bool isMimeFile(const QString &filename)
267{
268 return (classify(filename) & Class::TypeMask) == Class::MimeFile;
269}
270
271inline bool mayBeMimeFile(const QString &filename)
272{
273 return classify(filename) & Class::MimeFile;
274}
275inline bool mayBeMimeFile(const unsigned int classification)
276{
277 return classification & Class::MimeFile;
278}
279
280inline 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}
290inline 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 Mon Nov 18 2024 12:09:14 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.