Libkleo

dn.h
1/*
2 dn.h
3
4 This file is part of libkleopatra, the KDE keymanagement library
5 SPDX-FileCopyrightText: 2004 Klarälvdalens Datakonsult AB
6 SPDX-FileCopyrightText: 2021 g10 Code GmbH
7 SPDX-FileContributor: Ingo Klöcker <dev@ingo-kloecker.de>
8
9 SPDX-License-Identifier: GPL-2.0-or-later
10*/
11
12#pragma once
13
14#include "kleo_export.h"
15
16#include <QList>
17#include <QString>
18#include <QStringList>
19
20namespace Kleo
21{
22
23/**
24 @short DN parser and reorderer
25*/
26class KLEO_EXPORT DN
27{
28public:
29 class Attribute;
32
33 DN();
34 explicit DN(const QString &dn);
35 explicit DN(const char *utf8DN);
36 DN(const DN &other);
37 ~DN();
38
39 const DN &operator=(const DN &other);
40
41 static QStringList attributeOrder();
42 static void setAttributeOrder(const QStringList &order);
43
44 static QStringList defaultAttributeOrder();
45
46 static QStringList attributeNames();
47 static QString attributeNameToLabel(const QString &name);
48
49 /** @return the value in rfc-2253-escaped form */
50 static QString escape(const QString &value);
51
52 /** @return the DN in a reordered form, according to the settings in
53 the [DN] group of the application's config file */
54 QString prettyDN() const;
55
56 /** Returns the non-empty attributes formatted as \c{NAME=value} and reordered
57 * according to the settings in the [DN] group of the application's config file.
58 */
59 QStringList prettyAttributes() const;
60
61 /** @return the DN in the original form */
62 QString dn() const;
63 /**
64 \overload
65 Uses \a sep as separator (default: ,)
66 */
67 QString dn(const QString &sep) const;
68
69 QString operator[](const QString &attr) const;
70
71 void append(const Attribute &attr);
72
73 const_iterator begin() const;
74 const_iterator end() const;
75
76private:
77 void detach();
78
79private:
80 class Private;
81 Private *d;
82};
83
84class KLEO_EXPORT DN::Attribute
85{
86public:
87 using List = DN::AttributeList;
88
89 explicit Attribute(const QString &name = QString(), const QString &value = QString())
90 : mName(name.toUpper())
91 , mValue(value)
92 {
93 }
94 Attribute(const Attribute &other)
95 : mName(other.name())
96 , mValue(other.value())
97 {
98 }
99
100 const Attribute &operator=(const Attribute &other)
101 {
102 if (this != &other) {
103 mName = other.name();
104 mValue = other.value();
105 }
106 return *this;
107 }
108
109 const QString &name() const
110 {
111 return mName;
112 }
113 const QString &value() const
114 {
115 return mValue;
116 }
117
118 void setValue(const QString &value)
119 {
120 mValue = value;
121 }
122
123private:
124 QString mName;
125 QString mValue;
126};
127
128}
DN parser and reorderer.
Definition dn.h:27
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.