blob: 0d17e41a8e993bd5ab7287e5fb530a752b07a363 [file] [log] [blame]
Jeff Thompson3f3cfd32013-09-27 11:46:52 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/**
3 * Copyright (C) 2013 Regents of the University of California.
4 * @author: Yingdi Yu <yingdi@cs.ucla.edu>
5 * @author: Jeff Thompson <jefft0@remap.ucla.edu>
6 * See COPYING for copyright and distribution information.
7 */
8
Yingdi Yu4f324632014-01-15 18:10:03 -08009#ifndef NDN_SEC_POLICY_HPP
10#define NDN_SEC_POLICY_HPP
Jeff Thompson3f3cfd32013-09-27 11:46:52 -070011
Yingdi Yu4f324632014-01-15 18:10:03 -080012#include "../data.hpp"
Yingdi Yue07e3392014-01-28 10:29:27 -080013#include "verifier.hpp"
Yingdi Yu2abd73f2014-01-08 23:34:11 -080014#include "validation-request.hpp"
Jeff Thompson3f3cfd32013-09-27 11:46:52 -070015
16namespace ndn {
Jeff Thompson3f3cfd32013-09-27 11:46:52 -070017
18/**
Yingdi Yu4f324632014-01-15 18:10:03 -080019 * A SecPolicy is an abstract base class to represent the policy for verifying data packets.
Jeff Thompson3f3cfd32013-09-27 11:46:52 -070020 * You must create an object of a subclass.
21 */
Yingdi Yu4f324632014-01-15 18:10:03 -080022class SecPolicy {
Jeff Thompson3f3cfd32013-09-27 11:46:52 -070023public:
Yingdi Yu2abd73f2014-01-08 23:34:11 -080024 struct Error : public std::runtime_error { Error(const std::string &what) : std::runtime_error(what) {} };
25
Jeff Thompson3f3cfd32013-09-27 11:46:52 -070026 /**
27 * The virtual destructor.
28 */
29 virtual
Yingdi Yu4f324632014-01-15 18:10:03 -080030 ~SecPolicy() {}
Jeff Thompson3f3cfd32013-09-27 11:46:52 -070031
32 /**
Jeff Thompson3f3cfd32013-09-27 11:46:52 -070033 * Check whether the received data packet complies with the verification policy, and get the indication of the next verification step.
Yingdi Yue07e3392014-01-28 10:29:27 -080034 * If there is no next verification step, that imlies policy MUST have already made the verification decision.
35 * i.e., either onVerified or onVerifyFailed callback is invoked.
Jeff Thompson3f3cfd32013-09-27 11:46:52 -070036 * @param data The Data object with the signature to check.
37 * @param stepCount The number of verification steps that have been done, used to track the verification progress.
38 * @param onVerified If the signature is verified, this calls onVerified(data).
39 * @param onVerifyFailed If the signature check fails, this calls onVerifyFailed(data).
40 * @return the indication of next verification step, null if there is no further step.
41 */
42 virtual ptr_lib::shared_ptr<ValidationRequest>
43 checkVerificationPolicy
Yingdi Yue07e3392014-01-28 10:29:27 -080044 (const ptr_lib::shared_ptr<Data>& data, int stepCount, const OnVerified& onVerified, const OnVerifyFailed& onVerifyFailed)
45 {
46 onVerifyFailed();
47 return ptr_lib::shared_ptr<ValidationRequest>();
48 }
49
Jeff Thompson3f3cfd32013-09-27 11:46:52 -070050 /**
Yingdi Yue07e3392014-01-28 10:29:27 -080051 * Check whether the received interest packet complies with the verification policy, and get the indication of the next verification step.
52 * If there is no next verification step, that implies policy MUST have already made the verification decision.
53 * i.e., either onVerified or onVerifyFailed callback is invoked.
54 * @param data The Data object with the signature to check.
55 * @param stepCount The number of verification steps that have been done, used to track the verification progress.
56 * @param onVerified If the signature is verified, this calls onVerified(data).
57 * @param onVerifyFailed If the signature check fails, this calls onVerifyFailed(data).
58 * @return the indication of next verification step, null if there is no further step.
Jeff Thompson3f3cfd32013-09-27 11:46:52 -070059 */
Yingdi Yue07e3392014-01-28 10:29:27 -080060 virtual ptr_lib::shared_ptr<ValidationRequest>
61 checkVerificationPolicy
62 (const ptr_lib::shared_ptr<Interest>& interest, int stepCount, const OnVerified& onVerified, const OnVerifyFailed& onVerifyFailed)
63 {
64 onVerifyFailed();
65 return ptr_lib::shared_ptr<ValidationRequest>();
66 }
Jeff Thompson3f3cfd32013-09-27 11:46:52 -070067};
68
69}
70
71#endif