Make X509Certificate.Export non-null-returning
authorJeremy Barton <jbarton@microsoft.com>
Fri, 21 Feb 2020 01:52:44 +0000 (17:52 -0800)
committerGitHub <noreply@github.com>
Fri, 21 Feb 2020 01:52:44 +0000 (17:52 -0800)
src/libraries/System.Security.Cryptography.X509Certificates/ref/System.Security.Cryptography.X509Certificates.cs
src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/ICertificatePalCore.cs
src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.OSX/AppleCertificatePal.Pkcs12.cs
src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.OSX/AppleCertificatePal.cs
src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Unix/OpenSslX509CertificateReader.cs
src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Windows/CertificatePal.cs
src/libraries/System.Security.Cryptography.X509Certificates/src/System/Security/Cryptography/X509Certificates/X509Certificate.cs

index 8cbe362..78fe34a 100644 (file)
@@ -158,10 +158,10 @@ namespace System.Security.Cryptography.X509Certificates
         protected virtual void Dispose(bool disposing) { }
         public override bool Equals(object? obj) { throw null; }
         public virtual bool Equals(System.Security.Cryptography.X509Certificates.X509Certificate? other) { throw null; }
-        public virtual byte[]? Export(System.Security.Cryptography.X509Certificates.X509ContentType contentType) { throw null; }
+        public virtual byte[] Export(System.Security.Cryptography.X509Certificates.X509ContentType contentType) { throw null; }
         [System.CLSCompliantAttribute(false)]
-        public virtual byte[]? Export(System.Security.Cryptography.X509Certificates.X509ContentType contentType, System.Security.SecureString? password) { throw null; }
-        public virtual byte[]? Export(System.Security.Cryptography.X509Certificates.X509ContentType contentType, string? password) { throw null; }
+        public virtual byte[] Export(System.Security.Cryptography.X509Certificates.X509ContentType contentType, System.Security.SecureString? password) { throw null; }
+        public virtual byte[] Export(System.Security.Cryptography.X509Certificates.X509ContentType contentType, string? password) { throw null; }
         protected static string FormatDate(System.DateTime date) { throw null; }
         public virtual byte[] GetCertHash() { throw null; }
         public virtual byte[] GetCertHash(System.Security.Cryptography.HashAlgorithmName hashAlgorithm) { throw null; }
index 1925598..e6f5381 100644 (file)
@@ -29,6 +29,6 @@ namespace Internal.Cryptography
         DateTime NotAfter { get; }
         DateTime NotBefore { get; }
         byte[] RawData { get; }
-        byte[]? Export(X509ContentType contentType, SafePasswordHandle password);
+        byte[] Export(X509ContentType contentType, SafePasswordHandle password);
     }
 }
index 03ae114..cce34ee 100644 (file)
@@ -141,7 +141,7 @@ namespace Internal.Cryptography.Pal
             public DateTime NotAfter => _realPal.NotAfter;
             public DateTime NotBefore => _realPal.NotBefore;
             public byte[] RawData => _realPal.RawData;
-            public byte[]? Export(X509ContentType contentType, SafePasswordHandle password) =>
+            public byte[] Export(X509ContentType contentType, SafePasswordHandle password) =>
                 _realPal.Export(contentType, password);
         }
     }
index 51f56c1..08faefd 100644 (file)
@@ -623,11 +623,13 @@ namespace Internal.Cryptography.Pal
             sb.AppendLine("[Private Key]");
         }
 
-        public byte[]? Export(X509ContentType contentType, SafePasswordHandle password)
+        public byte[] Export(X509ContentType contentType, SafePasswordHandle password)
         {
             using (IExportPal storePal = StorePal.FromCertificate(this))
             {
-                return storePal.Export(contentType, password);
+                byte[]? exported = storePal.Export(contentType, password);
+                Debug.Assert(exported != null);
+                return exported;
             }
         }
 
index 1c1e68c..a3e6479 100644 (file)
@@ -769,11 +769,13 @@ namespace Internal.Cryptography.Pal
             throw new CryptographicException();
         }
 
-        public byte[]? Export(X509ContentType contentType, SafePasswordHandle password)
+        public byte[] Export(X509ContentType contentType, SafePasswordHandle password)
         {
             using (IExportPal storePal = StorePal.FromCertificate(this))
             {
-                return storePal.Export (contentType, password);
+                byte[]? exported = storePal.Export(contentType, password);
+                Debug.Assert(exported != null);
+                return exported;
             }
         }
     }
index 598fd63..aec31f0 100644 (file)
@@ -537,11 +537,13 @@ namespace Internal.Cryptography.Pal
             _certContext = certContext;
         }
 
-        public byte[]? Export(X509ContentType contentType, SafePasswordHandle password)
+        public byte[] Export(X509ContentType contentType, SafePasswordHandle password)
         {
             using (IExportPal storePal = StorePal.FromCertificate(this))
             {
-                return storePal.Export(contentType, password);
+                byte[]? exported = storePal.Export(contentType, password);
+                Debug.Assert(exported != null);
+                return exported;
             }
         }
     }
index 47553cb..41c6e04 100644 (file)
@@ -271,12 +271,12 @@ namespace System.Security.Cryptography.X509Certificates
             return true;
         }
 
-        public virtual byte[]? Export(X509ContentType contentType)
+        public virtual byte[] Export(X509ContentType contentType)
         {
             return Export(contentType, (string?)null);
         }
 
-        public virtual byte[]? Export(X509ContentType contentType, string? password)
+        public virtual byte[] Export(X509ContentType contentType, string? password)
         {
             VerifyContentType(contentType);
 
@@ -290,7 +290,7 @@ namespace System.Security.Cryptography.X509Certificates
         }
 
         [System.CLSCompliantAttribute(false)]
-        public virtual byte[]? Export(X509ContentType contentType, SecureString? password)
+        public virtual byte[] Export(X509ContentType contentType, SecureString? password)
         {
             VerifyContentType(contentType);