From 864395b6468d62f17d2e8f0e593408849564edc1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C3=81lvaro=20Herrera?= <alvherre@alvh.no-ip.org>
Date: Wed, 2 Apr 2025 17:25:20 +0200
Subject: [PATCH 1/2] pgindent

---
 contrib/pgcrypto/crypt-gensalt.c | 14 +++++------
 contrib/pgcrypto/crypt-sha.c     | 42 +++++++++++++++++---------------
 contrib/pgcrypto/px-crypt.c      |  6 ++---
 contrib/pgcrypto/px-crypt.h      |  2 +-
 4 files changed, 33 insertions(+), 31 deletions(-)

diff --git a/contrib/pgcrypto/crypt-gensalt.c b/contrib/pgcrypto/crypt-gensalt.c
index b9aded897d1..922f9eea6fa 100644
--- a/contrib/pgcrypto/crypt-gensalt.c
+++ b/contrib/pgcrypto/crypt-gensalt.c
@@ -190,9 +190,9 @@ static char *
 _crypt_gensalt_sha(unsigned long count,
 				   const char *input, int size, char *output, int output_size)
 {
-	char * s_ptr = output;
+	char	   *s_ptr = output;
 	unsigned int result_bufsize = PX_SHACRYPT_SALT_BUF_LEN;
-	int rc;
+	int			rc;
 
 	/* output buffer must be allocated with PX_MAX_SALT_LEN bytes */
 	if (PX_MAX_SALT_LEN < result_bufsize)
@@ -203,8 +203,8 @@ _crypt_gensalt_sha(unsigned long count,
 	}
 
 	/*
-	 * Care must be taken to not exceed the buffer size allocated for
-	 * the input character buffer.
+	 * Care must be taken to not exceed the buffer size allocated for the
+	 * input character buffer.
 	 */
 	if ((PX_SHACRYPT_SALT_MAX_LEN != size)
 		|| (output_size < size))
@@ -229,8 +229,8 @@ _crypt_gensalt_sha(unsigned long count,
 	/*
 	 * Normalize salt string
 	 *
-	 * size of input buffer was checked above to
-	 * not exceed PX_SHACRYPT_SALT_LEN_MAX.
+	 * size of input buffer was checked above to not exceed
+	 * PX_SHACRYPT_SALT_LEN_MAX.
 	 */
 	for (int i = 0; i < size; i++)
 	{
@@ -268,4 +268,4 @@ _crypt_gensalt_sha256_rn(unsigned long count,
 	output[2] = '$';
 
 	return _crypt_gensalt_sha(count, input, size, output, output_size);
-}
\ No newline at end of file
+}
diff --git a/contrib/pgcrypto/crypt-sha.c b/contrib/pgcrypto/crypt-sha.c
index ec51e865a5e..13ee8913052 100644
--- a/contrib/pgcrypto/crypt-sha.c
+++ b/contrib/pgcrypto/crypt-sha.c
@@ -77,24 +77,25 @@ px_crypt_shacrypt(const char *pw, const char *salt, char *passwd, unsigned dstle
 	int			err;
 
 	const char *dec_salt_binary;	/* pointer into the real salt string */
-	StringInfo decoded_salt = NULL; /* decoded salt string */
+	StringInfo	decoded_salt = NULL;	/* decoded salt string */
 
 	unsigned char sha_buf[PX_SHACRYPT_DIGEST_MAX_LEN];
 	unsigned char sha_buf_tmp[PX_SHACRYPT_DIGEST_MAX_LEN];	/* temporary buffer for
-																 * digests */
+															 * digests */
 
 	char		rounds_custom = 0;
 	char	   *p_bytes = NULL;
 	char	   *s_bytes = NULL;
 	char	   *cp = NULL;
-	const char *fp = NULL;				/* intermediate pointer within salt string */
-	const char *ep = NULL;				/* holds pointer to the end of the salt string */
+	const char *fp = NULL;		/* intermediate pointer within salt string */
+	const char *ep = NULL;		/* holds pointer to the end of the salt string */
 
 	size_t		buf_size = 0;	/* buffer size for sha256crypt/sha512crypt */
 	unsigned int block;			/* number of bytes processed */
 	unsigned long rounds = PX_SHACRYPT_ROUNDS_DEFAULT;
 
-	unsigned	len, salt_len = 0;
+	unsigned	len,
+				salt_len = 0;
 
 	/* Init result buffer */
 	out_buf = makeStringInfoExt(PX_SHACRYPT_BUF_LEN);
@@ -299,16 +300,16 @@ px_crypt_shacrypt(const char *pw, const char *salt, char *passwd, unsigned dstle
 
 	/*
 	 * We need the real decoded salt string from salt input, this is every
-	 * character before the last '$' in the preamble. Append every
-	 * compatible character up to PX_SHACRYPT_SALT_MAX_LEN to the result buffer.
-	 * Note that depending on the input, there might be no '$' marker after
-	 * the salt, when there is no password hash attached at the end.
+	 * character before the last '$' in the preamble. Append every compatible
+	 * character up to PX_SHACRYPT_SALT_MAX_LEN to the result buffer. Note
+	 * that depending on the input, there might be no '$' marker after the
+	 * salt, when there is no password hash attached at the end.
 	 *
 	 * We try hard to recognize mistakes, but since we might get an input
 	 * string which might also have the password hash after the salt string
 	 * section we give up as soon we reach the end of the input or if there
-	 * are any bytes consumed for the salt string until we reach the
-	 * first '$' marker thereafter.
+	 * are any bytes consumed for the salt string until we reach the first '$'
+	 * marker thereafter.
 	 */
 	for (ep = dec_salt_binary;
 		 *ep && ep < (dec_salt_binary + PX_SHACRYPT_SALT_MAX_LEN);
@@ -320,9 +321,9 @@ px_crypt_shacrypt(const char *pw, const char *salt, char *passwd, unsigned dstle
 		 * First check for accidentally embedded magic strings here. We don't
 		 * support '$' in salt strings anyways and seeing a magic byte trying
 		 * to identify shacrypt hashes might indicate that something went
-		 * wrong when generating this salt string. Note that we later check for
-		 * non-supported literals anyways, but any '$' here confuses us
-		 * at this point.
+		 * wrong when generating this salt string. Note that we later check
+		 * for non-supported literals anyways, but any '$' here confuses us at
+		 * this point.
 		 */
 		fp = strstr(dec_salt_binary, magic_bytes[0]);
 
@@ -362,13 +363,14 @@ px_crypt_shacrypt(const char *pw, const char *salt, char *passwd, unsigned dstle
 		}
 		else
 		{
-			/* We encountered a '$' marker. Check if we already absorbed
-			 * some bytes from input. If true, we are optimistic and
-			 * terminate at this stage. Of not, we try further.
+			/*
+			 * We encountered a '$' marker. Check if we already absorbed some
+			 * bytes from input. If true, we are optimistic and terminate at
+			 * this stage. Of not, we try further.
 			 *
-			 * If we already consumed enough bytes for the salt string, everything
-			 * that is after this marker is considered to be part of an
-			 * optionally specified password hash and ignored.
+			 * If we already consumed enough bytes for the salt string,
+			 * everything that is after this marker is considered to be part
+			 * of an optionally specified password hash and ignored.
 			 */
 			if (decoded_salt->len > 0)
 				break;
diff --git a/contrib/pgcrypto/px-crypt.c b/contrib/pgcrypto/px-crypt.c
index df9875b9433..a786277aeac 100644
--- a/contrib/pgcrypto/px-crypt.c
+++ b/contrib/pgcrypto/px-crypt.c
@@ -71,7 +71,7 @@ static char *
 run_crypt_sha(const char *psw, const char *salt,
 			  char *buf, unsigned len)
 {
-	char *res;
+	char	   *res;
 
 	res = px_crypt_shacrypt(psw, salt, buf, len);
 	return res;
@@ -140,9 +140,9 @@ static struct generator gen_list[] = {
 	{"xdes", _crypt_gensalt_extended_rn, 3, PX_XDES_ROUNDS, 1, 0xFFFFFF},
 	{"bf", _crypt_gensalt_blowfish_rn, 16, PX_BF_ROUNDS, 4, 31},
 	{"sha256crypt", _crypt_gensalt_sha256_rn, PX_SHACRYPT_SALT_MAX_LEN,
-	 PX_SHACRYPT_ROUNDS_DEFAULT, PX_SHACRYPT_ROUNDS_MIN, PX_SHACRYPT_ROUNDS_MAX},
+	PX_SHACRYPT_ROUNDS_DEFAULT, PX_SHACRYPT_ROUNDS_MIN, PX_SHACRYPT_ROUNDS_MAX},
 	{"sha512crypt", _crypt_gensalt_sha512_rn, PX_SHACRYPT_SALT_MAX_LEN,
-	 PX_SHACRYPT_ROUNDS_DEFAULT, PX_SHACRYPT_ROUNDS_MIN, PX_SHACRYPT_ROUNDS_MAX},
+	PX_SHACRYPT_ROUNDS_DEFAULT, PX_SHACRYPT_ROUNDS_MIN, PX_SHACRYPT_ROUNDS_MAX},
 	{NULL, NULL, 0, 0, 0, 0}
 };
 
diff --git a/contrib/pgcrypto/px-crypt.h b/contrib/pgcrypto/px-crypt.h
index 9287c33efe1..3829ec6c347 100644
--- a/contrib/pgcrypto/px-crypt.h
+++ b/contrib/pgcrypto/px-crypt.h
@@ -108,6 +108,6 @@ char	   *px_crypt_md5(const char *pw, const char *salt,
 						 char *passwd, unsigned dstlen);
 
 /* crypt-sha.c */
-char       *px_crypt_shacrypt(const char *pw, const char *salt, char *passwd, unsigned dstlen);
+char	   *px_crypt_shacrypt(const char *pw, const char *salt, char *passwd, unsigned dstlen);
 
 #endif							/* _PX_CRYPT_H */
-- 
2.39.5

