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 
20 namespace Kleo
21 {
22 
23 /**
24  @short DN parser and reorderer
25 */
26 class KLEO_EXPORT DN
27 {
28 public:
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  /** @return the DN in the original form */
56  QString dn() const;
57  /**
58  \overload
59  Uses \a sep as separator (default: ,)
60  */
61  QString dn(const QString &sep) const;
62 
63  QString operator[](const QString &attr) const;
64 
65  void append(const Attribute &attr);
66 
67  const_iterator begin() const;
68  const_iterator end() const;
69 
70 private:
71  void detach();
72 
73 private:
74  class Private;
75  Private *d;
76 };
77 
78 class KLEO_EXPORT DN::Attribute
79 {
80 public:
81  using List = DN::AttributeList;
82 
83  explicit Attribute(const QString &name = QString(), const QString &value = QString())
84  : mName(name.toUpper())
85  , mValue(value)
86  {
87  }
88  Attribute(const Attribute &other)
89  : mName(other.name())
90  , mValue(other.value())
91  {
92  }
93 
94  const Attribute &operator=(const Attribute &other)
95  {
96  if (this != &other) {
97  mName = other.name();
98  mValue = other.value();
99  }
100  return *this;
101  }
102 
103  const QString &name() const
104  {
105  return mName;
106  }
107  const QString &value() const
108  {
109  return mValue;
110  }
111 
112  void setValue(const QString &value)
113  {
114  mValue = value;
115  }
116 
117 private:
118  QString mName;
119  QString mValue;
120 };
121 
122 }
DN parser and reorderer.
Definition: dn.h:26
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.