3939import static com .microsoft .identity .common .java .exception .ClientException .NO_SUCH_PADDING ;
4040import static com .microsoft .identity .common .java .exception .ClientException .SIGNING_FAILURE ;
4141import static com .microsoft .identity .common .java .exception .ClientException .THUMBPRINT_COMPUTATION_FAILURE ;
42+ import static com .microsoft .identity .common .java .exception .ClientException .UNKNOWN_CRYPTO_ERROR ;
4243import static com .microsoft .identity .common .java .exception .ClientException .UNKNOWN_EXPORT_FORMAT ;
4344import static com .microsoft .identity .common .java .marker .PerfConstants .CodeMarkerConstants .GENERATE_AT_POP_ASYMMETRIC_KEYPAIR_END ;
4445import static com .microsoft .identity .common .java .marker .PerfConstants .CodeMarkerConstants .GENERATE_AT_POP_ASYMMETRIC_KEYPAIR_START ;
@@ -626,6 +627,15 @@ public byte[] encrypt(@NonNull final Cipher cipher, @NonNull final byte[] plaint
626627 }
627628 }
628629
630+ /**
631+ * Maps cryptographic exceptions to corresponding ClientException error code constants.
632+ * This helper method is used by both encrypt and decrypt operations to provide consistent
633+ * error code mappings for various cryptographic failure scenarios.
634+ *
635+ * @param e The exception to map to an error code. Must be non-null.
636+ * @return The corresponding ClientException error code constant.
637+ * Note : Returns {@link ClientException#UNKNOWN_CRYPTO_ERROR} as the default fallback when the exception type doesn't match any known types.
638+ */
629639 private String mapCryptoExceptionToErrorCode (@ NonNull final Exception e ) {
630640 if (e instanceof NoSuchAlgorithmException ) {
631641 return NO_SUCH_ALGORITHM ;
@@ -644,7 +654,7 @@ private String mapCryptoExceptionToErrorCode(@NonNull final Exception e) {
644654 } else if (e instanceof InvalidAlgorithmParameterException ) {
645655 return INVALID_ALG_PARAMETER ;
646656 }
647- return INVALID_KEY ; // default fallback
657+ return UNKNOWN_CRYPTO_ERROR ; // default fallback
648658 }
649659
650660 @ Override
0 commit comments