summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2024-01-28 14:20:31 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2024-01-28 14:20:31 +0700
commita8743aa5c7d0b5f3a3efd0670be7e89da96de6f8 (patch)
tree60dc7b59cb4ee4621c23500b8110f0df6755ed25
parentUpdate rosstandart OIDs (diff)
downloadBouncyCastle.NET-ed25519-a8743aa5c7d0b5f3a3efd0670be7e89da96de6f8.tar.xz
Tolerate missing assembly attributes
- mainly for third party builds that neglect to add the attributes
- see https://github.com/bcgit/bc-csharp/issues/495
-rw-r--r--crypto/src/bcpg/ArmoredOutputStream.cs11
1 files changed, 8 insertions, 3 deletions
diff --git a/crypto/src/bcpg/ArmoredOutputStream.cs b/crypto/src/bcpg/ArmoredOutputStream.cs
index 37dcf2340..03d4a1a91 100644
--- a/crypto/src/bcpg/ArmoredOutputStream.cs
+++ b/crypto/src/bcpg/ArmoredOutputStream.cs
@@ -133,9 +133,14 @@ namespace Org.BouncyCastle.Bcpg
         private static string CreateVersion()
         {
             var assembly = Assembly.GetExecutingAssembly();
-            var title = assembly.GetCustomAttribute<AssemblyTitleAttribute>().Title;
-            var version = assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion;
-            return title + " v" + version;
+
+            var titleAttr = assembly.GetCustomAttribute<AssemblyTitleAttribute>();
+            var versionAttr = assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>();
+
+            if (titleAttr == null || versionAttr == null)
+                return "BouncyCastle (unknown version)";
+
+            return titleAttr.Title + " v" + versionAttr.InformationalVersion;
         }
 
         private static readonly string Version = CreateVersion();