update credits
[LibreOffice.git] / comphelper / source / xml / xmltools.cxx
blob83387d56c1590d1d86167f3179dae5c2493fc71a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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 */
10 #include <comphelper/xmltools.hxx>
11 #include <rtl/random.h>
12 #include <boost/static_assert.hpp>
13 #include <vector>
15 using namespace com::sun::star;
17 namespace
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[] =
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', '/',
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', '/',
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', '/',
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', '/'
61 void encodeChaff(std::vector<sal_uInt8> &rChaff)
63 BOOST_STATIC_ASSERT(sizeof(aChaffEncoder) == 256);
65 for (std::vector<sal_uInt8>::iterator aI = rChaff.begin(), aEnd = rChaff.end();
66 aI != aEnd; ++aI)
68 *aI = aChaffEncoder[*aI];
73 namespace comphelper
75 namespace xml
77 OString makeXMLChaff()
79 rtlRandomPool pool = rtl_random_createPool();
81 sal_Int8 n;
82 rtl_random_getBytes(pool, &n, 1);
84 //1024 minus max -127/plus max 128
85 sal_Int32 nLength = 1024+n;
86 std::vector<sal_uInt8> aChaff(nLength);
87 rtl_random_getBytes(pool, &aChaff[0], nLength);
89 rtl_random_destroyPool(pool);
91 encodeChaff(aChaff);
93 return OString(reinterpret_cast<const sal_Char*>(&aChaff[0]), nLength);
97 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */