E-MailRelay

gsecret.h
Go to the documentation of this file.
1//
2// Copyright (C) 2001-2021 Graeme Walker <graeme_walker@users.sourceforge.net>
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <http://www.gnu.org/licenses/>.
16// ===
17///
18/// \file gsecret.h
19///
20
21#ifndef G_AUTH_SECRET_H
22#define G_AUTH_SECRET_H
23
24#include "gdef.h"
25#include "gexception.h"
26#include <string>
27
28 namespace GAuth
29{
30 class Secret ;
31}
32
33//| \class GAuth::Secret
34/// Encapsulates a shared secret from the secrets file plus the associated
35/// userid. A secret is usually a plaintext shared key, but it may be masked
36/// by a hash function. If masked then it can only be verified by an hmac
37/// operation using the matching hash function. However, the hmac hash function
38/// must be capable of accepting an intermediate hash state, and this is might
39/// only be available for md5.
40///
41 class GAuth::Secret
42{
43 public:
44 G_EXCEPTION( Error , "invalid authorisation secret" ) ;
45 G_EXCEPTION( BadId , "invalid authorisation id" ) ;
46
47 Secret( const std::string & secret , const std::string & secret_encoding ,
48 const std::string & id , bool id_encoding_xtext ,
49 const std::string & context = std::string() ) ;
50 ///< Constructor used by the SecretsFile class. Throws on error,
51 ///< including if the encodings are invalid.
52
53 static std::string check( const std::string & secret , const std::string & secret_encoding ,
54 const std::string & id , bool id_encoding_xtext ) ;
55 ///< Does a non-throwing check of the constructor parameters,
56 ///< returning an error message or the empty string.
57
58 bool valid() const ;
59 ///< Returns true if the secret is valid.
60
61 std::string key() const ;
62 ///< Returns the key. Throws if not valid().
63
64 bool masked() const ;
65 ///< Returns true if key() is masked.
66
67 std::string maskType() const ;
68 ///< Returns the masking function name, such as "MD5", or the
69 ///< empty string if not masked(). Throws if not valid().
70
71 std::string id() const ;
72 ///< Returns the associated identity. Throws if not valid().
73
74 static Secret none( const std::string & id ) ;
75 ///< Factory function that returns a secret that is not valid(),
76 ///< as used by the SecretsFile class.
77
78 static Secret none() ;
79 ///< Factory function that returns a secret that is not valid() and
80 ///< has an empty id().
81
82 std::string info( const std::string & id = std::string() ) const ;
83 ///< Returns information for logging, excluding anything
84 ///< sensitive. The secret may be in-valid().
85
86 private:
87 Secret() ; // Secret::none()
88 explicit Secret( const std::string & ) ;
89 static bool isDotted( const std::string & ) ;
90 static std::string undotted( const std::string & ) ;
91
92 private:
93 std::string m_server_type ;
94 std::string m_key ;
95 std::string m_mask_type ;
96 std::string m_id ;
97 std::string m_context ;
98} ;
99
100#endif
GAuth::Secret
Encapsulates a shared secret from the secrets file plus the associated userid.
Definition: gsecret.h:42
GAuth::Secret::masked
bool masked() const
Returns true if key() is masked.
Definition: gsecret.cpp:110
GAuth::Secret::none
static Secret none()
Factory function that returns a secret that is not valid() and has an empty id().
Definition: gsecret.cpp:94
GAuth::Secret::valid
bool valid() const
Returns true if the secret is valid.
Definition: gsecret.cpp:99
GAuth::Secret::check
static std::string check(const std::string &secret, const std::string &secret_encoding, const std::string &id, bool id_encoding_xtext)
Does a non-throwing check of the constructor parameters, returning an error message or the empty stri...
Definition: gsecret.cpp:69
GAuth::Secret::info
std::string info(const std::string &id=std::string()) const
Returns information for logging, excluding anything sensitive.
Definition: gsecret.cpp:127
GAuth::Secret::maskType
std::string maskType() const
Returns the masking function name, such as "MD5", or the empty string if not masked().
Definition: gsecret.cpp:121
GAuth::Secret::id
std::string id() const
Returns the associated identity. Throws if not valid().
Definition: gsecret.cpp:115
GAuth::Secret::key
std::string key() const
Returns the key. Throws if not valid().
Definition: gsecret.cpp:104
gexception.h
GAuth
SASL authentication classes.
Definition: gcram.cpp:36