File: encryptionextension.hh

package info (click to toggle)
qdmr 0.13.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 22,420 kB
  • sloc: cpp: 95,929; xml: 10,749; python: 1,108; makefile: 78; sh: 9
file content (150 lines) | stat: -rw-r--r-- 4,310 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#ifndef ENCRYPTIONEXTENSION_HH
#define ENCRYPTIONEXTENSION_HH

#include "configobject.hh"


/** Base class of all encryption keys.
 * @ingroup conf */
class EncryptionKey: public ConfigObject
{
  Q_OBJECT
  Q_CLASSINFO("IdPrefix", "key")

  /** The key representation as a hex string. */
  Q_PROPERTY(QString key READ toHex WRITE fromHex)

protected:
  /** Hidden constructor. */
  explicit EncryptionKey(QObject *parent=nullptr);

public:
  void clear();

  /** Creates a key from the given hex-string. */
  virtual bool fromHex(const QString &hex, const ErrorStack &err=ErrorStack());
  /** Converts a key to a hex string. */
  virtual QString toHex() const;

  /** Returns the binary key. */
  const QByteArray &key() const;
  /** Sets the binary key. */
  virtual bool setKey(const QByteArray &key, const ErrorStack &err=ErrorStack());

protected:
  /** Holds the key data.
   * The size depends on the key type. */
  QByteArray _key;
};


/** Represents a DMR (basic) encryption key.
 *
 * This is a variable sized key used for the DMR basic encryption method.
 *
 * @ingroup conf */
class BasicEncryptionKey: public EncryptionKey
{
  Q_OBJECT
  Q_CLASSINFO("description", "A basic DMR encryption key.")
  Q_CLASSINFO("longDescription",
              "This is a variable sized pre-shared key that can be used to encrypt/decrypt traffic "
              "on DMR channels. Encryption is forbidden in HAM radio context!")

public:
  /** Empty constructor. */
  Q_INVOKABLE explicit BasicEncryptionKey(QObject *parent=nullptr);

  ConfigItem *clone() const;

public:
  YAML::Node serialize(const Context &context, const ErrorStack &err=ErrorStack());
  bool parse(const YAML::Node &node, Context &ctx, const ErrorStack &err=ErrorStack());
};


/** Represents an (enhanced) ARC4 encryption key.
 *
 * This is a 40bit key used for the DMR enhanced encryption method.
 *
 * @ingroup conf */
class ARC4EncryptionKey: public EncryptionKey
{
  Q_OBJECT
  Q_CLASSINFO("description", "An enhanced DMR encryption key.")
  Q_CLASSINFO("longDescription",
              "This is a 40bit pre-shared RC4 key, that can be used to encrypt/decrypt traffic on "
              "DMR channels. Encryption is forbidden in HAM radio context!")

public:
  /** Empty constructor. */
  Q_INVOKABLE explicit ARC4EncryptionKey(QObject *parent=nullptr);

  ConfigItem *clone() const;
  bool fromHex(const QString &hex, const ErrorStack &err=ErrorStack());

  bool setKey(const QByteArray &key, const ErrorStack &err);

public:
  YAML::Node serialize(const Context &context, const ErrorStack &err=ErrorStack());
  bool parse(const YAML::Node &node, Context &ctx, const ErrorStack &err=ErrorStack());
};


/** Represents a variable size AES (enhanced) encryption key.
 *
 * This is a 128-256bit key used for the DMR enhanced encryption method.
 *
 * @ingroup conf */
class AESEncryptionKey: public EncryptionKey
{
  Q_OBJECT

  Q_CLASSINFO("description", "An AES (advanced) DMR encryption key.")
  Q_CLASSINFO("longDescription",
              "This is a variable sized (usually 128-256bit) pre-shared key that can be used to "
              "encrypt/decrypt traffic on DMR channels. Encryption is forbidden in HAM radio "
              "context!")

public:
  /** Empty constructor. */
  Q_INVOKABLE explicit AESEncryptionKey(QObject *parent=nullptr);

  ConfigItem *clone() const;

  bool setKey(const QByteArray &key, const ErrorStack &err);

public:
  YAML::Node serialize(const Context &context, const ErrorStack &err=ErrorStack());
  bool parse(const YAML::Node &node, Context &ctx, const ErrorStack &err=ErrorStack());
};

Q_DECLARE_OPAQUE_POINTER(AESEncryptionKey*)


/** The list of encryption keys.
 *
 * This list holds all encryption keys defined within the codeplug.
 *
 * @warning Please note that this is a commercial feature and forbidden for HAM radio use.
 *
 * @ingroup conf */
class EncryptionKeys: public ConfigObjectList
{
  Q_OBJECT

public:
  /** Empty constructor. */
  explicit EncryptionKeys(QObject *parent=nullptr);

  int add(ConfigObject *obj, int row=-1, bool unique=true);

  /** Returns the key the given index. */
  EncryptionKey *key(int index) const;

  ConfigItem *allocateChild(const YAML::Node &node, ConfigItem::Context &ctx, const ErrorStack &err=ErrorStack());
};



#endif // ENCRYPTIONEXTENSION_HH