1 /*############################################################################
2   # Copyright 2016 Intel Corporation
3   #
4   # Licensed under the Apache License, Version 2.0 (the "License");
5   # you may not use this file except in compliance with the License.
6   # You may obtain a copy of the License at
7   #
8   #     http://www.apache.org/licenses/LICENSE-2.0
9   #
10   # Unless required by applicable law or agreed to in writing, software
11   # distributed under the License is distributed on an "AS IS" BASIS,
12   # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   # See the License for the specific language governing permissions and
14   # limitations under the License.
15   ############################################################################*/
16 
17 /*!
18  * \file
19  * \brief Bignum C++ wrapper interface.
20  */
21 #ifndef EPID_COMMON_TESTHELPER_BIGNUM_WRAPPER_TESTHELPER_H_
22 #define EPID_COMMON_TESTHELPER_BIGNUM_WRAPPER_TESTHELPER_H_
23 
24 #include <memory>
25 #include <vector>
26 
27 extern "C" {
28 #include "epid/common/math/bignum.h"
29 }
30 
31 /*!
32 Wrapper class to provide Resource Allocation is Initialization handling
33 for BigNum
34 */
35 class BigNumObj {
36  public:
37   /// Create a BigNum of default size ( sizeof(BigNumStr) )
38   BigNumObj();
39   /// copy constructor
40   BigNumObj(BigNumObj const& other);
41   /// assignment operator
42   BigNumObj& operator=(BigNumObj const& other);
43   /// Create a BigNum of specific size
44   explicit BigNumObj(size_t data_size_bytes);
45   /// Create a BigNum of specific size and initialize it to bytes
46   BigNumObj(size_t data_size_bytes, std::vector<unsigned char> const& bytes);
47   /// Create a BigNum of specific size and initialize it to bytes
48   BigNumObj(size_t data_size_bytes, BigNumStr const& bytes);
49   /// Create a BigNum the same size as bytes and initialize it to bytes
50   explicit BigNumObj(std::vector<unsigned char> const& bytes);
51   /// Create a BigNum the same size as bytes and initialize it to bytes
52   explicit BigNumObj(BigNumStr const& bytes);
53   /// Destroy the Bignum
54   ~BigNumObj();
55   /// cast operator to get the pointer to the stored BigNum
56   operator BigNum*();
57   /// const cast operator to get the pointer to the stored BigNum
58   operator const BigNum*() const;
59   /// Get the underlying pointer
60   BigNum* get();
61   /// Get the underlying pointer
62   BigNum const* getc() const;
63 
64  private:
65   struct State;
66   std::unique_ptr<State> state_;
67 };
68 
69 #endif  // EPID_COMMON_TESTHELPER_BIGNUM_WRAPPER_TESTHELPER_H_
70