1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-23 02:35:57 +01:00

Move Internals::byte_array into crypto.cpp

This commit is contained in:
Matias Fontanini
2017-04-30 09:53:11 -07:00
parent 92bda42ac1
commit ab51787323
2 changed files with 46 additions and 52 deletions

View File

@@ -52,57 +52,6 @@ class ICMPExtensionsStructure;
namespace Internals {
template<size_t n>
class byte_array {
public:
typedef uint8_t* iterator;
typedef const uint8_t* const_iterator;
byte_array() {
std::fill(begin(), end(), 0);
}
template<typename InputIterator>
byte_array(InputIterator start, InputIterator last) {
std::copy(start, last, data);
}
template<typename InputIterator>
byte_array(InputIterator start) {
std::copy(start, n, data);
}
uint8_t& operator[](size_t i) {
return data[i];
}
uint8_t operator[](size_t i) const{
return data[i];
}
iterator begin() {
return data;
}
iterator end() {
return data + n;
}
const_iterator begin() const {
return data;
}
const_iterator end() const {
return data + n;
}
size_t size() const {
return n;
}
private:
uint8_t data[n];
};
void skip_line(std::istream& input);
bool from_hex(const std::string& str, uint32_t& result);
bool from_hex(const std::string& str, std::string& result);

View File

@@ -38,8 +38,8 @@
#endif // TINS_HAVE_WPA2_DECRYPTION
#include "dot11/dot11_data.h"
#include "dot11/dot11_beacon.h"
#include "internals.h"
#include "exceptions.h"
#include "detail/type_traits.h"
using std::string;
using std::make_pair;
@@ -52,6 +52,51 @@ using std::fill;
using std::runtime_error;
namespace Tins {
namespace Internals {
template<size_t n>
class byte_array {
public:
typedef uint8_t* iterator;
typedef const uint8_t* const_iterator;
byte_array() {
std::memset(data, 0, size());
}
uint8_t& operator[](size_t i) {
return data[i];
}
uint8_t operator[](size_t i) const{
return data[i];
}
iterator begin() {
return data;
}
iterator end() {
return data + n;
}
const_iterator begin() const {
return data;
}
const_iterator end() const {
return data + n;
}
size_t size() const {
return n;
}
private:
uint8_t data[n];
};
} // Internals
namespace Crypto {
WEPDecrypter::WEPDecrypter()