예제 #1
0
        public void Load()
        {
            var path1 = Path.GetTempFileName();
            var path2 = Path.GetTempFileName();

            try
            {
                // Separate files with CRLF line endings.

                File.WriteAllText(path1, TestCertPart);
                File.WriteAllText(path2, TestKeyPart);

                var cert = TlsCertificate.Load(path1, path2);

                Assert.Equal(TlsCertificate.NormalizePem(TestCertPart), cert.CertPem);
                Assert.Equal(TlsCertificate.NormalizePem(TestKeyPart), cert.KeyPem);

                // Separate files with LF line endings.

                File.WriteAllText(path1, TlsCertificate.NormalizePem(TestCertPart));
                File.WriteAllText(path2, TlsCertificate.NormalizePem(TestKeyPart));

                cert = TlsCertificate.Load(path1, path2);

                Assert.Equal(TlsCertificate.NormalizePem(TestCertPart), cert.CertPem);
                Assert.Equal(TlsCertificate.NormalizePem(TestKeyPart), cert.KeyPem);

                // Combined file with CRLF line endings.

                File.WriteAllText(path1, TestCertPart + TestKeyPart);

                cert = TlsCertificate.Load(path1);

                File.WriteAllText(path1, TlsCertificate.NormalizePem(TestCertPart));
                File.WriteAllText(path2, TlsCertificate.NormalizePem(TestKeyPart));

                // Combined file with LF line endings.

                File.WriteAllText(path1, TlsCertificate.NormalizePem(TestCertPart) + TlsCertificate.NormalizePem(TestKeyPart));

                cert = TlsCertificate.Load(path1);

                File.WriteAllText(path1, TlsCertificate.NormalizePem(TestCertPart));
                File.WriteAllText(path2, TlsCertificate.NormalizePem(TestKeyPart));
            }
            finally
            {
                File.Delete(path1);
                File.Delete(path2);
            }
        }
예제 #2
0
        public void Constructor()
        {
            var cert = new TlsCertificate(TestCertPart + TestKeyPart);

            Assert.Equal(TlsCertificate.NormalizePem(TestCertPart), cert.CertPem);
            Assert.Equal(TlsCertificate.NormalizePem(TestKeyPart), cert.KeyPem);

            cert = new TlsCertificate(TestCertPart, TestKeyPart);

            Assert.Equal(TlsCertificate.NormalizePem(TestCertPart), cert.CertPem);
            Assert.Equal(TlsCertificate.NormalizePem(TestKeyPart), cert.KeyPem);

            Assert.Equal(TlsCertificate.NormalizePem(TestCertPart) + TlsCertificate.NormalizePem(TestKeyPart), cert.CombinedPem);
        }
예제 #3
0
        public void Load()
        {
            using (var tempFolder = new TempFolder())
            {
                var path1 = Path.Combine(tempFolder.Path, "test1");
                var path2 = Path.Combine(tempFolder.Path, "test2");

                // Separate files with CRLF line endings.

                File.WriteAllText(path1, TestCertPart);
                File.WriteAllText(path2, TestKeyPart);

                var cert = TlsCertificate.Load(path1, path2);

                Assert.Equal(TlsCertificate.NormalizePem(TestCertPart), cert.CertPem);
                Assert.Equal(TlsCertificate.NormalizePem(TestKeyPart), cert.KeyPem);

                // Separate files with LF line endings.

                File.WriteAllText(path1, TlsCertificate.NormalizePem(TestCertPart));
                File.WriteAllText(path2, TlsCertificate.NormalizePem(TestKeyPart));

                cert = TlsCertificate.Load(path1, path2);

                Assert.Equal(TlsCertificate.NormalizePem(TestCertPart), cert.CertPem);
                Assert.Equal(TlsCertificate.NormalizePem(TestKeyPart), cert.KeyPem);

                // Combined file with CRLF line endings.

                File.WriteAllText(path1, TestCertPart + TestKeyPart);

                cert = TlsCertificate.Load(path1);

                File.WriteAllText(path1, TlsCertificate.NormalizePem(TestCertPart));
                File.WriteAllText(path2, TlsCertificate.NormalizePem(TestKeyPart));

                // Combined file with LF line endings.

                File.WriteAllText(path1, TlsCertificate.NormalizePem(TestCertPart) + TlsCertificate.NormalizePem(TestKeyPart));

                cert = TlsCertificate.Load(path1);

                File.WriteAllText(path1, TlsCertificate.NormalizePem(TestCertPart));
                File.WriteAllText(path2, TlsCertificate.NormalizePem(TestKeyPart));
            }
        }
예제 #4
0
 public void NormalizePem()
 {
     Assert.Equal("abcde\n", TlsCertificate.NormalizePem("abcde"));
     Assert.Equal("abcde\n", TlsCertificate.NormalizePem("abcde\n"));
     Assert.Equal("abcde\n", TlsCertificate.NormalizePem("abcde\r\n"));
 }