LCOV - code coverage report
Current view: top level - comphelper/source/xml - xmltools.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 13 13 100.0 %
Date: 2015-06-13 12:38:46 Functions: 2 2 100.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 <vector>
      13             : 
      14             : using namespace com::sun::star;
      15             : 
      16             : namespace
      17             : {
      18             :     //Will be inside an xml comment, so can't use '-' in case '--' appears in
      19             :     //output, etc. Despite what *is* legal in an xml comment, just using the
      20             :     //base-64 subset to avoid pain with simplistic third-party parsers
      21             :     static const sal_uInt8 aChaffEncoder[] =
      22             :     {
      23             :         'A', 'Q', 'g', 'w', 'B', 'R', 'h', 'x',
      24             :         'C', 'S', 'i', 'y', 'D', 'T', 'j', 'z',
      25             :         'E', 'U', 'k', '0', 'F', 'V', 'l', '1',
      26             :         'G', 'W', 'm', '2', 'H', 'X', 'n', '3',
      27             :         'I', 'Y', 'o', '4', 'J', 'Z', 'p', '5',
      28             :         'K', 'a', 'q', '6', 'L', 'b', 'r', '7',
      29             :         'M', 'c', 's', '8', 'N', 'd', 't', '9',
      30             :         'O', 'e', 'u', '+', 'P', 'f', 'v', '/',
      31             : 
      32             :         'A', 'Q', 'g', 'w', 'B', 'R', 'h', 'x',
      33             :         'C', 'S', 'i', 'y', 'D', 'T', 'j', 'z',
      34             :         'E', 'U', 'k', '0', 'F', 'V', 'l', '1',
      35             :         'G', 'W', 'm', '2', 'H', 'X', 'n', '3',
      36             :         'I', 'Y', 'o', '4', 'J', 'Z', 'p', '5',
      37             :         'K', 'a', 'q', '6', 'L', 'b', 'r', '7',
      38             :         'M', 'c', 's', '8', 'N', 'd', 't', '9',
      39             :         'O', 'e', 'u', '+', 'P', 'f', 'v', '/',
      40             : 
      41             :         'A', 'Q', 'g', 'w', 'B', 'R', 'h', 'x',
      42             :         'C', 'S', 'i', 'y', 'D', 'T', 'j', 'z',
      43             :         'E', 'U', 'k', '0', 'F', 'V', 'l', '1',
      44             :         'G', 'W', 'm', '2', 'H', 'X', 'n', '3',
      45             :         'I', 'Y', 'o', '4', 'J', 'Z', 'p', '5',
      46             :         'K', 'a', 'q', '6', 'L', 'b', 'r', '7',
      47             :         'M', 'c', 's', '8', 'N', 'd', 't', '9',
      48             :         'O', 'e', 'u', '+', 'P', 'f', 'v', '/',
      49             : 
      50             :         'A', 'Q', 'g', 'w', 'B', 'R', 'h', 'x',
      51             :         'C', 'S', 'i', 'y', 'D', 'T', 'j', 'z',
      52             :         'E', 'U', 'k', '0', 'F', 'V', 'l', '1',
      53             :         'G', 'W', 'm', '2', 'H', 'X', 'n', '3',
      54             :         'I', 'Y', 'o', '4', 'J', 'Z', 'p', '5',
      55             :         'K', 'a', 'q', '6', 'L', 'b', 'r', '7',
      56             :         'M', 'c', 's', '8', 'N', 'd', 't', '9',
      57             :         'O', 'e', 'u', '+', 'P', 'f', 'v', '/'
      58             :     };
      59             : 
      60           4 :     void encodeChaff(std::vector<sal_uInt8> &rChaff)
      61             :     {
      62             :         static_assert(sizeof(aChaffEncoder) == 256, "this has to cover all chars");
      63             : 
      64        3922 :         for (std::vector<sal_uInt8>::iterator aI = rChaff.begin(), aEnd = rChaff.end();
      65             :             aI != aEnd; ++aI)
      66             :         {
      67        3918 :             *aI = aChaffEncoder[*aI];
      68             :         }
      69           4 :     }
      70             : }
      71             : 
      72             : namespace comphelper
      73             : {
      74             :     namespace xml
      75             :     {
      76           4 :         OString makeXMLChaff()
      77             :         {
      78           4 :             rtlRandomPool pool = rtl_random_createPool();
      79             : 
      80             :             sal_Int8 n;
      81           4 :             rtl_random_getBytes(pool, &n, 1);
      82             : 
      83             :             //1024 minus max -127/plus max 128
      84           4 :             sal_Int32 nLength = 1024+n;
      85           4 :             std::vector<sal_uInt8> aChaff(nLength);
      86           4 :             rtl_random_getBytes(pool, &aChaff[0], nLength);
      87             : 
      88           4 :             rtl_random_destroyPool(pool);
      89             : 
      90           4 :             encodeChaff(aChaff);
      91             : 
      92           4 :             return OString(reinterpret_cast<const sal_Char*>(&aChaff[0]), nLength);
      93             :         }
      94             :     }
      95             : }
      96             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11