File indexing completed on 2025-01-05 04:55:53
0001 /* -*- mode: c++; c-basic-offset:4 -*- 0002 utils/keyusage.h 0003 0004 This file is part of libkleopatra, the KDE keymanagement library 0005 SPDX-FileCopyrightText: 2022 g10 Code GmbH 0006 SPDX-FileContributor: Ingo Klöcker <dev@ingo-kloecker.de> 0007 0008 SPDX-License-Identifier: GPL-2.0-or-later 0009 */ 0010 0011 #pragma once 0012 0013 #include "kleo_export.h" 0014 0015 #include <QFlags> 0016 0017 namespace Kleo 0018 { 0019 0020 class KLEO_EXPORT KeyUsage 0021 { 0022 public: 0023 enum Flag { 0024 None = 0, 0025 Certify = 1, 0026 Sign = 2, 0027 Encrypt = 4, 0028 Authenticate = 8, 0029 }; 0030 Q_DECLARE_FLAGS(Flags, Flag) 0031 0032 KeyUsage() 0033 { 0034 } 0035 0036 explicit KeyUsage(Flags flags) 0037 : mFlags{flags} 0038 { 0039 } 0040 0041 void setValue(Flags flags) 0042 { 0043 mFlags = flags; 0044 } 0045 Flags value() const 0046 { 0047 return mFlags; 0048 } 0049 0050 void setCanAuthenticate(bool set) 0051 { 0052 mFlags.setFlag(Authenticate, set); 0053 } 0054 bool canAuthenticate() const 0055 { 0056 return mFlags.testFlag(Authenticate); 0057 } 0058 0059 void setCanCertify(bool set) 0060 { 0061 mFlags.setFlag(Certify, set); 0062 } 0063 bool canCertify() const 0064 { 0065 return mFlags.testFlag(Certify); 0066 } 0067 0068 void setCanEncrypt(bool set) 0069 { 0070 mFlags.setFlag(Encrypt, set); 0071 } 0072 bool canEncrypt() const 0073 { 0074 return mFlags.testFlag(Encrypt); 0075 } 0076 0077 void setCanSign(bool set) 0078 { 0079 mFlags.setFlag(Sign, set); 0080 } 0081 bool canSign() const 0082 { 0083 return mFlags.testFlag(Sign); 0084 } 0085 0086 private: 0087 Flags mFlags; 0088 }; 0089 0090 Q_DECLARE_OPERATORS_FOR_FLAGS(KeyUsage::Flags) 0091 0092 }