From 01391f7a76904b1ed0853d3fc30c49001030ac0a Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Thu, 17 Mar 2022 00:46:25 +0000 Subject: [PATCH] Add null reference checks. --- MD5Context.cs | 3 +++ SHA1Context.cs | 3 +++ SHA256Context.cs | 3 +++ SHA384Context.cs | 3 +++ SHA512Context.cs | 3 +++ 5 files changed, 15 insertions(+) diff --git a/MD5Context.cs b/MD5Context.cs index 5862bfd87..985a5a0d3 100644 --- a/MD5Context.cs +++ b/MD5Context.cs @@ -74,6 +74,9 @@ public sealed class Md5Context : IChecksum _provider.TransformFinalBlock(Array.Empty(), 0, 0); var md5Output = new StringBuilder(); + if(_provider.Hash is null) + return null; + foreach(byte h in _provider.Hash) md5Output.Append(h.ToString("x2")); diff --git a/SHA1Context.cs b/SHA1Context.cs index f332b9b7e..ccb360a5e 100644 --- a/SHA1Context.cs +++ b/SHA1Context.cs @@ -74,6 +74,9 @@ public sealed class Sha1Context : IChecksum _provider.TransformFinalBlock(Array.Empty(), 0, 0); var sha1Output = new StringBuilder(); + if(_provider.Hash is null) + return null; + foreach(byte h in _provider.Hash) sha1Output.Append(h.ToString("x2")); diff --git a/SHA256Context.cs b/SHA256Context.cs index 1e7e49d90..be65193e3 100644 --- a/SHA256Context.cs +++ b/SHA256Context.cs @@ -74,6 +74,9 @@ public sealed class Sha256Context : IChecksum _provider.TransformFinalBlock(Array.Empty(), 0, 0); var sha256Output = new StringBuilder(); + if(_provider.Hash is null) + return null; + foreach(byte h in _provider.Hash) sha256Output.Append(h.ToString("x2")); diff --git a/SHA384Context.cs b/SHA384Context.cs index 12e397f77..26601c78b 100644 --- a/SHA384Context.cs +++ b/SHA384Context.cs @@ -74,6 +74,9 @@ public sealed class Sha384Context : IChecksum _provider.TransformFinalBlock(Array.Empty(), 0, 0); var sha384Output = new StringBuilder(); + if(_provider.Hash is null) + return null; + foreach(byte h in _provider.Hash) sha384Output.Append(h.ToString("x2")); diff --git a/SHA512Context.cs b/SHA512Context.cs index 44098225d..8dbe6fa22 100644 --- a/SHA512Context.cs +++ b/SHA512Context.cs @@ -74,6 +74,9 @@ public sealed class Sha512Context : IChecksum _provider.TransformFinalBlock(Array.Empty(), 0, 0); var sha512Output = new StringBuilder(); + if(_provider.Hash is null) + return null; + foreach(byte h in _provider.Hash) sha512Output.Append(h.ToString("x2"));