@@ -727,9 +727,9 @@ func (t *MIFARETag) clearRemainingBlocks(startBlock uint8) error {
727727func (t * MIFARETag ) ResetAuthState () error {
728728 // SECURITY: Thread-safe state clearing
729729 t .authMutex .Lock ()
730- defer t .authMutex .Unlock ()
731730 t .lastAuthSector = - 1
732731 t .lastAuthKeyType = 0
732+ t .authMutex .Unlock ()
733733
734734 // Force PN532 to reset by attempting to re-detect the tag
735735 // This clears any internal authentication state in the PN532 chip
@@ -769,20 +769,18 @@ func (t *MIFARETag) Authenticate(sector uint8, keyType byte, key []byte) error {
769769 _ , err := t .device .SendDataExchange (cmd )
770770 if err != nil {
771771 // SECURITY: Thread-safe state clearing on failure
772- func () {
773- t .authMutex .Lock ()
774- defer t .authMutex .Unlock ()
775- t .lastAuthSector = - 1
776- t .lastAuthKeyType = 0
777- }()
772+ t .authMutex .Lock ()
773+ t .lastAuthSector = - 1
774+ t .lastAuthKeyType = 0
775+ t .authMutex .Unlock ()
778776 return fmt .Errorf ("authentication failed: %w" , err )
779777 }
780778
781779 // SECURITY: Thread-safe state update on success
782780 t .authMutex .Lock ()
783- defer t .authMutex .Unlock ()
784781 t .lastAuthSector = int (sector )
785782 t .lastAuthKeyType = keyType
783+ t .authMutex .Unlock ()
786784
787785 return nil
788786}
@@ -804,12 +802,10 @@ func (t *MIFARETag) AuthenticateRobust(sector uint8, keyType byte, key []byte) e
804802 // If standard auth failed, try Chinese clone unlock sequences
805803 if t .tryChineseCloneUnlock (sector ) {
806804 // Clone unlock successful, tag is accessible without auth
807- func () {
808- t .authMutex .Lock ()
809- defer t .authMutex .Unlock ()
810- t .lastAuthSector = int (sector )
811- t .lastAuthKeyType = keyType
812- }()
805+ t .authMutex .Lock ()
806+ t .lastAuthSector = int (sector )
807+ t .lastAuthKeyType = keyType
808+ t .authMutex .Unlock ()
813809 return nil
814810 }
815811
@@ -878,12 +874,10 @@ func (t *MIFARETag) applyRetryStrategy(level retryLevel, _ error) error {
878874 }
879875
880876 // Clear authentication state
881- func () {
882- t .authMutex .Lock ()
883- defer t .authMutex .Unlock ()
884- t .lastAuthSector = - 1
885- t .lastAuthKeyType = 0
886- }()
877+ t .authMutex .Lock ()
878+ t .lastAuthSector = - 1
879+ t .lastAuthKeyType = 0
880+ t .authMutex .Unlock ()
887881
888882 return nil
889883
@@ -899,12 +893,10 @@ func (t *MIFARETag) applyRetryStrategy(level retryLevel, _ error) error {
899893 time .Sleep (50 * time .Millisecond )
900894 }
901895
902- func () {
903- t .authMutex .Lock ()
904- defer t .authMutex .Unlock ()
905- t .lastAuthSector = - 1
906- t .lastAuthKeyType = 0
907- }()
896+ t .authMutex .Lock ()
897+ t .lastAuthSector = - 1
898+ t .lastAuthKeyType = 0
899+ t .authMutex .Unlock ()
908900
909901 return nil
910902
0 commit comments