summary refs log tree commit diff
path: root/crypto/src/tls
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2022-07-01 16:04:26 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2022-07-01 16:04:26 +0700
commit7667960b24e63b23518408337c69d5f36c5dfd94 (patch)
tree5a4d0d42d37cd2413b3ec7b68eccfb16f3d4a858 /crypto/src/tls
parentRework EdDSA precomputations (diff)
downloadBouncyCastle.NET-ed25519-7667960b24e63b23518408337c69d5f36c5dfd94.tar.xz
Custom serialization
Diffstat (limited to 'crypto/src/tls')
-rw-r--r--crypto/src/tls/TlsFatalAlert.cs16
-rw-r--r--crypto/src/tls/TlsFatalAlertReceived.cs14
2 files changed, 25 insertions, 5 deletions
diff --git a/crypto/src/tls/TlsFatalAlert.cs b/crypto/src/tls/TlsFatalAlert.cs
index 511fa9fb1..feca84820 100644
--- a/crypto/src/tls/TlsFatalAlert.cs
+++ b/crypto/src/tls/TlsFatalAlert.cs
@@ -17,10 +17,10 @@ namespace Org.BouncyCastle.Tls
             return msg;
         }
 
-        protected readonly short m_alertDescription;
+        protected readonly byte m_alertDescription;
 
         public TlsFatalAlert(short alertDescription)
-            : this(alertDescription, (string)null)
+            : this(alertDescription, null, null)
         {
         }
 
@@ -37,12 +37,22 @@ namespace Org.BouncyCastle.Tls
         public TlsFatalAlert(short alertDescription, string detailMessage, Exception alertCause)
             : base(GetMessage(alertDescription, detailMessage), alertCause)
         {
-            this.m_alertDescription = alertDescription;
+            if (!TlsUtilities.IsValidUint8(alertDescription))
+                throw new ArgumentOutOfRangeException(nameof(alertDescription));
+
+            m_alertDescription = (byte)alertDescription;
         }
 
         protected TlsFatalAlert(SerializationInfo info, StreamingContext context)
             : base(info, context)
         {
+            m_alertDescription = info.GetByte("alertDescription");
+        }
+
+        public override void GetObjectData(SerializationInfo info, StreamingContext context)
+        {
+            base.GetObjectData(info, context);
+            info.AddValue("alertDescription", m_alertDescription);
         }
 
         public virtual short AlertDescription
diff --git a/crypto/src/tls/TlsFatalAlertReceived.cs b/crypto/src/tls/TlsFatalAlertReceived.cs
index adf71d5b9..4e1a62481 100644
--- a/crypto/src/tls/TlsFatalAlertReceived.cs
+++ b/crypto/src/tls/TlsFatalAlertReceived.cs
@@ -7,17 +7,27 @@ namespace Org.BouncyCastle.Tls
     public class TlsFatalAlertReceived
         : TlsException
     {
-        protected readonly short m_alertDescription;
+        protected readonly byte m_alertDescription;
 
         public TlsFatalAlertReceived(short alertDescription)
             : base(Tls.AlertDescription.GetText(alertDescription))
         {
-            this.m_alertDescription = alertDescription;
+            if (!TlsUtilities.IsValidUint8(alertDescription))
+                throw new ArgumentOutOfRangeException(nameof(alertDescription));
+
+            m_alertDescription = (byte)alertDescription;
         }
 
         protected TlsFatalAlertReceived(SerializationInfo info, StreamingContext context)
             : base(info, context)
         {
+            m_alertDescription = info.GetByte("alertDescription");
+        }
+
+        public override void GetObjectData(SerializationInfo info, StreamingContext context)
+        {
+            base.GetObjectData(info, context);
+            info.AddValue("alertDescription", m_alertDescription);
         }
 
         public virtual short AlertDescription