File indexing completed on 2025-10-29 08:11:32
0001 #ifndef BOOST_ARCHIVE_ITERATORS_BINARY_FROM_BASE64_HPP
0002 #define BOOST_ARCHIVE_ITERATORS_BINARY_FROM_BASE64_HPP
0003 
0004 
0005 #if defined(_MSC_VER)
0006 # pragma once
0007 #endif
0008 
0009 
0010 
0011 
0012 
0013 
0014 
0015 
0016 
0017 
0018 
0019 #include <boost/assert.hpp>
0020 
0021 #include <boost/serialization/throw_exception.hpp>
0022 #include <boost/static_assert.hpp>
0023 
0024 #include <boost/iterator/transform_iterator.hpp>
0025 #include <boost/archive/iterators/dataflow_exception.hpp>
0026 
0027 namespace boost {
0028 namespace archive {
0029 namespace iterators {
0030 
0031 
0032 
0033 
0034 namespace detail {
0035 
0036 template<class CharType>
0037 struct to_6_bit {
0038     typedef CharType result_type;
0039     CharType operator()(CharType t) const{
0040         static const signed char lookup_table[] = {
0041             -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
0042             -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
0043             -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,62,-1,-1,-1,63,
0044             52,53,54,55,56,57,58,59,60,61,-1,-1,-1, 0,-1,-1, 
0045             -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,
0046             15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1,
0047             -1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,
0048             41,42,43,44,45,46,47,48,49,50,51,-1,-1,-1,-1,-1
0049         };
0050         
0051         #if ! defined(__MWERKS__)
0052         BOOST_STATIC_ASSERT(128 == sizeof(lookup_table));
0053         #endif
0054         signed char value = -1;
0055         if((unsigned)t <= 127)
0056             value = lookup_table[(unsigned)t];
0057         if(-1 == value)
0058             boost::serialization::throw_exception(
0059                 dataflow_exception(dataflow_exception::invalid_base64_character)
0060             );
0061         return value;
0062     }
0063 };
0064 
0065 } 
0066 
0067 
0068 
0069 
0070 
0071 
0072 
0073 
0074 
0075 
0076 
0077 
0078 
0079 
0080 template<
0081     class Base,
0082     class CharType = typename boost::iterator_value<Base>::type
0083 >
0084 class binary_from_base64 : public
0085     transform_iterator<
0086         detail::to_6_bit<CharType>,
0087         Base
0088     >
0089 {
0090     friend class boost::iterator_core_access;
0091     typedef transform_iterator<
0092         detail::to_6_bit<CharType>,
0093         Base
0094     > super_t;
0095 public:
0096     
0097     template<class T>
0098     binary_from_base64(T  start) :
0099         super_t(
0100             Base(static_cast< T >(start)),
0101             detail::to_6_bit<CharType>()
0102         )
0103     {}
0104     
0105     binary_from_base64(const binary_from_base64 & rhs) :
0106         super_t(
0107             Base(rhs.base_reference()),
0108             detail::to_6_bit<CharType>()
0109         )
0110     {}
0111 
0112 };
0113 
0114 } 
0115 } 
0116 } 
0117 
0118 #endif