PageRenderTime 55ms CodeModel.GetById 51ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llcommon/llbase64.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 61 lines | 21 code | 8 blank | 32 comment | 2 complexity | a39d38d4d1bfce52be6379abd0f7300b MD5 | raw file
 1/** 
 2 * @file llbase64.cpp
 3 * @brief Wrapper for apr base64 encoding that returns a std::string
 4 * @author James Cook
 5 *
 6 * $LicenseInfo:firstyear=2007&license=viewerlgpl$
 7 * Second Life Viewer Source Code
 8 * Copyright (C) 2010, Linden Research, Inc.
 9 * 
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation;
13 * version 2.1 of the License only.
14 * 
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 * Lesser General Public License for more details.
19 * 
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
23 * 
24 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
25 * $/LicenseInfo$
26 */
27
28#include "linden_common.h"
29
30#include "llbase64.h"
31
32#include <string>
33
34#include "apr_base64.h"
35
36
37// static
38std::string LLBase64::encode(const U8* input, size_t input_size)
39{
40	std::string output;
41	if (input
42		&& input_size > 0)
43	{
44		// Yes, it returns int.
45		int b64_buffer_length = apr_base64_encode_len(input_size);
46		char* b64_buffer = new char[b64_buffer_length];
47		
48		// This is faster than apr_base64_encode() if you know
49		// you're not on an EBCDIC machine.  Also, the output is
50		// null terminated, even though the documentation doesn't
51		// specify.  See apr_base64.c for details. JC
52		b64_buffer_length = apr_base64_encode_binary(
53			b64_buffer,
54			input,
55			input_size);
56		output.assign(b64_buffer);
57		delete[] b64_buffer;
58	}
59	return output;
60}
61