Kea  2.1.7-git
binary_from_base32hex.h
Go to the documentation of this file.
1 #ifndef BOOST_ARCHIVE_ITERATORS_BINARY_FROM_BASE32HEX_HPP
2 #define BOOST_ARCHIVE_ITERATORS_BINARY_FROM_BASE32HEX_HPP
3 
5 // binary_from_base32hex.h (derived from boost binary_from_base64.hpp)
6 
7 // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
8 // Use, modification and distribution is subject to the Boost Software
9 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
10 // http://www.boost.org/LICENSE_1_0.txt)
11 
12 // See http://www.boost.org for updates, documentation, and revision history.
13 
14 #include <cassert>
15 
16 // We use the same boost header files used in "_from_base64". Since the
17 // precise path to these headers may vary depending on the boost version we
18 // simply include the base64 header here.
19 #include <boost/archive/iterators/binary_from_base64.hpp>
20 
21 #include <exceptions/exceptions.h>
22 
23 namespace boost {
24 namespace archive {
25 namespace iterators {
26 
28 // convert base32hex characters to binary data
29 
30 namespace detail {
31 
32 template<class CharType>
33 struct to_5_bit {
34  typedef CharType result_type;
35  CharType operator()(CharType t) const{
36  const signed char lookup_table[] = {
37  -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 00-0f
38  -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 10-1f
39  -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 20-2f
40  0, 1, 2, 3, 4, 5, 6, 7, 8, 9,-1,-1,-1,-1,-1,-1, // 30-3f
41  -1,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24, // 40-4f
42  25,26,27,28,29,30,31,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 50-5f
43  -1,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24, // 60-6f
44  25,26,27,28,29,30,31,-1,-1,-1,-1,-1,-1,-1,-1,-1 // 70-7f
45  };
46  BOOST_STATIC_ASSERT(0x80 == sizeof(lookup_table));
47  signed char value = -1;
48  if((unsigned)t < sizeof(lookup_table))
49  value = lookup_table[(unsigned)t];
50  if(-1 == value) {
52  "attempt to decode a value not in base32hex char set");
53  }
54  return (value);
55  }
56 };
57 
58 } // namespace detail
59 
60 // note: what we would like to do is
61 // template<class Base, class CharType = BOOST_DEDUCED_TYPENAME Base::value_type>
62 // typedef transform_iterator<
63 // from_5_bit<CharType>,
64 // transform_width<Base, 5, sizeof(Base::value_type) * 8, CharType>
65 // > base32hex_from_binary;
66 // but C++ won't accept this. Rather than using a "type generator" and
67 // using a different syntax, make a derivation which should be equivalent.
68 //
69 // Another issue addressed here is that the transform_iterator doesn't have
70 // a templated constructor. This makes it incompatible with the dataflow
71 // ideal. This is also addressed here.
72 
73 template<
74  class Base,
75  class CharType = BOOST_DEDUCED_TYPENAME boost::iterator_value<Base>::type
76 >
77 class binary_from_base32hex : public
78  transform_iterator<
79  detail::to_5_bit<CharType>,
80  Base
81  >
82 {
83  friend class boost::iterator_core_access;
84  typedef transform_iterator<
86  Base
87  > super_t;
88 public:
89  // make composable by using templated constructor
90  template<class T>
92  super_t(
93  Base(static_cast<T>(start)),
94  detail::to_5_bit<CharType>()
95  )
96  {}
97  // intel 7.1 doesn't like default copy constructor
99  super_t(
100  Base(rhs.base_reference()),
101  detail::to_5_bit<CharType>()
102  )
103  {}
104 // binary_from_base32hex(){};
105 };
106 
107 } // namespace iterators
108 } // namespace archive
109 } // namespace boost
110 
111 #endif // BOOST_ARCHIVE_ITERATORS_BINARY_FROM_BASE32HEX_HPP
112 
113 // Local Variables:
114 // mode: c++
115 // End:
binary_from_base32hex(const binary_from_base32hex &rhs)
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...