1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
10 #include <comphelper/xmltools.hxx>
11 #include <rtl/random.h>
14 using namespace com::sun::star
;
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
[] =
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', '/',
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', '/',
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', '/',
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', '/'
60 void encodeChaff(std::vector
<sal_uInt8
> &rChaff
)
62 static_assert(sizeof(aChaffEncoder
) == 256, "this has to cover all chars");
64 for (std::vector
<sal_uInt8
>::iterator aI
= rChaff
.begin(), aEnd
= rChaff
.end();
67 *aI
= aChaffEncoder
[*aI
];
76 OString
makeXMLChaff()
78 rtlRandomPool pool
= rtl_random_createPool();
81 rtl_random_getBytes(pool
, &n
, 1);
83 //1024 minus max -127/plus max 128
84 sal_Int32 nLength
= 1024+n
;
85 std::vector
<sal_uInt8
> aChaff(nLength
);
86 rtl_random_getBytes(pool
, &aChaff
[0], nLength
);
88 rtl_random_destroyPool(pool
);
92 return OString(reinterpret_cast<const sal_Char
*>(&aChaff
[0]), nLength
);
96 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */