コード例 #1
0
ファイル: Sodium.cs プロジェクト: ikvm/ravendb
        static Sodium()
        {
            try
            {
                DynamicNativeLibraryResolver.Register(typeof(Sodium).Assembly, LIBSODIUM);

                var rc = sodium_init();
                if (rc != 0)
                {
                    throw new InvalidOperationException("Unable to initialize sodium, error code: " + rc);
                }
                crypto_sign_publickeybytes(); // test libsodium functionality
            }
            catch (Exception ex)
            {
                var errString = $"{LIBSODIUM} version might be invalid, missing or not usable on current platform.";

                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    errString += " Initialization error could also be caused by missing 'Microsoft Visual C++ 2015 Redistributable Package' (or newer). It can be downloaded from https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads.";
                }

                errString += $" Arch: {RuntimeInformation.OSArchitecture}, OSDesc: {RuntimeInformation.OSDescription}";

                throw new IncorrectDllException(errString, ex);
            }
        }
コード例 #2
0
        public const int PAL_VER = 42013; // Should match auto generated rc from rvn_get_pal_ver() @ src/rvngetpalver.c

        static Pal()
        {
            PalFlags.FailCodes rc;
            int errorCode;

            try
            {
                var mutator = PlatformDetails.IsWindows8OrNewer == false ? (Func <string, string>)ToWin7DllName : default;
                DynamicNativeLibraryResolver.Register(typeof(Pal).Assembly, LIBRVNPAL, mutator);

                var palVer = rvn_get_pal_ver();
                if (palVer != 0 && palVer != PAL_VER)
                {
                    throw new IncorrectDllException(
                              $"{LIBRVNPAL} version '{palVer}' mismatches this RavenDB instance version (set to '{PAL_VER}'). Did you forget to set new value in 'rvn_get_pal_ver()'");
                }

                rc = rvn_get_system_information(out SysInfo, out errorCode);
            }
            catch (Exception ex)
            {
                var errString = $"{LIBRVNPAL} version might be invalid, missing or not usable on current platform.";

                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    errString +=
                        " Initialization error could also be caused by missing 'Microsoft Visual C++ 2015 Redistributable Package' (or newer). It can be downloaded from https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads.";
                }

                errString += $" Arch: {RuntimeInformation.OSArchitecture}, OSDesc: {RuntimeInformation.OSDescription}";

                throw new IncorrectDllException(errString, ex);
            }

            if (rc != PalFlags.FailCodes.Success)
            {
                PalHelper.ThrowLastError(rc, errorCode, "Cannot get system information");
            }

            string ToWin7DllName(string name)
            {
                return(name.Replace("win", "win7"));
            }
        }
コード例 #3
0
 static ZstdLib()
 {
     DynamicNativeLibraryResolver.Register(typeof(ZstdLib).Assembly, LIBZSTD);
 }