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 
87 };
88 
89 } // namespace Ssl
bool validate(const Certificate *certificate)
Validate certificate via registered validators.
Definition: Alert.h:15
Performs certificate validation.
Definition: ValidatorList.h:32
Vector class template.
Definition: WVector.h:29
Maintains a set of fingerprint types.
Definition: Fingerprints.h:39
Implemented by SSL adapter to handle certificate operations.
Definition: Certificate.h:48
bool add(Validator *validator)
Add a validator to the list.
Definition: ValidatorList.h:39
void add(Type type)
Definition: Fingerprints.h:42
Fingerprint::Types fingerprintTypes
Contains a list of registered fingerprint types.
Definition: ValidatorList.h:86
Class template to validate any kind of fingerprint.
Definition: Validator.h:43
bool pin(const T &fingerprint)
Pin a fingerprint.
Definition: ValidatorList.h:49
bool addElement(const Element &obj)
Definition: WVector.h:243
bool add(ValidatorCallback callback, void *data=nullptr)
Register a custom validator callback.
Definition: ValidatorList.h:64
Base validator class.
Definition: Validator.h:29
Validator class wrapping a user-provided callback delegate, plus optional parameter.
Definition: Validator.h:77