E-MailRelay
gsecret.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2001-2018 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 "gstrings.h"
26 #include "gexception.h"
27 #include <string>
28 
29 namespace GAuth
30 {
31  class Secret ;
32 }
33 
34 /// \class GAuth::Secret
35 /// Encapsulates a shared secret from the secrets file plus the associated
36 /// userid. A secret is usually a shared key, but it may be masked by a hash
37 /// function. If masked then it can only be verified by an hmac operation
38 /// using the matching hash function. However, the hmac hash function must
39 /// be capable of accepting an intermediate hash state, and this is might
40 /// only be available for md5.
41 ///
43 {
44 public:
45  G_EXCEPTION( Error , "invalid authorisation secret" ) ;
46 
47  Secret( const std::string & , const std::string & , const std::string & , const std::string & = std::string() ) ;
48  ///< Constructor used by the SecretsFile class.
49 
50  static std::string check( const std::string & , const std::string & , const std::string & ) ;
51  ///< Does a non-throwing check of the constructor parameters,
52  ///< returning an error or the empty string.
53 
54  bool valid() const ;
55  ///< Returns true if the secret is valid.
56 
57  std::string key() const ;
58  ///< Returns the key. Throws if not valid().
59 
60  bool masked() const ;
61  ///< Returns true if key() is masked.
62 
63  std::string maskType() const ;
64  ///< Returns the masking function name, such as "MD5", or the
65  ///< empty string if not masked(). Throws if not valid().
66 
67  std::string id() const ;
68  ///< Returns the associated identity. Throws if not valid().
69 
70  static Secret none( const std::string & id ) ;
71  ///< Factory function that returns a secret that is not valid(),
72  ///< as used by the SecretsFile class.
73 
74  static Secret none() ;
75  ///< Factory function that returns a secret that is not valid() and
76  ///< has an empty id().
77 
78  std::string info( const std::string & id = std::string() ) const ;
79  ///< Returns information for logging, excluding anything
80  ///< sensitive. The secret may be in-valid().
81 
82 private:
83  Secret() ;
84  explicit Secret( const std::string & ) ;
85  static bool isDotted( const std::string & ) ;
86  static std::string undotted( const std::string & ) ;
87 
88 private:
89  std::string m_server_type ;
90  std::string m_key ;
91  std::string m_mask_type ;
92  std::string m_id ;
93  std::string m_context ;
94 } ;
95 
96 #endif
std::string key() const
Returns the key. Throws if not valid().
Definition: gsecret.cpp:100
bool valid() const
Returns true if the secret is valid.
Definition: gsecret.cpp:95
static std::string check(const std::string &, const std::string &, const std::string &)
Does a non-throwing check of the constructor parameters, returning an error or the empty string...
Definition: gsecret.cpp:68
std::string info(const std::string &id=std::string()) const
Returns information for logging, excluding anything sensitive.
Definition: gsecret.cpp:123
std::string id() const
Returns the associated identity. Throws if not valid().
Definition: gsecret.cpp:111
static Secret none()
Factory function that returns a secret that is not valid() and has an empty id(). ...
Definition: gsecret.cpp:90
bool masked() const
Returns true if key() is masked.
Definition: gsecret.cpp:106
std::string maskType() const
Returns the masking function name, such as "MD5", or the empty string if not masked().
Definition: gsecret.cpp:117
SASL authentication classes.
Definition: gcram.h:30
Encapsulates a shared secret from the secrets file plus the associated userid.
Definition: gsecret.h:42