Commit eeee7921 authored by Jarvis Dong's avatar Jarvis Dong
Browse files

remove 3rd party depends

parent 574e16da
/**
* Copyright (C) 2015 Topology LP
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#ifndef CPPCODEC_BASE32_CROCKFORD
#define CPPCODEC_BASE32_CROCKFORD
#include "detail/codec.hpp"
#include "detail/base32.hpp"
namespace cppcodec {
namespace detail {
static constexpr const char base32_crockford_alphabet[] = {
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', // at index 10
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', // 18 - no I
'J', 'K', // 20 - no L
'M', 'N', // 22 - no O
'P', 'Q', 'R', 'S', 'T', // 27 - no U
'V', 'W', 'X', 'Y', 'Z' // 32
};
class base32_crockford_base
{
public:
static CPPCODEC_ALWAYS_INLINE constexpr size_t alphabet_size() {
static_assert(sizeof(base32_crockford_alphabet) == 32, "base32 alphabet must have 32 values");
return sizeof(base32_crockford_alphabet);
}
static CPPCODEC_ALWAYS_INLINE constexpr char symbol(alphabet_index_t idx)
{
return base32_crockford_alphabet[idx];
}
static CPPCODEC_ALWAYS_INLINE constexpr char normalized_symbol(char c)
{
// Hex decoding is always case-insensitive (even in RFC 4648), the question
// is only for encoding whether to use upper-case or lower-case letters.
return (c == 'O' || c == 'o') ? '0'
: (c == 'I' || c == 'i' || c == 'L' || c == 'l') ? '1'
: (c >= 'a' && c <= 'z') ? (c - 'a' + 'A')
: c;
}
static CPPCODEC_ALWAYS_INLINE constexpr bool generates_padding() { return false; }
static CPPCODEC_ALWAYS_INLINE constexpr bool requires_padding() { return false; }
static CPPCODEC_ALWAYS_INLINE constexpr bool is_padding_symbol(char) { return false; }
static CPPCODEC_ALWAYS_INLINE constexpr bool is_eof_symbol(char c) { return c == '\0'; }
static CPPCODEC_ALWAYS_INLINE constexpr bool should_ignore(char c) {
return c == '-'; // "Hyphens (-) can be inserted into strings [for readability]."
}
};
// base32_crockford is a concatenative iterative (i.e. streaming) interpretation of Crockford base32.
// It interprets the statement "zero-extend the number to make its bit-length a multiple of 5"
// to mean zero-extending it on the right.
// (The other possible interpretation is base32_crockford_num, a place-based single number encoding system.
// See http://merrigrove.blogspot.ca/2014/04/what-heck-is-base64-encoding-really.html for more info.)
class base32_crockford : public base32_crockford_base
{
public:
template <typename Codec> using codec_impl = stream_codec<Codec, base32_crockford>;
};
} // namespace detail
using base32_crockford = detail::codec<detail::base32<detail::base32_crockford>>;
} // namespace cppcodec
#endif // CPPCODEC_BASE32_CROCKFORD
/**
* Copyright (C) 2015 Topology LP
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#ifndef CPPCODEC_BASE32_DEFAULT_CROCKFORD
#define CPPCODEC_BASE32_DEFAULT_CROCKFORD
#include "base32_crockford.hpp"
using base32 = cppcodec::base32_crockford;
#endif // CPPCODEC_BASE32_DEFAULT_CROCKFORD
/**
* Copyright (C) 2015, 2016 Topology LP
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#ifndef CPPCODEC_BASE32_DEFAULT_HEX
#define CPPCODEC_BASE32_DEFAULT_HEX
#include "base32_hex.hpp"
using base32 = cppcodec::base32_hex;
#endif // CPPCODEC_BASE32_DEFAULT_HEX
/**
* Copyright (C) 2015 Topology LP
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#ifndef CPPCODEC_BASE32_DEFAULT_RFC4648
#define CPPCODEC_BASE32_DEFAULT_RFC4648
#include "base32_rfc4648.hpp"
using base32 = cppcodec::base32_rfc4648;
#endif // CPPCODEC_BASE32_DEFAULT_RFC4648
/**
* Copyright (C) 2015, 2016 Topology LP
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#ifndef CPPCODEC_BASE32_HEX
#define CPPCODEC_BASE32_HEX
#include "detail/codec.hpp"
#include "detail/base32.hpp"
namespace cppcodec {
namespace detail {
// RFC 4648 also specifies a hex encoding system which uses 0-9, then A-V.
static constexpr const char base32_hex_alphabet[] = {
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',
'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V'
};
class base32_hex
{
public:
template <typename Codec> using codec_impl = stream_codec<Codec, base32_hex>;
static CPPCODEC_ALWAYS_INLINE constexpr size_t alphabet_size() {
static_assert(sizeof(base32_hex_alphabet) == 32, "base32 alphabet must have 32 values");
return sizeof(base32_hex_alphabet);
}
static CPPCODEC_ALWAYS_INLINE constexpr char symbol(alphabet_index_t idx)
{
return base32_hex_alphabet[idx];
}
static CPPCODEC_ALWAYS_INLINE constexpr char normalized_symbol(char c)
{
// Lower-case letters are accepted, though not generally expected.
return (c >= 'a' && c <= 'v') ? (c - 'a' + 'A') : c;
}
static CPPCODEC_ALWAYS_INLINE constexpr bool generates_padding() { return true; }
static CPPCODEC_ALWAYS_INLINE constexpr bool requires_padding() { return true; }
static CPPCODEC_ALWAYS_INLINE constexpr char padding_symbol() { return '='; }
static CPPCODEC_ALWAYS_INLINE constexpr bool is_padding_symbol(char c) { return c == '='; }
static CPPCODEC_ALWAYS_INLINE constexpr bool is_eof_symbol(char c) { return c == '\0'; }
// RFC4648 does not specify any whitespace being allowed in base32 encodings.
static CPPCODEC_ALWAYS_INLINE constexpr bool should_ignore(char) { return false; }
};
} // namespace detail
using base32_hex = detail::codec<detail::base32<detail::base32_hex>>;
} // namespace cppcodec
#endif // CPPCODEC_BASE32_HEX
/**
* Copyright (C) 2015 Topology LP
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#ifndef CPPCODEC_BASE32_RFC4648
#define CPPCODEC_BASE32_RFC4648
#include "detail/codec.hpp"
#include "detail/base32.hpp"
namespace cppcodec {
namespace detail {
// RFC 4648 uses a simple alphabet: A-Z starting at index 0, then 2-7 starting at index 26.
static constexpr const char base32_rfc4648_alphabet[] = {
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', // at index 26
'2', '3', '4', '5', '6', '7'
};
class base32_rfc4648
{
public:
template <typename Codec> using codec_impl = stream_codec<Codec, base32_rfc4648>;
static CPPCODEC_ALWAYS_INLINE constexpr size_t alphabet_size() {
static_assert(sizeof(base32_rfc4648_alphabet) == 32, "base32 alphabet must have 32 values");
return sizeof(base32_rfc4648_alphabet);
}
static CPPCODEC_ALWAYS_INLINE constexpr char symbol(alphabet_index_t idx)
{
return base32_rfc4648_alphabet[idx];
}
static CPPCODEC_ALWAYS_INLINE constexpr char normalized_symbol(char c)
{
// Lower-case letters are accepted, though not generally expected.
return (c >= 'a' && c <= 'z') ? (c - 'a' + 'A') : c;
}
static CPPCODEC_ALWAYS_INLINE constexpr bool generates_padding() { return true; }
static CPPCODEC_ALWAYS_INLINE constexpr bool requires_padding() { return true; }
static CPPCODEC_ALWAYS_INLINE constexpr char padding_symbol() { return '='; }
static CPPCODEC_ALWAYS_INLINE constexpr bool is_padding_symbol(char c) { return c == '='; }
static CPPCODEC_ALWAYS_INLINE constexpr bool is_eof_symbol(char c) { return c == '\0'; }
// RFC4648 does not specify any whitespace being allowed in base32 encodings.
static CPPCODEC_ALWAYS_INLINE constexpr bool should_ignore(char) { return false; }
};
} // namespace detail
using base32_rfc4648 = detail::codec<detail::base32<detail::base32_rfc4648>>;
} // namespace cppcodec
#endif // CPPCODEC_BASE32_RFC4648
/**
* Copyright (C) 2015 Topology LP
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#ifndef CPPCODEC_BASE64_DEFAULT_RFC4648
#define CPPCODEC_BASE64_DEFAULT_RFC4648
#include "base64_rfc4648.hpp"
using base64 = cppcodec::base64_rfc4648;
#endif // CPPCODEC_BASE64_DEFAULT_RFC4648
/**
* Copyright (C) 2015 Topology LP
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#ifndef CPPCODEC_BASE64_DEFAULT_URL
#define CPPCODEC_BASE64_DEFAULT_URL
#include "base64_url.hpp"
using base64 = cppcodec::base64_url;
#endif // CPPCODEC_BASE64_DEFAULT_URL
/**
* Copyright (C) 2016 Topology LP
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#ifndef CPPCODEC_BASE64_DEFAULT_URL_UNPADDED
#define CPPCODEC_BASE64_DEFAULT_URL_UNPADDED
#include "base64_url_unpadded.hpp"
using base64 = cppcodec::base64_url_unpadded;
#endif // CPPCODEC_BASE64_DEFAULT_URL_UNPADDED
/**
* Copyright (C) 2015 Topology LP
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#ifndef CPPCODEC_BASE64_RFC4648
#define CPPCODEC_BASE64_RFC4648
#include "detail/codec.hpp"
#include "detail/base64.hpp"
namespace cppcodec {
namespace detail {
static constexpr const char base64_rfc4648_alphabet[] = {
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'
};
class base64_rfc4648
{
public:
template <typename Codec> using codec_impl = stream_codec<Codec, base64_rfc4648>;
static CPPCODEC_ALWAYS_INLINE constexpr size_t alphabet_size() {
static_assert(sizeof(base64_rfc4648_alphabet) == 64, "base64 alphabet must have 64 values");
return sizeof(base64_rfc4648_alphabet);
}
static CPPCODEC_ALWAYS_INLINE constexpr char symbol(alphabet_index_t idx)
{
return base64_rfc4648_alphabet[idx];
}
static CPPCODEC_ALWAYS_INLINE constexpr char normalized_symbol(char c) { return c; }
static CPPCODEC_ALWAYS_INLINE constexpr bool generates_padding() { return true; }
static CPPCODEC_ALWAYS_INLINE constexpr bool requires_padding() { return true; }
static CPPCODEC_ALWAYS_INLINE constexpr char padding_symbol() { return '='; }
static CPPCODEC_ALWAYS_INLINE constexpr bool is_padding_symbol(char c) { return c == '='; }
static CPPCODEC_ALWAYS_INLINE constexpr bool is_eof_symbol(char c) { return c == '\0'; }
// RFC4648 does not specify any whitespace being allowed in base64 encodings.
static CPPCODEC_ALWAYS_INLINE constexpr bool should_ignore(char) { return false; }
};
} // namespace detail
using base64_rfc4648 = detail::codec<detail::base64<detail::base64_rfc4648>>;
} // namespace cppcodec
#endif // CPPCODEC_BASE64_RFC4648
/**
* Copyright (C) 2015 Topology LP
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#ifndef CPPCODEC_BASE64_URL
#define CPPCODEC_BASE64_URL
#include "detail/codec.hpp"
#include "detail/base64.hpp"
namespace cppcodec {
namespace detail {
// The URL and filename safe alphabet is also specified by RFC4648, named "base64url".
// We keep the underscore ("base64_url") for consistency with the other codec variants.
static constexpr const char base64_url_alphabet[] = {
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', '_'
};
class base64_url
{
public:
template <typename Codec> using codec_impl = stream_codec<Codec, base64_url>;
static CPPCODEC_ALWAYS_INLINE constexpr size_t alphabet_size() {
static_assert(sizeof(base64_url_alphabet) == 64, "base64 alphabet must have 64 values");
return sizeof(base64_url_alphabet);
}
static CPPCODEC_ALWAYS_INLINE constexpr char symbol(alphabet_index_t idx)
{
return base64_url_alphabet[idx];
}
static CPPCODEC_ALWAYS_INLINE constexpr char normalized_symbol(char c) { return c; }
static CPPCODEC_ALWAYS_INLINE constexpr bool generates_padding() { return true; }
static CPPCODEC_ALWAYS_INLINE constexpr bool requires_padding() { return true; }
static CPPCODEC_ALWAYS_INLINE constexpr char padding_symbol() { return '='; }
static CPPCODEC_ALWAYS_INLINE constexpr bool is_padding_symbol(char c) { return c == '='; }
static CPPCODEC_ALWAYS_INLINE constexpr bool is_eof_symbol(char c) { return c == '\0'; }
// RFC4648 does not specify any whitespace being allowed in base64 encodings.
static CPPCODEC_ALWAYS_INLINE constexpr bool should_ignore(char) { return false; }
};
} // namespace detail
using base64_url = detail::codec<detail::base64<detail::base64_url>>;
} // namespace cppcodec
#endif // CPPCODEC_BASE64_URL
/**
* Copyright (C) 2016 Topology LP
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*