client-cpp  0.6.3
EndpointObjectHash.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2014 CyberVision, Inc.
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 #ifndef ENDPOINT_OBJECT_HASH_HPP_
18 #define ENDPOINT_OBJECT_HASH_HPP_
19 
20 #include <utility>
21 #include <cstring>
22 #include <vector>
23 
24 #include <botan/sha160.h>
25 
26 #include <cstdint>
27 #include <boost/shared_array.hpp>
28 
29 namespace kaa {
30 
31 typedef std::pair<boost::shared_array<std::uint8_t>, std::uint32_t> SharedDataBuffer;
32 
36 class EndpointObjectHash : protected Botan::SHA_160 {
37 public:
38  /*
39  * Default constructor
40  */
42 
43  /*
44  * Specific constructors
45  * Throws \ref KaaException when invalid data was passed (zero-sized or null buffer)
46  */
47  EndpointObjectHash(const std::string& str);
48  EndpointObjectHash(const std::uint8_t* data, const std::uint32_t& dataSize);
49  EndpointObjectHash(const SharedDataBuffer& endpointHash);
51 
52  /*
53  * Copy operator
54  * Throws \ref KaaException when invalid data was passed (zero-sized or null buffer)
55  */
57 
63 
68  bool operator==(EndpointObjectHash& endpointHash) {
69  return isEqual(getHash(), endpointHash.getHash());
70  }
71 
76  bool operator!=(EndpointObjectHash& endpointHash) {
77  return !isEqual(getHash(), endpointHash.getHash());
78  }
79 
84  static bool isEqual(SharedDataBuffer left, SharedDataBuffer right);
85 
86  operator std::vector<std::uint8_t>();
87 
88 private:
89  void cloneHash(const std::uint8_t* data, const std::uint32_t& dataSize);
90 
91 private:
95  bool withData_;
96  SharedDataBuffer hashBuffer_;
97 };
98 
99 } /* namespace kaa */
100 
101 #endif /* ENDPOINT_OBJECT_HASH_HPP_ */
static bool isEqual(SharedDataBuffer left, SharedDataBuffer right)
bool operator==(EndpointObjectHash &endpointHash)
EndpointObjectHash & operator=(EndpointObjectHash &endpointHash)
SharedDataBuffer getHash()
std::pair< boost::shared_array< std::uint8_t >, std::uint32_t > SharedDataBuffer
bool operator!=(EndpointObjectHash &endpointHash)