Leosac  0.8.0
Open Source Access Control
PinCode.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014-2016 Leosac
3 
4  This file is part of Leosac.
5 
6  Leosac is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Affero General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Leosac is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Affero General Public License for more details.
15 
16  You should have received a copy of the GNU Affero General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
22 #include "tools/log.hpp"
23 #include <boost/algorithm/string.hpp>
24 
25 using namespace Leosac;
26 using namespace Leosac::Cred;
27 
28 const std::string &PinCode::pin_code() const
29 {
30  return pin_code_;
31 }
32 
33 void PinCode::pin_code(const std::string &pin)
34 {
36  pin_code_ = pin;
37 }
38 
40 {
42 }
43 
44 void PinCodeValidator::validate_pin_code(const std::string &pin)
45 {
46  for (const auto &c : pin)
47  {
48  if (!(c >= '0' && c <= '9'))
49  {
50  throw ModelException(
51  "data/attributes/code",
52  BUILD_STR("Pin code contains invalid character: " << c));
53  }
54  }
55 }
Leosac::Cred::IPinCode::pin_code
virtual const std::string & pin_code() const =0
Leosac::Cred::PinCodeValidator::validate
static void validate(const IPinCode &card)
Definition: PinCode.cpp:39
BUILD_STR
#define BUILD_STR(param)
Internal macro.
Definition: log.hpp:63
Leosac::Cred::PinCodeValidator::validate_pin_code
static void validate_pin_code(const std::string &)
Definition: PinCode.cpp:44
Leosac
This is the header file for a generated source file, GitSHA1.cpp.
Definition: APIStatusCode.hpp:22
Leosac::Cred::PinCode::pin_code
const std::string & pin_code() const override
Definition: PinCode.cpp:28
Leosac::Cred::PinCode::pin_code_
std::string pin_code_
Definition: PinCode.hpp:44
ModelException.hpp
PinCode.hpp
ModelException
An exception class for general API error.
Definition: ModelException.hpp:33
Leosac::Cred
Definition: Credential.hpp:31
log.hpp
Leosac::Cred::IPinCode
Interface for PinCode credentials.
Definition: IPinCode.hpp:32