File indexing completed on 2024-06-23 05:18:38

0001 /*  -*- c++ -*-
0002     kleo_util.h
0003 
0004     This file is part of KMail, the KDE mail client.
0005     SPDX-FileCopyrightText: 2004 Marc Mutz <mutz@kde.org>
0006 
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 
0010 #pragma once
0011 
0012 #include <Libkleo/Enum>
0013 
0014 static const Kleo::CryptoMessageFormat cryptoMessageFormats[] = {Kleo::AutoFormat,
0015                                                                  Kleo::InlineOpenPGPFormat,
0016                                                                  Kleo::OpenPGPMIMEFormat,
0017                                                                  Kleo::SMIMEFormat,
0018                                                                  Kleo::SMIMEOpaqueFormat};
0019 static const int numCryptoMessageFormats = sizeof cryptoMessageFormats / sizeof *cryptoMessageFormats;
0020 
0021 static const Kleo::CryptoMessageFormat concreteCryptoMessageFormats[] = {Kleo::OpenPGPMIMEFormat,
0022                                                                          Kleo::SMIMEFormat,
0023                                                                          Kleo::SMIMEOpaqueFormat,
0024                                                                          Kleo::InlineOpenPGPFormat};
0025 static const unsigned int numConcreteCryptoMessageFormats = sizeof concreteCryptoMessageFormats / sizeof *concreteCryptoMessageFormats;
0026 
0027 static inline Kleo::CryptoMessageFormat cb2format(int idx)
0028 {
0029     return cryptoMessageFormats[idx >= 0 && idx < numCryptoMessageFormats ? idx : 0];
0030 }
0031 
0032 static inline int format2cb(Kleo::CryptoMessageFormat f)
0033 {
0034     for (int i = 0; i < numCryptoMessageFormats; ++i) {
0035         if (f == cryptoMessageFormats[i]) {
0036             return i;
0037         }
0038     }
0039     return 0;
0040 }
0041 
0042 //
0043 // some helper functions indicating the need for CryptoMessageFormat
0044 // to be a class type :)
0045 //
0046 
0047 static inline bool isSMIME(Kleo::CryptoMessageFormat f)
0048 {
0049     return f == Kleo::SMIMEFormat || f == Kleo::SMIMEOpaqueFormat;
0050 }
0051 
0052 static inline bool isOpenPGP(Kleo::CryptoMessageFormat f)
0053 {
0054     return f == Kleo::InlineOpenPGPFormat || f == Kleo::OpenPGPMIMEFormat;
0055 }
0056 
0057 static inline bool containsSMIME(unsigned int f)
0058 {
0059     return f & (Kleo::SMIMEFormat | Kleo::SMIMEOpaqueFormat);
0060 }
0061 
0062 static inline bool containsOpenPGP(unsigned int f)
0063 {
0064     return f & (Kleo::OpenPGPMIMEFormat | Kleo::InlineOpenPGPFormat);
0065 }