[Merge] lp:~pete-woods/net-cpp/base64 into lp:net-cpp

Thomas Voß thomas.voss at canonical.com
Thu Jun 5 14:12:29 UTC 2014


Review: Needs Information

I think the symbols file needs an update. Did you try running a package build?

Diff comments:

> === modified file 'debian/control'
> --- debian/control	2014-05-06 14:15:08 +0000
> +++ debian/control	2014-06-04 15:04:33 +0000
> @@ -7,6 +7,7 @@
>                 google-mock,
>                 graphviz,
>                 libboost-dev,
> +               libboost-serialization-dev,
>                 libboost-system-dev,
>                 libcurl3,
>                 libcurl4-openssl-dev,
> 
> === modified file 'include/core/net/http/client.h'
> --- include/core/net/http/client.h	2014-05-06 11:05:04 +0000
> +++ include/core/net/http/client.h	2014-06-04 15:04:33 +0000
> @@ -98,6 +98,12 @@
>      /** @brief Percent-encodes the given string. */
>      virtual std::string url_escape(const std::string& s) const = 0;
>  
> +    /** @brief Base64-encodes the given string. */
> +    virtual std::string base64_encode(const std::string& s) const = 0;
> +
> +    /** @brief Base64-decodes the given string. */
> +    virtual std::string base64_decode(const std::string& s) const = 0;
> +
>      /** @brief Queries timing statistics over all requests that have been executed by this client. */
>      virtual Timings timings() = 0;
>  
> 
> === modified file 'src/CMakeLists.txt'
> --- src/CMakeLists.txt	2014-05-05 15:08:01 +0000
> +++ src/CMakeLists.txt	2014-06-04 15:04:33 +0000
> @@ -14,7 +14,7 @@
>  #
>  # Authored by: Thomas Voss <thomas.voss at canonical.com>
>  
> -find_package(Boost COMPONENTS system REQUIRED)
> +find_package(Boost COMPONENTS system serialization REQUIRED)
>  find_package(CURL REQUIRED)
>  
>  include_directories(${Boost_INCLUDE_DIRS} ${CURL_INCLUDE_DIRS})
> 
> === modified file 'src/core/net/http/impl/curl/client.cpp'
> --- src/core/net/http/impl/curl/client.cpp	2014-05-06 07:57:16 +0000
> +++ src/core/net/http/impl/curl/client.cpp	2014-06-04 15:04:33 +0000
> @@ -22,8 +22,21 @@
>  
>  #include <core/net/http/method.h>
>  
> +#include <boost/archive/iterators/base64_from_binary.hpp>
> +#include <boost/archive/iterators/binary_from_base64.hpp>
> +#include <boost/archive/iterators/transform_width.hpp>
> +#include <boost/archive/iterators/ostream_iterator.hpp>
> +
>  namespace net = core::net;
>  namespace http = core::net::http;
> +namespace bai = boost::archive::iterators;
> +
> +namespace
> +{
> +

Unneeded whitespace.

> +const std::string BASE64_PADDING[] = { "", "==", "=" };
> +

Unneeded whitespace.

> +}
>  
>  http::impl::curl::Client::Client()
>  {
> @@ -35,6 +48,52 @@
>      return ::curl::native::escape(s);
>  }
>  
> +std::string http::impl::curl::Client::base64_encode(const std::string& s) const
> +{
> +    std::stringstream os;
> +
> +    // convert binary values to base64 characters
> +    typedef bai::base64_from_binary
> +    // retrieve 6 bit integers from a sequence of 8 bit bytes
> +    <bai::transform_width<const char *, 6, 8> > base64_enc;
> +
> +    std::copy(base64_enc(s.c_str()), base64_enc(s.c_str() + s.size()),
> +            std::ostream_iterator<char>(os));
> +
> +    os << BASE64_PADDING[s.size() % 3];
> +
> +    return os.str();
> +}
> +
> +std::string http::impl::curl::Client::base64_decode(const std::string& s) const
> +{
> +    std::stringstream os;
> +
> +    typedef bai::transform_width<bai::binary_from_base64<const char *>, 8, 6> base64_dec;
> +
> +    unsigned int size = s.size();
> +
> +    // Remove the padding characters
> +    // See: https://svn.boost.org/trac/boost/ticket/5629
> +    if (size && s[size - 1] == '=')
> +    {
> +        --size;
> +        if (size && s[size - 1] == '=')
> +        {
> +            --size;
> +        }
> +    }
> +    if (size == 0)
> +    {
> +        return std::string();
> +    }
> +
> +    std::copy(base64_dec(s.data()), base64_dec(s.data() + size),
> +            std::ostream_iterator<char>(os));
> +
> +    return os.str();
> +}
> +
>  core::net::http::Client::Timings http::impl::curl::Client::timings()
>  {
>      return multi.timings();
> 
> === modified file 'src/core/net/http/impl/curl/client.h'
> --- src/core/net/http/impl/curl/client.h	2014-03-18 12:33:18 +0000
> +++ src/core/net/http/impl/curl/client.h	2014-06-04 15:04:33 +0000
> @@ -40,6 +40,10 @@
>      // From core::net::http::Client
>      std::string url_escape(const std::string& s) const;
>  
> +    std::string base64_encode(const std::string& s) const override;
> +
> +    std::string base64_decode(const std::string& s) const override;
> +
>      core::net::http::Client::Timings timings();
>  
>      void run();
> 
> === modified file 'tests/http_client_test.cpp'
> --- tests/http_client_test.cpp	2014-05-22 12:11:07 +0000
> +++ tests/http_client_test.cpp	2014-06-04 15:04:33 +0000
> @@ -550,3 +550,45 @@
>                response.status);
>  }
>  
> +typedef std::pair<std::string, std::string> Base64TestParams;
> +
> +class HttpClientBase64Test : public ::testing::TestWithParam<Base64TestParams> {
> +};
> +
> +TEST_P(HttpClientBase64Test, encoder)
> +{
> +    // We obtain a default client instance, dispatching to the default implementation.
> +    auto client = http::make_client();
> +
> +    // Get our encoding parameters
> +    auto param = GetParam();
> +
> +    // Try the base64 encode out
> +    EXPECT_EQ(param.second, client->base64_encode(param.first));
> +}
> +
> +TEST_P(HttpClientBase64Test, decoder)
> +{
> +    // We obtain a default client instance, dispatching to the default implementation.
> +    auto client = http::make_client();
> +
> +    // Get our encoding parameters
> +    auto param = GetParam();
> +
> +    // Try the base64 decode out
> +    EXPECT_EQ(param.first, client->base64_decode(param.second));
> +}
> +
> +INSTANTIATE_TEST_CASE_P(Base64Fixtures, HttpClientBase64Test,
> +        ::testing::Values(
> +                Base64TestParams("", ""),
> +                Base64TestParams("M", "TQ=="),
> +                Base64TestParams("Ma", "TWE="),
> +                Base64TestParams("Man", "TWFu"),
> +                Base64TestParams("pleasure.", "cGxlYXN1cmUu"),
> +                Base64TestParams("leasure.", "bGVhc3VyZS4="),
> +                Base64TestParams("easure.", "ZWFzdXJlLg=="),
> +                Base64TestParams("asure.", "YXN1cmUu"),
> +                Base64TestParams("sure.", "c3VyZS4="),
> +                Base64TestParams("bananas are tasty", "YmFuYW5hcyBhcmUgdGFzdHk=")
> +        ));
> 


-- 
https://code.launchpad.net/~pete-woods/net-cpp/base64/+merge/222055
Your team Ubuntu Phablet Team is requested to review the proposed merge of lp:~pete-woods/net-cpp/base64 into lp:net-cpp.



More information about the Ubuntu-reviews mailing list