MCPcopy Create free account
hub / github.com/OpenDDS/OpenDDS / b32h_encode

Function b32h_encode

dds/DCPS/FileSystemStorage.cpp:870–900  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

868// Base32Hex
869
870ACE_TString b32h_encode(const ACE_TCHAR* decoded)
871{
872 static const ACE_TCHAR lookup[] =
873 ACE_TEXT("0123456789ABCDEFGHIJKLMNOPQRSTUV");
874 static const ACE_TCHAR padding[] = ACE_TEXT("======");
875 static const size_t enc[] = {0, 2, 4, 5, 7}; // #input -> #non-padded output
876 ACE_TString encoded;
877
878 for (size_t len = ACE_OS::strlen(decoded); *decoded; decoded += 5, len -= 5) {
879 ACE_UINT64 chunk = 0;
880
881 for (size_t i(0); i < 5 && i < len; ++i) {
882 chunk |= static_cast<ACE_UINT64>(decoded[i] & 0xFF) << ((4 - i) * 8);
883 }
884
885 size_t limit = (len < 5) ? enc[len] : 8;
886
887 for (size_t i(0); i < limit; ++i) {
888 unsigned char val =
889 static_cast<unsigned char>(chunk >>((7 - i) * 5)) & 0x1F;
890 encoded += lookup[val];
891 }
892
893 if (len < 5) {
894 encoded.append(padding, 8 - enc[len]);
895 return encoded;
896 }
897 }
898
899 return encoded;
900}
901
902ACE_TString b32h_decode(const ACE_TCHAR* encoded)
903{

Callers 3

make_new_fileMethod · 0.85
make_new_subdirMethod · 0.85
encode_testFunction · 0.85

Calls 1

appendMethod · 0.45

Tested by 1

encode_testFunction · 0.68