@@ -99,18 +99,16 @@ internal open class DPoPKeyStore {
9999 if (publicKey != null ) {
100100 return Pair (privateKey, publicKey)
101101 }
102- } catch (e: KeyStoreException ) {
103- throw DPoPException (DPoPException .Code .KEY_STORE_ERROR , e)
104- } catch (e: NoSuchAlgorithmException ) {
105- throw DPoPException (DPoPException .Code .KEY_STORE_ERROR , e)
106- } catch (e: UnrecoverableKeyException ) {
107- throw DPoPException (DPoPException .Code .KEY_STORE_ERROR , e)
108- } catch (e: ClassCastException ) {
109- throw DPoPException (DPoPException .Code .KEY_STORE_ERROR , e)
110- } catch (e: IOException ) {
111- throw DPoPException (DPoPException .Code .KEY_STORE_ERROR , e)
112- } catch (e: CertificateException ) {
113- throw DPoPException (DPoPException .Code .KEY_STORE_ERROR , e)
102+ } catch (e: Exception ) {
103+ when (e) {
104+ is KeyStoreException ,
105+ is NoSuchAlgorithmException ,
106+ is UnrecoverableKeyException ,
107+ is ClassCastException ,
108+ is IOException ,
109+ is CertificateException -> throw DPoPException (DPoPException .Code .KEY_STORE_ERROR , e)
110+ else -> throw DPoPException (DPoPException .Code .UNKNOWN_ERROR , e)
111+ }
114112 }
115113 Log .d(TAG , " Returning null key pair " )
116114 return null
@@ -119,28 +117,28 @@ internal open class DPoPKeyStore {
119117 fun hasKeyPair (): Boolean {
120118 try {
121119 return keyStore.containsAlias(KEY_ALIAS )
122- } catch (e: KeyStoreException ) {
123- throw DPoPException ( DPoPException . Code . KEY_STORE_ERROR , e)
124- } catch (e : NoSuchAlgorithmException ) {
125- throw DPoPException ( DPoPException . Code . KEY_STORE_ERROR , e)
126- } catch (e : IOException ) {
127- throw DPoPException (DPoPException .Code .KEY_STORE_ERROR , e)
128- } catch (e : CertificateException ) {
129- throw DPoPException ( DPoPException . Code . KEY_STORE_ERROR , e)
120+ } catch (e: Exception ) {
121+ when (e) {
122+ is KeyStoreException ,
123+ is NoSuchAlgorithmException ,
124+ is IOException ,
125+ is CertificateException -> throw DPoPException (DPoPException .Code .KEY_STORE_ERROR , e)
126+ else -> throw DPoPException ( DPoPException . Code . UNKNOWN_ERROR , e)
127+ }
130128 }
131129 }
132130
133131 fun deleteKeyPair () {
134132 try {
135133 keyStore.deleteEntry(KEY_ALIAS )
136- } catch (e: KeyStoreException ) {
137- throw DPoPException ( DPoPException . Code . KEY_STORE_ERROR , e)
138- } catch (e : NoSuchAlgorithmException ) {
139- throw DPoPException ( DPoPException . Code . KEY_STORE_ERROR , e)
140- } catch (e : IOException ) {
141- throw DPoPException (DPoPException .Code .KEY_STORE_ERROR , e)
142- } catch (e : CertificateException ) {
143- throw DPoPException ( DPoPException . Code . KEY_STORE_ERROR , e)
134+ } catch (e: Exception ) {
135+ when (e) {
136+ is KeyStoreException ,
137+ is NoSuchAlgorithmException ,
138+ is IOException ,
139+ is CertificateException -> throw DPoPException (DPoPException .Code .KEY_STORE_ERROR , e)
140+ else -> throw DPoPException ( DPoPException . Code . UNKNOWN_ERROR , e)
141+ }
144142 }
145143 }
146144
0 commit comments