| 232 | } |
| 233 | |
| 234 | size_t Base32ToByteStream (std::string_view base32Str, uint8_t * outBuf, size_t outLen) |
| 235 | { |
| 236 | unsigned int tmp = 0, bits = 0; |
| 237 | size_t ret = 0; |
| 238 | for (auto ch: base32Str) |
| 239 | { |
| 240 | if (ch >= '2' && ch <= '7') // digit |
| 241 | ch = (ch - '2') + 26; // 26 means a-z |
| 242 | else if (ch >= 'a' && ch <= 'z') |
| 243 | ch = ch - 'a'; // a = 0 |
| 244 | else |
| 245 | return 0; // unexpected character |
| 246 | |
| 247 | tmp |= ch; |
| 248 | bits += 5; |
| 249 | if (bits >= 8) |
| 250 | { |
| 251 | if (ret >= outLen) return ret; |
| 252 | outBuf[ret] = tmp >> (bits - 8); |
| 253 | bits -= 8; |
| 254 | ret++; |
| 255 | } |
| 256 | tmp <<= 5; |
| 257 | } |
| 258 | return ret; |
| 259 | } |
| 260 | |
| 261 | std::string ByteStreamToBase32 (const uint8_t * inBuf, size_t len) |
| 262 | { |
no outgoing calls
no test coverage detected