mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-07-25 13:53:09 +00:00
Removes unused base32 encoding added in 5cc814759f.
For modern standards base64 costs a bit less space and might be implemented on demand. base32 usage was introduced ine0dfbe719dand removed in93cffe9deb. Refsa34b759720,317f98a6c0. This was SVN commit r25568.
This commit is contained in:
@@ -1,60 +0,0 @@
|
||||
/* Copyright (C) 2010 Wildfire Games.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* base32 conversion
|
||||
*/
|
||||
|
||||
#include "precompiled.h"
|
||||
|
||||
|
||||
// big endian!
|
||||
void base32(const size_t in_len, const u8* in, u8* out)
|
||||
{
|
||||
u32 pool = 0; // of bits from buffer
|
||||
ssize_t pool_bits = 0; // # bits currently in buffer
|
||||
|
||||
static const u8 tbl[33] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
|
||||
|
||||
size_t in_bytes_left = in_len; // to avoid overrunning input buffer
|
||||
const size_t out_chars = (in_len*8 + 4) / 5; // = ceil(# 5-bit blocks)
|
||||
for(size_t i = 0; i < out_chars; i++)
|
||||
{
|
||||
if(pool_bits < 5 && in_bytes_left)
|
||||
{
|
||||
pool <<= 8;
|
||||
pool |= *in++;
|
||||
pool_bits += 8;
|
||||
in_bytes_left--;
|
||||
}
|
||||
|
||||
pool_bits -= 5;
|
||||
size_t c;
|
||||
if (pool_bits < 0)
|
||||
c = (pool << -pool_bits) & 31;
|
||||
else
|
||||
c = (pool >> pool_bits) & 31;
|
||||
*out++ = tbl[c];
|
||||
}
|
||||
|
||||
*out++ = '\0';
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
/* Copyright (C) 2010 Wildfire Games.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* base32 conversion
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_BASE32
|
||||
#define INCLUDED_BASE32
|
||||
|
||||
/**
|
||||
* generate the base32 textual representation of a buffer.
|
||||
*
|
||||
* @param len Size [bytes] of input
|
||||
* @param in Big-endian input data (assumed to be integral number of bytes)
|
||||
* @param out Output string; zero-terminated. must be big enough
|
||||
* (i.e. at least ceil(len*CHAR_BIT/5) + 1 chars)
|
||||
**/
|
||||
extern void base32(const size_t len, const u8* in, u8* out);
|
||||
|
||||
#endif // #ifndef INCLUDED_BASE32
|
||||
@@ -1,62 +0,0 @@
|
||||
/* Copyright (C) 2010 Wildfire Games.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "lib/self_test.h"
|
||||
|
||||
#include "lib/base32.h"
|
||||
|
||||
class TestBase32 : public CxxTest::TestSuite
|
||||
{
|
||||
public:
|
||||
void test_base32()
|
||||
{
|
||||
// compare against previous output (generated via this base32() call)
|
||||
const u8 in[] = { 0x12, 0x57, 0x85, 0xA2, 0xF9, 0x41, 0xCD, 0x57, 0xF3 };
|
||||
u8 out[20] = {0};
|
||||
base32(ARRAY_SIZE(in), in, out);
|
||||
const u8 correct_out[] = "CJLYLIXZIHGVP4Y";
|
||||
TS_ASSERT_SAME_DATA(out, correct_out, ARRAY_SIZE(correct_out));
|
||||
}
|
||||
|
||||
void test_base32_lengths()
|
||||
{
|
||||
#define TEST(in, expected) \
|
||||
{ \
|
||||
u8 out[20] = {0}; \
|
||||
base32(ARRAY_SIZE(in), in, out); \
|
||||
const u8 correct_out[] = expected; \
|
||||
TS_ASSERT_SAME_DATA(out, correct_out, ARRAY_SIZE(correct_out)); \
|
||||
}
|
||||
const u8 in1[] = { 0xFF };
|
||||
const u8 in2[] = { 0xFF, 0xFF };
|
||||
const u8 in3[] = { 0xFF, 0xFF, 0xFF };
|
||||
const u8 in4[] = { 0xFF, 0xFF, 0xFF, 0xFF };
|
||||
const u8 in5[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
|
||||
const u8 in6[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
|
||||
TEST(in1, "74");
|
||||
TEST(in2, "777Q");
|
||||
TEST(in3, "77776");
|
||||
TEST(in4, "777777Y");
|
||||
TEST(in5, "77777777");
|
||||
TEST(in6, "7777777774");
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user