ValidatorList.h
Go to the documentation of this file.
1 /****
2  * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development.
3  * Created 2015 by Skurydin Alexey
4  * http://github.com/SmingHub/Sming
5  * All files of the Sming Core are provided under the LGPL v3 license.
6  *
7  * Validator.h
8  *
9  * @author: 2018 - Slavey Karadzhov <slav@attachix.com>
10  *
11  ****/
12 
13 #pragma once
14 
15 #include "Validator.h"
16 #include "Fingerprints.h"
17 #include <WVector.h>
18 
19 namespace Ssl
20 {
32 class ValidatorList : public Vector<Validator>
33 {
34 public:
39  bool add(Validator* validator)
40  {
41  return validator ? Vector::addElement(validator) : false;
42  }
43 
49  template <class T> bool pin(const T& fingerprint)
50  {
51  if(!add(new FingerprintValidator<T>(fingerprint))) {
52  return false;
53  }
54 
55  fingerprintTypes.add(fingerprint.type);
56  return true;
57  }
58 
64  bool add(ValidatorCallback callback, void* data = nullptr)
65  {
66  return add(new CallbackValidator(callback, data));
67  }
68 
78  bool validate(const Certificate* certificate);
79 
86  Fingerprint::Types fingerprintTypes;
87 };
88 
89 } // namespace Ssl
bool addElement(const Element &obj)
Definition: WVector.h:349
bool add(Validator *validator)
Add a validator to the list.
Definition: ValidatorList.h:59
Fingerprint::Types fingerprintTypes
Contains a list of registered fingerprint types.
Definition: ValidatorList.h:106
Class template to validate any kind of fingerprint.
Definition: Validator.h:53
bool pin(const T &fingerprint)
Pin a fingerprint.
Definition: ValidatorList.h:69
Delegate< bool(const Certificate *certificate, void *data)> ValidatorCallback
Validator callback function.
Definition: Validator.h:82
void add(Type type)
Definition: Fingerprints.h:58
Vector class template.
Definition: WVector.h:31
Definition: Alert.h:15
bool validate(const Certificate *certificate)
Validate certificate via registered validators.