@@ -70,12 +70,8 @@ public SignedDataVerifier(Set<InputStream> rootCertificates, String bundleId, Lo
70
70
*/
71
71
public JWSTransactionDecodedPayload verifyAndDecodeTransaction (String signedTransaction ) throws VerificationException {
72
72
JWSTransactionDecodedPayload transaction = decodeSignedObject (signedTransaction , JWSTransactionDecodedPayload .class );
73
- if (!bundleId .equals (transaction .getBundleId ())) {
74
- throw new VerificationException (VerificationStatus .INVALID_APP_IDENTIFIER );
75
- }
76
- if (!this .environment .equals (transaction .getEnvironment ())) {
77
- throw new VerificationException (VerificationStatus .INVALID_ENVIRONMENT );
78
- }
73
+ validateBundleId (transaction .getBundleId ());
74
+ validateEnvironment (transaction .getEnvironment ());
79
75
return transaction ;
80
76
}
81
77
@@ -89,9 +85,7 @@ public JWSTransactionDecodedPayload verifyAndDecodeTransaction(String signedTran
89
85
*/
90
86
public JWSRenewalInfoDecodedPayload verifyAndDecodeRenewalInfo (String signedRenewalInfo ) throws VerificationException {
91
87
JWSRenewalInfoDecodedPayload renewalInfo = decodeSignedObject (signedRenewalInfo , JWSRenewalInfoDecodedPayload .class );
92
- if (!this .environment .equals (renewalInfo .getEnvironment ())) {
93
- throw new VerificationException (VerificationStatus .INVALID_ENVIRONMENT );
94
- }
88
+ validateEnvironment (renewalInfo .getEnvironment ());
95
89
return renewalInfo ;
96
90
}
97
91
@@ -135,12 +129,9 @@ public ResponseBodyV2DecodedPayload verifyAndDecodeNotification(String signedPay
135
129
}
136
130
137
131
protected void verifyNotification (String bundleId , Long appAppleId , Environment notificationEnv ) throws VerificationException {
138
- if (!this .bundleId .equals (bundleId ) || (this .environment .equals (Environment .PRODUCTION ) && !this .appAppleId .equals (appAppleId ))) {
139
- throw new VerificationException (VerificationStatus .INVALID_APP_IDENTIFIER );
140
- }
141
- if (!this .environment .equals (notificationEnv )) {
142
- throw new VerificationException (VerificationStatus .INVALID_ENVIRONMENT );
143
- }
132
+ validateBundleId (bundleId );
133
+ validateAppAppleId (appAppleId );
134
+ validateEnvironment (notificationEnv );
144
135
}
145
136
146
137
/**
@@ -154,13 +145,28 @@ protected void verifyNotification(String bundleId, Long appAppleId, Environment
154
145
public AppTransaction verifyAndDecodeAppTransaction (String signedAppTransaction ) throws VerificationException {
155
146
AppTransaction appTransaction = decodeSignedObject (signedAppTransaction , AppTransaction .class );
156
147
Environment environment = appTransaction .getReceiptType ();
157
- if (!this .bundleId .equals (appTransaction .getBundleId ()) || (this .environment .equals (Environment .PRODUCTION ) && !this .appAppleId .equals (appTransaction .getAppAppleId ()))) {
148
+ validateBundleId (appTransaction .getBundleId ());
149
+ validateAppAppleId (appTransaction .getAppAppleId ());
150
+ validateEnvironment (environment );
151
+ return appTransaction ;
152
+ }
153
+
154
+ protected void validateAppAppleId (Long appAppleId ) throws VerificationException {
155
+ if (this .environment .equals (Environment .PRODUCTION ) && !this .appAppleId .equals (appAppleId )) {
156
+ throw new VerificationException (VerificationStatus .INVALID_APP_IDENTIFIER );
157
+ }
158
+ }
159
+
160
+ protected void validateBundleId (String bundleId ) throws VerificationException {
161
+ if (!this .bundleId .equals (bundleId )) {
158
162
throw new VerificationException (VerificationStatus .INVALID_APP_IDENTIFIER );
159
163
}
164
+ }
165
+
166
+ protected void validateEnvironment (Environment environment ) throws VerificationException {
160
167
if (!this .environment .equals (environment )) {
161
168
throw new VerificationException (VerificationStatus .INVALID_ENVIRONMENT );
162
169
}
163
- return appTransaction ;
164
170
}
165
171
166
172
protected <T extends DecodedSignedData > T decodeSignedObject (String signedObject , Class <T > clazz ) throws VerificationException {
0 commit comments