| 38 | } |
| 39 | |
| 40 | string GPWriter::constructRandomStr() { |
| 41 | int randomDevice = ::open("/dev/urandom", O_RDONLY); |
| 42 | char randomData[32]; |
| 43 | size_t randomDataLen = 0; |
| 44 | |
| 45 | S3_CHECK_OR_DIE(randomDevice >= 0, S3RuntimeError, "failed to generate random number"); |
| 46 | |
| 47 | while (randomDataLen < sizeof(randomData)) { |
| 48 | ssize_t result = |
| 49 | ::read(randomDevice, randomData + randomDataLen, sizeof(randomData) - randomDataLen); |
| 50 | if (result < 0) { |
| 51 | break; |
| 52 | } |
| 53 | randomDataLen += result; |
| 54 | } |
| 55 | ::close(randomDevice); |
| 56 | |
| 57 | char out_hash_hex[SHA256_DIGEST_STRING_LENGTH]; |
| 58 | |
| 59 | sha256_hex(randomData, 32, out_hash_hex); |
| 60 | |
| 61 | return out_hash_hex + SHA256_DIGEST_STRING_LENGTH - 8 - 1; |
| 62 | } |
| 63 | |
| 64 | // invoked by s3_export(), need to be exception safe |
| 65 | GPWriter* writer_init(const char* url_with_options, const char* format) { |
no test coverage detected