@@ -341,8 +341,8 @@ String createAssertion(JsonFactory jsonFactory, long currentTime) throws IOExcep
341341 try {
342342 assertion = signUsingEsSha256 (privateKey , jsonFactory , header , payload );
343343 } catch (GeneralSecurityException e ) {
344- throw new IOException (
345- "Error signing service account access token request with private key." , e );
344+ throw new GoogleAuthException (
345+ false , 0 , "Error signing service account access token request with private key." , e );
346346 }
347347
348348 return assertion ;
@@ -689,7 +689,7 @@ static String signUsingEsSha256(
689689 JsonFactory jsonFactory ,
690690 JsonWebSignature .Header header ,
691691 JsonWebToken .Payload payload )
692- throws GeneralSecurityException , IOException {
692+ throws GeneralSecurityException , GoogleAuthException {
693693
694694 // 1. Construct the JWS Signing Input: Base64URL(UTF8(Header)) + '.' + Base64URL(UTF8(Payload))
695695 String content =
@@ -725,10 +725,11 @@ static String signUsingEsSha256(
725725 * @throws IOException If the DER format is invalid.
726726 */
727727 @ VisibleForTesting
728- static byte [] transcodeDerToConcat (byte [] derSignature , int outputLength ) throws IOException {
728+ static byte [] transcodeDerToConcat (byte [] derSignature , int outputLength )
729+ throws GoogleAuthException {
729730 // Validate basic ASN.1 DER structure (0x30 = SEQUENCE)
730731 if (derSignature .length < 8 || derSignature [0 ] != 0x30 ) {
731- throw new IOException ( "Invalid DER signature format." );
732+ throw new GoogleAuthException ( false , 0 , "Invalid DER signature format." , null );
732733 }
733734
734735 int offset = 2 ;
@@ -740,12 +741,12 @@ static byte[] transcodeDerToConcat(byte[] derSignature, int outputLength) throws
740741 }
741742
742743 if (derSignature .length - offset != seqLength ) {
743- throw new IOException ( "Invalid DER signature length." );
744+ throw new GoogleAuthException ( false , 0 , "Invalid DER signature length." , null );
744745 }
745746
746747 // Parse Integer R (0x02 = INTEGER)
747748 if (derSignature [offset ++] != 0x02 ) {
748- throw new IOException ( "Expected INTEGER for R." );
749+ throw new GoogleAuthException ( false , 0 , "Expected INTEGER for R." , null );
749750 }
750751 int rLength = derSignature [offset ++];
751752 // Skip leading zero byte if it exists (DER integers are signed; zero is added to stay positive)
@@ -759,7 +760,7 @@ static byte[] transcodeDerToConcat(byte[] derSignature, int outputLength) throws
759760
760761 // Parse Integer S
761762 if (derSignature [offset ++] != 0x02 ) {
762- throw new IOException ( "Expected INTEGER for S." );
763+ throw new GoogleAuthException ( false , 0 , "Expected INTEGER for S." , null );
763764 }
764765 int sLength = derSignature [offset ++];
765766 if (derSignature [offset ] == 0x00 && sLength > 1 && (derSignature [offset + 1 ] & 0x80 ) != 0 ) {
@@ -772,10 +773,13 @@ static byte[] transcodeDerToConcat(byte[] derSignature, int outputLength) throws
772773 // Concatenate r and s into fixed-length segments (32 bytes each for ES256)
773774 int keySizeBytes = outputLength / 2 ;
774775 if (r .length > keySizeBytes || s .length > keySizeBytes ) {
775- throw new IOException (
776+ throw new GoogleAuthException (
777+ false ,
778+ 0 ,
776779 String .format (
777780 "Invalid R or S length. R: %d, S: %d, Expected: %d" ,
778- r .length , s .length , keySizeBytes ));
781+ r .length , s .length , keySizeBytes ),
782+ null );
779783 }
780784
781785 byte [] result = new byte [outputLength ];
0 commit comments