client-cpp  0.6.1
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 
23 #include <botan/sha160.h>
24 
25 #include <cstdint>
26 #include <boost/shared_array.hpp>
27 
28 namespace kaa {
29 
30 typedef std::pair<boost::shared_array<std::uint8_t>, std::uint32_t> SharedDataBuffer;
31 
35 class EndpointObjectHash : protected Botan::SHA_160 {
36 public:
37  /*
38  * Default constructor
39  */
41 
42  /*
43  * Specific constructors
44  * Throws \ref KaaException when invalid data was passed (zero-sized or null buffer)
45  */
46  EndpointObjectHash(const std::string& str);
47  EndpointObjectHash(const std::uint8_t* data, const std::uint32_t& dataSize);
48  EndpointObjectHash(const SharedDataBuffer& endpointHash);
50 
51  /*
52  * Copy operator
53  * Throws \ref KaaException when invalid data was passed (zero-sized or null buffer)
54  */
56 
62 
67  bool operator==(EndpointObjectHash& endpointHash) {
68  return isEqual(getHash(), endpointHash.getHash());
69  }
70 
75  bool operator!=(EndpointObjectHash& endpointHash) {
76  return !isEqual(getHash(), endpointHash.getHash());
77  }
78 
83  static bool isEqual(SharedDataBuffer left, SharedDataBuffer right);
84 
85  operator std::vector<std::uint8_t>();
86 
87 private:
88  void cloneHash(const std::uint8_t* data, const std::uint32_t& dataSize);
89 
90 private:
94  bool withData_;
95  SharedDataBuffer hashBuffer_;
96 };
97 
98 } /* namespace kaa */
99 
100 #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)