LCOV - code coverage report
Current view: top level - comphelper/source/xml - xmltools.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 13 0.0 %
Date: 2014-04-14 Functions: 0 2 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  */
       9             : 
      10             : #include <comphelper/xmltools.hxx>
      11             : #include <rtl/random.h>
      12             : #include <boost/static_assert.hpp>
      13             : #include <vector>
      14             : 
      15             : using namespace com::sun::star;
      16             : 
      17             : namespace
      18             : {
      19             :     //Will be inside an xml comment, so can't use '-' in case '--' appears in
      20             :     //output, etc. Despite what *is* legal in an xml comment, just using the
      21             :     //base-64 subset to avoid pain with simplistic third-party parsers
      22             :     static const sal_uInt8 aChaffEncoder[] =
      23             :     {
      24             :         'A', 'Q', 'g', 'w', 'B', 'R', 'h', 'x',
      25             :         'C', 'S', 'i', 'y', 'D', 'T', 'j', 'z',
      26             :         'E', 'U', 'k', '0', 'F', 'V', 'l', '1',
      27             :         'G', 'W', 'm', '2', 'H', 'X', 'n', '3',
      28             :         'I', 'Y', 'o', '4', 'J', 'Z', 'p', '5',
      29             :         'K', 'a', 'q', '6', 'L', 'b', 'r', '7',
      30             :         'M', 'c', 's', '8', 'N', 'd', 't', '9',
      31             :         'O', 'e', 'u', '+', 'P', 'f', 'v', '/',
      32             : 
      33             :         'A', 'Q', 'g', 'w', 'B', 'R', 'h', 'x',
      34             :         'C', 'S', 'i', 'y', 'D', 'T', 'j', 'z',
      35             :         'E', 'U', 'k', '0', 'F', 'V', 'l', '1',
      36             :         'G', 'W', 'm', '2', 'H', 'X', 'n', '3',
      37             :         'I', 'Y', 'o', '4', 'J', 'Z', 'p', '5',
      38             :         'K', 'a', 'q', '6', 'L', 'b', 'r', '7',
      39             :         'M', 'c', 's', '8', 'N', 'd', 't', '9',
      40             :         'O', 'e', 'u', '+', 'P', 'f', 'v', '/',
      41             : 
      42             :         'A', 'Q', 'g', 'w', 'B', 'R', 'h', 'x',
      43             :         'C', 'S', 'i', 'y', 'D', 'T', 'j', 'z',
      44             :         'E', 'U', 'k', '0', 'F', 'V', 'l', '1',
      45             :         'G', 'W', 'm', '2', 'H', 'X', 'n', '3',
      46             :         'I', 'Y', 'o', '4', 'J', 'Z', 'p', '5',
      47             :         'K', 'a', 'q', '6', 'L', 'b', 'r', '7',
      48             :         'M', 'c', 's', '8', 'N', 'd', 't', '9',
      49             :         'O', 'e', 'u', '+', 'P', 'f', 'v', '/',
      50             : 
      51             :         'A', 'Q', 'g', 'w', 'B', 'R', 'h', 'x',
      52             :         'C', 'S', 'i', 'y', 'D', 'T', 'j', 'z',
      53             :         'E', 'U', 'k', '0', 'F', 'V', 'l', '1',
      54             :         'G', 'W', 'm', '2', 'H', 'X', 'n', '3',
      55             :         'I', 'Y', 'o', '4', 'J', 'Z', 'p', '5',
      56             :         'K', 'a', 'q', '6', 'L', 'b', 'r', '7',
      57             :         'M', 'c', 's', '8', 'N', 'd', 't', '9',
      58             :         'O', 'e', 'u', '+', 'P', 'f', 'v', '/'
      59             :     };
      60             : 
      61           0 :     void encodeChaff(std::vector<sal_uInt8> &rChaff)
      62             :     {
      63             :         BOOST_STATIC_ASSERT(sizeof(aChaffEncoder) == 256);
      64             : 
      65           0 :         for (std::vector<sal_uInt8>::iterator aI = rChaff.begin(), aEnd = rChaff.end();
      66             :             aI != aEnd; ++aI)
      67             :         {
      68           0 :             *aI = aChaffEncoder[*aI];
      69             :         }
      70           0 :     }
      71             : }
      72             : 
      73             : namespace comphelper
      74             : {
      75             :     namespace xml
      76             :     {
      77           0 :         OString makeXMLChaff()
      78             :         {
      79           0 :             rtlRandomPool pool = rtl_random_createPool();
      80             : 
      81             :             sal_Int8 n;
      82           0 :             rtl_random_getBytes(pool, &n, 1);
      83             : 
      84             :             //1024 minus max -127/plus max 128
      85           0 :             sal_Int32 nLength = 1024+n;
      86           0 :             std::vector<sal_uInt8> aChaff(nLength);
      87           0 :             rtl_random_getBytes(pool, &aChaff[0], nLength);
      88             : 
      89           0 :             rtl_random_destroyPool(pool);
      90             : 
      91           0 :             encodeChaff(aChaff);
      92             : 
      93           0 :             return OString(reinterpret_cast<const sal_Char*>(&aChaff[0]), nLength);
      94             :         }
      95             :     }
      96             : }
      97             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10