From 30387eabd067f8eeb6eb41e5a50467cdffd220e6 Mon Sep 17 00:00:00 2001 From: Ravi Shekhar Jethani Date: Fri, 16 Aug 2024 15:53:07 +0200 Subject: [PATCH] code fix --- secret.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/secret.go b/secret.go index 749e308..9b7e774 100644 --- a/secret.go +++ b/secret.go @@ -79,7 +79,19 @@ func (tx *Text) UnmarshalText(b []byte) error { return nil } -// Equal returns true if both arguments have the same secret. The redact strings are not considered. +// Equal returns true if both arguments have the same secret regardless of the redact strings. func Equal(tx1, tx2 Text) bool { + // If both pointers are equal then it means either both are nil or point to same value. + if tx1.secret == tx2.secret { + return true + } + + // If we are here then it means the two pointers have different values hence return false + // if any one of them is nil. + if tx1.secret == nil || tx2.secret == nil { + return false + } + + // If we are here then it means both pointers are not nil hence compare the values pointed by them. return *tx1.secret == *tx2.secret }