Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * Version: MPL 1.1 / GPLv3+ / LGPLv3+
4 : : *
5 : : * The contents of this file are subject to the Mozilla Public License Version
6 : : * 1.1 (the "License"); you may not use this file except in compliance with
7 : : * the License or as specified alternatively below. You may obtain a copy of
8 : : * the License at http://www.mozilla.org/MPL/
9 : : *
10 : : * Software distributed under the License is distributed on an "AS IS" basis,
11 : : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : : * for the specific language governing rights and limitations under the
13 : : * License.
14 : : *
15 : : * Major Contributor(s):
16 : : * Copyright (C) 2011 Red Hat, Inc., Caolán McNamara <caolanm@redhat.com>
17 : : * (initial developer)
18 : : *
19 : : * All Rights Reserved.
20 : : *
21 : : * For minor contributions see the git repository.
22 : : *
23 : : * Alternatively, the contents of this file may be used under the terms of
24 : : * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
25 : : * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
26 : : * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
27 : : * instead of those above.
28 : : */
29 : :
30 : : #include <comphelper/xmltools.hxx>
31 : : #include <rtl/random.h>
32 : : #include <boost/static_assert.hpp>
33 : : #include <vector>
34 : :
35 : : using namespace com::sun::star;
36 : :
37 : : namespace
38 : : {
39 : : //Will be inside an xml comment, so can't use '-' in case '--' appears in
40 : : //output, etc. Despite what *is* legal in an xml comment, just using the
41 : : //base-64 subset to avoid pain with simplistic third-party parsers
42 : : static const sal_uInt8 aChaffEncoder[] =
43 : : {
44 : : 'A', 'Q', 'g', 'w', 'B', 'R', 'h', 'x',
45 : : 'C', 'S', 'i', 'y', 'D', 'T', 'j', 'z',
46 : : 'E', 'U', 'k', '0', 'F', 'V', 'l', '1',
47 : : 'G', 'W', 'm', '2', 'H', 'X', 'n', '3',
48 : : 'I', 'Y', 'o', '4', 'J', 'Z', 'p', '5',
49 : : 'K', 'a', 'q', '6', 'L', 'b', 'r', '7',
50 : : 'M', 'c', 's', '8', 'N', 'd', 't', '9',
51 : : 'O', 'e', 'u', '+', 'P', 'f', 'v', '/',
52 : :
53 : : 'A', 'Q', 'g', 'w', 'B', 'R', 'h', 'x',
54 : : 'C', 'S', 'i', 'y', 'D', 'T', 'j', 'z',
55 : : 'E', 'U', 'k', '0', 'F', 'V', 'l', '1',
56 : : 'G', 'W', 'm', '2', 'H', 'X', 'n', '3',
57 : : 'I', 'Y', 'o', '4', 'J', 'Z', 'p', '5',
58 : : 'K', 'a', 'q', '6', 'L', 'b', 'r', '7',
59 : : 'M', 'c', 's', '8', 'N', 'd', 't', '9',
60 : : 'O', 'e', 'u', '+', 'P', 'f', 'v', '/',
61 : :
62 : : 'A', 'Q', 'g', 'w', 'B', 'R', 'h', 'x',
63 : : 'C', 'S', 'i', 'y', 'D', 'T', 'j', 'z',
64 : : 'E', 'U', 'k', '0', 'F', 'V', 'l', '1',
65 : : 'G', 'W', 'm', '2', 'H', 'X', 'n', '3',
66 : : 'I', 'Y', 'o', '4', 'J', 'Z', 'p', '5',
67 : : 'K', 'a', 'q', '6', 'L', 'b', 'r', '7',
68 : : 'M', 'c', 's', '8', 'N', 'd', 't', '9',
69 : : 'O', 'e', 'u', '+', 'P', 'f', 'v', '/',
70 : :
71 : : 'A', 'Q', 'g', 'w', 'B', 'R', 'h', 'x',
72 : : 'C', 'S', 'i', 'y', 'D', 'T', 'j', 'z',
73 : : 'E', 'U', 'k', '0', 'F', 'V', 'l', '1',
74 : : 'G', 'W', 'm', '2', 'H', 'X', 'n', '3',
75 : : 'I', 'Y', 'o', '4', 'J', 'Z', 'p', '5',
76 : : 'K', 'a', 'q', '6', 'L', 'b', 'r', '7',
77 : : 'M', 'c', 's', '8', 'N', 'd', 't', '9',
78 : : 'O', 'e', 'u', '+', 'P', 'f', 'v', '/'
79 : : };
80 : :
81 : 0 : void encodeChaff(std::vector<sal_uInt8> &rChaff)
82 : : {
83 : : BOOST_STATIC_ASSERT(sizeof(aChaffEncoder) == 256);
84 : :
85 [ # # ][ # # ]: 0 : for (std::vector<sal_uInt8>::iterator aI = rChaff.begin(), aEnd = rChaff.end();
[ # # ]
86 : : aI != aEnd; ++aI)
87 : : {
88 [ # # ][ # # ]: 0 : *aI = aChaffEncoder[*aI];
89 : : }
90 : 0 : }
91 : : }
92 : :
93 : : namespace comphelper
94 : : {
95 : : namespace xml
96 : : {
97 : 0 : rtl::OString makeXMLChaff()
98 : : {
99 : 0 : rtlRandomPool pool = rtl_random_createPool();
100 : :
101 : : sal_Int8 n;
102 : 0 : rtl_random_getBytes(pool, &n, 1);
103 : :
104 : : //1024 minus max -127/plus max 128
105 : 0 : sal_Int32 nLength = 1024+n;
106 [ # # ]: 0 : std::vector<sal_uInt8> aChaff(nLength);
107 [ # # ]: 0 : rtl_random_getBytes(pool, &aChaff[0], nLength);
108 : :
109 : 0 : rtl_random_destroyPool(pool);
110 : :
111 [ # # ]: 0 : encodeChaff(aChaff);
112 : :
113 [ # # ]: 0 : return rtl::OString(reinterpret_cast<const sal_Char*>(&aChaff[0]), nLength);
114 : : }
115 : : }
116 : : }
117 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|