Appends up to 64 random chars to the given pointer. Returns the end of the appended chars.
| 822 | |
| 823 | // Appends up to 64 random chars to the given pointer. Returns the end of the appended chars. |
| 824 | char* Generate64RandomChars(char* out) { |
| 825 | size_t amount = 32; |
| 826 | while (amount > 0) { |
| 827 | unsigned char buf[32]; |
| 828 | ssize_t res = getrandom(buf, amount, 0); |
| 829 | if (res == -1) { |
| 830 | if (errno == EINTR) |
| 831 | continue; |
| 832 | else |
| 833 | break; // too bad, urandom isn't working well |
| 834 | } |
| 835 | amount -= res; |
| 836 | // we encode each random char using two chars, since they must be [A-Z][a-z][0-9]_ |
| 837 | for (size_t i = 0; i != static_cast<size_t>(res); ++i) { |
| 838 | *out++ = 'A' + static_cast<char>(buf[i] & 15); |
| 839 | *out++ = 'A' + static_cast<char>(buf[i] >> 4); |
| 840 | } |
| 841 | } |
| 842 | return out; |
| 843 | } |
| 844 | |
| 845 | constexpr const char STR_RESPONSE_HANDLE_PREFIX[] = "/org/freedesktop/portal/desktop/request/"; |
| 846 | constexpr size_t STR_RESPONSE_HANDLE_PREFIX_LEN = |
no outgoing calls
no test coverage detected