All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
validator-fixture.hpp
1 
23 #ifndef NDN_VALIDATOR_FIXTURE_HPP
24 #define NDN_VALIDATOR_FIXTURE_HPP
25 
26 #include <ndn-cpp/security/v2/validator.hpp>
27 #include <ndn-cpp/security/v2/certificate-fetcher-from-network.hpp>
28 #include "identity-management-fixture.hpp"
29 
35 {
36 public:
44  ValidatorFixture(const ndn::ptr_lib::shared_ptr<ndn::ValidationPolicy>& policy);
45 
50  class TestFace : public ndn::Face {
51  public:
52  typedef ndn::func_lib::function<void
53  (const ndn::Interest& interest, const ndn::OnData& onData,
54  const ndn::OnTimeout& onTimeout, const ndn::OnNetworkNack& onNetworkNack)>
55  ProcessInterest;
56 
57  TestFace()
58  : Face("localhost")
59  {}
60 
68  virtual uint64_t
70  (const ndn::Interest& interest, const ndn::OnData& onData,
71  const ndn::OnTimeout& onTimeout, const ndn::OnNetworkNack& onNetworkNack,
73 
74  ProcessInterest processInterest_;
75  std::vector<ndn::Interest> sentInterests_;
76  };
77 
78  void
79  processInterestFromCache
80  (const ndn::Interest& interest, const ndn::OnData& onData,
81  const ndn::OnTimeout& onTimeout, const ndn::OnNetworkNack& onNetworkNack);
82 
83  TestFace face_;
84  ndn::Validator validator_;
85  ndn::ptr_lib::shared_ptr<ndn::ValidationPolicy> policy_;
87 };
88 
90 public:
92  (const ndn::ptr_lib::shared_ptr<ndn::ValidationPolicy>& policy)
93  : ValidatorFixture(policy)
94  {
95  identity_ = addIdentity("/Security/V2/ValidatorFixture");
96  subIdentity_ = addSubCertificate("/Security/V2/ValidatorFixture/Sub1", identity_);
97  subSelfSignedIdentity_ = addIdentity("/Security/V2/ValidatorFixture/Sub1/Sub2");
98  otherIdentity_ = addIdentity("/Security/V2/OtherIdentity");
99 
100  validator_.loadAnchor
101  ("", ndn::CertificateV2(*identity_->getDefaultKey()->getDefaultCertificate()));
102 
103  cache_.insert(*identity_->getDefaultKey()->getDefaultCertificate());
104  cache_.insert(*subIdentity_->getDefaultKey()->getDefaultCertificate());
105  cache_.insert(*subSelfSignedIdentity_->getDefaultKey()->getDefaultCertificate());
106  cache_.insert(*otherIdentity_->getDefaultKey()->getDefaultCertificate());
107  }
108 
109  ndn::ptr_lib::shared_ptr<ndn::PibIdentity> identity_;
110  ndn::ptr_lib::shared_ptr<ndn::PibIdentity> subIdentity_;
111  ndn::ptr_lib::shared_ptr<ndn::PibIdentity> subSelfSignedIdentity_;
112  ndn::ptr_lib::shared_ptr<ndn::PibIdentity> otherIdentity_;
113 };
114 
115 #endif
Copyright (C) 2017-2018 Regents of the University of California.
Definition: identity-management-fixture.hpp:29
Copyright (C) 2017-2018 Regents of the University of California.
Definition: validator-fixture.hpp:34
The Face class provides the main methods for NDN communication.
Definition: face.hpp:86
CertificateV2 represents a certificate following the certificate format naming convention.
Definition: certificate-v2.hpp:81
ndn::ptr_lib::shared_ptr< ndn::PibIdentity > addSubCertificate(const ndn::Name &subIdentityName, const ndn::ptr_lib::shared_ptr< ndn::PibIdentity > &issuer, const ndn::KeyParams &params=ndn::KeyChain::getDefaultKeyParams())
Issue a certificate for subIdentityName signed by issuer.
Definition: identity-management-fixture.cpp:84
virtual uint64_t expressInterest(const ndn::Interest &interest, const ndn::OnData &onData, const ndn::OnTimeout &onTimeout, const ndn::OnNetworkNack &onNetworkNack, ndn::WireFormat &wireFormat=*ndn::WireFormat::getDefaultWireFormat())
If processInterest_ is not null, call processInterest_(interest, onData, onTimeout, onNetworkNack) which must call one of the callbacks to simulate the response.
Definition: validator-fixture.cpp:54
func_lib::function< void(const ptr_lib::shared_ptr< const Interest > &interest, const ptr_lib::shared_ptr< NetworkNack > &networkNack)> OnNetworkNack
An OnNetworkNack function object is used to pass a callback to expressInterest.
Definition: face.hpp:55
ValidatorFixture(const ndn::ptr_lib::shared_ptr< ndn::ValidationPolicy > &policy)
Create a ValidatorFixture to use the given policy.
Definition: validator-fixture.cpp:30
func_lib::function< void(const ptr_lib::shared_ptr< const Interest > &interest)> OnTimeout
An OnTimeout function object is used to pass a callback to expressInterest.
Definition: face.hpp:48
An Interest holds a Name and other fields for an interest.
Definition: interest.hpp:43
TestFace extends Face to instantly simulate a call to expressInterest.
Definition: validator-fixture.hpp:50
Face()
Create a new Face for communication with an NDN hub using a default connection as follows...
void insert(const CertificateV2 &certificate)
Insert the certificate into the cache.
Definition: certificate-cache-v2.cpp:42
func_lib::function< void(const ptr_lib::shared_ptr< const Interest > &interest, const ptr_lib::shared_ptr< Data > &data)> OnData
An OnData function object is used to pass a callback to expressInterest.
Definition: face.hpp:35
A CertificateCacheV2 holds other user's verified certificates in security v2 format CertificateV2...
Definition: certificate-cache-v2.hpp:38
Definition: validator-fixture.hpp:89
The Validator class provides an interface for validating data and interest packets.
Definition: validator.hpp:55
static WireFormat * getDefaultWireFormat()
Return the default WireFormat used by default encoding and decoding methods which was set with setDef...
Definition: wire-format.cpp:34
void loadAnchor(const std::string &groupId, const CertificateV2 &certificate)
Load a static trust anchor.
Definition: certificate-storage.hpp:100
Definition: wire-format.hpp:39
ndn::ptr_lib::shared_ptr< ndn::PibIdentity > addIdentity(const ndn::Name &identityName, const ndn::KeyParams &params=ndn::KeyChain::getDefaultKeyParams())
Add an identity for the identityName.
Definition: identity-management-fixture.cpp:60