Ticket #8432: boost_1_53_0_random_device_win32_error_continue.diff

File boost_1_53_0_random_device_win32_error_continue.diff, 996 bytes (added by frank.richter@…, 10 years ago)

random_device: On Win32, be more lenient wrt CSP enumeration errors

  • libs/random/src/random_device.cpp

    diff -rub boost_1_53_0.org/libs/random/src/random_device.cpp boost_1_53_0/libs/random/src/random_device.cpp
    old new  
    6868    char buffer[80];
    6969    DWORD type;
    7070    DWORD len;
     71    bool found (false);
    7172
    72     // Find the type of the provider
     73    // Find the type of a specific provider
    7374    for(DWORD i = 0; ; ++i) {
    7475      len = sizeof(buffer);
    7576      if(!CryptEnumProvidersA(i, NULL, 0, &type, buffer, &len)) {
    76         error("Could not find provider name");
     77        if (GetLastError() == ERROR_NO_MORE_ITEMS) break;
     78        continue;
    7779      }
    7880      if(buffer == provider) {
     81        found = true;
    7982        break;
    8083      }
    8184    }
     85    if (!found) {
     86      error("Could not find provider name");
     87    }
    8288
    8389    if(!CryptAcquireContextA(&hProv, NULL, provider.c_str(), type,
    8490        CRYPT_VERIFYCONTEXT | CRYPT_SILENT)) {