Пример #1
0
        private void TestCloseWithClosedSecretShouldNoop()
        {
            Debug.WriteLine("TestCloseWithClosedSecretShouldNoop");
            byte[] secretBytes = { 0, 1 };

            // TODO : Need to determine if we can stub out the protectedMemoryAllocatorMock.
            if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
            {
                Mock <MacOSProtectedMemoryAllocatorLP64> protectedMemoryAllocatorMacOSMock =
                    new Mock <MacOSProtectedMemoryAllocatorLP64> {
                    CallBase = true
                };

                SecureMemorySecret secret =
                    new SecureMemorySecret(secretBytes, protectedMemoryAllocatorMacOSMock.Object, configuration);
                secret.Close();
                secret.Close();
                protectedMemoryAllocatorMacOSMock.Verify(
                    x => x.Free(It.IsAny <IntPtr>(), It.IsAny <ulong>()), Times.Exactly(1));
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                Mock <LinuxProtectedMemoryAllocatorLP64> protectedMemoryAllocatorLinuxMock =
                    new Mock <LinuxProtectedMemoryAllocatorLP64> {
                    CallBase = true
                };

                SecureMemorySecret secret =
                    new SecureMemorySecret(secretBytes, protectedMemoryAllocatorLinuxMock.Object, configuration);
                secret.Close();
                secret.Close();
                protectedMemoryAllocatorLinuxMock.Verify(
                    x => x.Free(It.IsAny <IntPtr>(), It.IsAny <ulong>()), Times.Exactly(1));
            }
        }
Пример #2
0
        private void TestWithSecretUtf8CharsWithClosedSecretShouldFail(ISecureMemoryAllocator protectedMemoryAllocator)
        {
            Debug.WriteLine("TestWithSecretUtf8CharsWithClosedSecretShouldFail");
            char[]             secretChars = { 'a', 'b' };
            SecureMemorySecret secret      =
                SecureMemorySecret.FromCharArray(secretChars, protectedMemoryAllocator, configuration);

            secret.Close();
            Assert.Throws <InvalidOperationException>(() => { secret.WithSecretUtf8Chars(decryptedChars => true); });
        }
Пример #3
0
        private void TestWithSecretBytesWithClosedSecretShouldFail(ISecureMemoryAllocator protectedMemoryAllocator)
        {
            Debug.WriteLine("TestWithSecretBytesWithClosedSecretShouldFail");
            byte[]             secretBytes = { 0, 1 };
            SecureMemorySecret secret      =
                new SecureMemorySecret((byte[])secretBytes.Clone(), protectedMemoryAllocator, configuration);

            secret.Close();
            Assert.Throws <InvalidOperationException>(() => { secret.WithSecretBytes(decryptedBytes => true); });
        }