public AllocatorGenerator() { var configuration = new ConfigurationBuilder().AddInMemoryCollection(new Dictionary <string, string>() { { "heapSize", "32000" }, { "minimumAllocationSize", "128" }, }).Build(); allocators = new List <object[]>(); if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { allocators.Add(new object[] { new MacOSProtectedMemoryAllocatorLP64() }); } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { if (LinuxOpenSSL11ProtectedMemoryAllocatorLP64.IsAvailable()) { allocators.Add(new object[] { new LinuxOpenSSL11ProtectedMemoryAllocatorLP64(configuration) }); } allocators.Add(new object[] { new LinuxProtectedMemoryAllocatorLP64() }); } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { allocators.Add(new object[] { new WindowsProtectedMemoryAllocatorVirtualAlloc(configuration) }); } }
private static IProtectedMemoryAllocator ConfigureForLinux64(IConfiguration configuration) { if (configuration != null) { var secureHeapEngine = configuration["secureHeapEngine"]; if (!string.IsNullOrWhiteSpace(secureHeapEngine)) { if (string.Compare(secureHeapEngine, "openssl11", StringComparison.InvariantCultureIgnoreCase) == 0) { if (LinuxOpenSSL11ProtectedMemoryAllocatorLP64.IsAvailable()) { return(new LinuxOpenSSL11ProtectedMemoryAllocatorLP64(configuration)); } throw new PlatformNotSupportedException( "OpenSSL 1.1 selected for secureHeapEngine but library not found"); } if (string.Compare(secureHeapEngine, "mmap", StringComparison.InvariantCultureIgnoreCase) == 0) { return(new LinuxProtectedMemoryAllocatorLP64()); } throw new PlatformNotSupportedException("Unknown secureHeapEngine: " + secureHeapEngine); } } return(new LinuxProtectedMemoryAllocatorLP64()); }
public OpenSSLCryptProtectMemoryTests() { var configuration = new ConfigurationBuilder().AddInMemoryCollection(new Dictionary <string, string>() { { "heapSize", "32000" }, { "minimumAllocationSize", "128" }, }).Build(); if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { Debug.WriteLine("\nLinuxOpenSSL11ProtectedMemoryAllocatorTest ctor"); linuxOpenSSL11ProtectedMemoryAllocatorLP64 = new LinuxOpenSSL11ProtectedMemoryAllocatorLP64(configuration); } }
private void TestFreeAfterDispose() { Skip.IfNot(RuntimeInformation.IsOSPlatform(OSPlatform.Linux)); Debug.WriteLine("\nLinuxOpenSSL11ProtectedMemoryAllocatorTest ctor"); linuxOpenSSL11ProtectedMemoryAllocatorLP64 = new LinuxOpenSSL11ProtectedMemoryAllocatorLP64(configuration); linuxOpenSSL11ProtectedMemoryAllocatorLP64.Dispose(); var exception = Assert.Throws <Exception>(() => { linuxOpenSSL11ProtectedMemoryAllocatorLP64.Free(new IntPtr(-1), 0); }); Assert.Equal("Called Free on disposed LinuxOpenSSL11ProtectedMemoryAllocatorLP64", exception.Message); }
public LinuxOpenSSL11ProtectedMemoryAllocatorTest() { Trace.Listeners.Clear(); var consoleListener = new ConsoleTraceListener(); Trace.Listeners.Add(consoleListener); configuration = new ConfigurationBuilder().AddInMemoryCollection(new Dictionary <string, string>() { { "heapSize", "32000" }, { "minimumAllocationSize", "128" }, }).Build(); if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { Debug.WriteLine("\nLinuxOpenSSL11ProtectedMemoryAllocatorTest ctor"); linuxOpenSSL11ProtectedMemoryAllocatorLP64 = new LinuxOpenSSL11ProtectedMemoryAllocatorLP64(configuration); } }