From 69544553c36f0613f6283e0eeb3f9eb549825986 Mon Sep 17 00:00:00 2001
From: Jakub Jelen <jjelen@redhat.com>
Date: Mon, 7 Dec 2020 17:44:34 +0100
Subject: [PATCH] tcos: Reformat insert_pin() for readability

---
 src/libopensc/pkcs15-tcos.c | 35 ++++++++++++++++++++++-------------
 1 file changed, 22 insertions(+), 13 deletions(-)

diff --git a/src/libopensc/pkcs15-tcos.c b/src/libopensc/pkcs15-tcos.c
index 1134ac11ba..feeb7eb39d 100644
--- a/src/libopensc/pkcs15-tcos.c
+++ b/src/libopensc/pkcs15-tcos.c
@@ -225,12 +225,14 @@ static int insert_pin(
 	pin_obj.auth_id.len      = auth_id ? 0 : 1;
 	pin_obj.auth_id.value[0] = auth_id;
 
-	if(card->type==SC_CARD_TYPE_TCOS_V3){
+	if(card->type == SC_CARD_TYPE_TCOS_V3) {
 		unsigned char buf[256];
 		int i, rec_no=0;
-		if(pin_info.path.len>=2) pin_info.path.len-=2;
+		if (pin_info.path.len >= 2) {
+			pin_info.path.len -= 2;
+		}
 		sc_append_file_id(&pin_info.path, 0x5049);
-		if(sc_select_file(card, &pin_info.path, NULL)!=SC_SUCCESS){
+		if (sc_select_file(card, &pin_info.path, NULL) != SC_SUCCESS) {
 			sc_log(ctx, 
 				"Select(%s) failed\n",
 				sc_print_path(&pin_info.path));
@@ -238,17 +240,24 @@ static int insert_pin(
 		}
 		sc_log(ctx, 
 			"Searching for PIN-Ref %02X\n", pin_reference);
-		while((r=sc_read_record(card, ++rec_no, buf, sizeof(buf), SC_RECORD_BY_REC_NR))>0){
-			int found=0, fbz=-1;
-			if(buf[0]!=0xA0) continue;
-			for(i=2;i<buf[1]+2;i+=2+buf[i+1]){
-				if(buf[i]==0x83 && buf[i+1]==1 && buf[i+2]==pin_reference) ++found;
-				if(buf[i]==0x90) fbz=buf[i+1+buf[i+1]];
+		while ((r = sc_read_record(card, ++rec_no, buf, sizeof(buf), SC_RECORD_BY_REC_NR)) > 0) {
+			int found = 0, fbz = -1;
+			if (buf[0] != 0xA0)
+				continue;
+			for (i = 2; i < buf[1] + 2; i += 2 + buf[i + 1]) {
+				if (buf[i] == 0x83 && buf[i + 1] == 1 && buf[i + 2] == pin_reference) {
+					++found;
+				}
+				if (buf[i] == 0x90) {
+					fbz = buf[i + 1 + buf[i + 1]];
+				}
+			}
+			if (found) {
+				pin_info.tries_left = fbz;
+				break;
 			}
-			if(found) pin_info.tries_left=fbz;
-			if(found) break;
 		}
-		if(r<=0){
+		if (r <= 0) {
 			sc_log(ctx, "No EF_PWDD-Record found\n");
 			return 1;
 		}
@@ -259,6 +268,6 @@ static int insert_pin(
 			return 1;
 		}
-		pin_info.tries_left=f->prop_attr[3];
+		pin_info.tries_left = f->prop_attr[3];
 		sc_file_free(f);
 	}
 
