Skip to content

Commit 1a9aab6

Browse files
committed
refactor: linter issue fixed
1 parent ced1891 commit 1a9aab6

4 files changed

Lines changed: 26 additions & 11 deletions

File tree

src/main/java/io/apimatic/core/security/DigestCodecFactory.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ public byte[] decode(String encoded) {
5959
}
6060
byte[] result = new byte[len / HEX_BYTE_LENGTH];
6161
for (int i = 0; i < len; i += HEX_BYTE_LENGTH) {
62-
result[i / HEX_BYTE_LENGTH] = (byte) ((Character.digit(encoded.charAt(i), HEX_RADIX) << HEX_SHIFT)
62+
result[i / HEX_BYTE_LENGTH] = (byte) (
63+
(Character.digit(encoded.charAt(i), HEX_RADIX) << HEX_SHIFT)
6364
+ Character.digit(encoded.charAt(i + 1), HEX_RADIX));
6465
}
6566
return result;

src/main/java/io/apimatic/core/security/HmacSignatureVerifier.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,19 @@ public CompletableFuture<VerificationResult> verifyAsync(final Request request)
144144
private byte[] extractSignature(final String headerValue) {
145145
try {
146146
int index = signatureValueTemplate.indexOf(SIGNATURE_VALUE_PLACEHOLDER);
147-
if (index < 0) { return null; }
147+
if (index < 0) {
148+
return null;
149+
}
148150

149151
String prefix = signatureValueTemplate.substring(0, index);
150152
String suffix = signatureValueTemplate.substring(
151153
index + SIGNATURE_VALUE_PLACEHOLDER.length());
152154

153155
// find prefix anywhere (case-insensitive)
154156
int prefixAt = indexOfIgnoreCase(headerValue, prefix, 0);
155-
if (prefixAt < 0) { return null; }
157+
if (prefixAt < 0) {
158+
return null;
159+
}
156160

157161
int digestStart = prefixAt + prefix.length();
158162

@@ -162,10 +166,14 @@ private byte[] extractSignature(final String headerValue) {
162166
digestEnd = headerValue.length();
163167
} else {
164168
digestEnd = indexOfIgnoreCase(headerValue, suffix, digestStart);
165-
if (digestEnd < 0) { return null; }
169+
if (digestEnd < 0) {
170+
return null;
171+
}
166172
}
167173

168-
if (digestEnd < digestStart) { return null; }
174+
if (digestEnd < digestStart) {
175+
return null;
176+
}
169177

170178
String digest = headerValue.substring(digestStart, digestEnd).trim();
171179
// strip Optional Quotes
@@ -182,7 +190,7 @@ private byte[] extractSignature(final String headerValue) {
182190
}
183191

184192
/**
185-
* Finds the index of the first case-insensitive occurrence of {@code needle} in {@code haystack}
193+
* Finds the index of the first case-insensitive {@code needle} in {@code haystack}
186194
* starting from {@code fromIndex}, or -1 if not found.
187195
*
188196
* @param haystack The string to search in.
@@ -195,7 +203,9 @@ private static int indexOfIgnoreCase(
195203
final String needle,
196204
final int fromIndex
197205
) {
198-
if (needle.isEmpty()) { return fromIndex; }
206+
if (needle.isEmpty()) {
207+
return fromIndex;
208+
}
199209
int max = haystack.length() - needle.length();
200210
for (int i = Math.max(0, fromIndex); i <= max; i++) {
201211
if (haystack.regionMatches(true, i, needle, 0, needle.length())) {

src/test/java/apimatic/core/security/DigestCodecFactoryTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ public void testBase64DecodeInvalid() {
9595
@Test
9696
public void testBase64UrlEncodeDecode() {
9797
DigestCodec codec = DigestCodecFactory.base64Url();
98-
byte[] input = {BASE64URL_BYTE_1, BASE64URL_BYTE_2, BASE64URL_BYTE_3, BASE64URL_BYTE_4, BASE64URL_BYTE_5};
98+
byte[] input = {BASE64URL_BYTE_1, BASE64URL_BYTE_2,
99+
BASE64URL_BYTE_3, BASE64URL_BYTE_4, BASE64URL_BYTE_5};
99100
String encoded = codec.encode(input);
100101
assertEquals("ChQeKDI", encoded); // without padding
101102
assertArrayEquals(input, codec.decode(encoded));

src/test/java/apimatic/core/security/HmacSignatureVerifierTest.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,8 @@ public void verifyAsyncSuccessRequestSignatureTemplateResolverBody() throws Exce
414414
Map<String, String> headers = new HashMap<>();
415415
String signature = computeSignature(
416416
SECRET_KEY,
417-
"session=abc123:2025-09-17T12:34:56Z:POST:payment:{\"id\":123,\"type\":\"payment\",\"amount\":100.5}",
417+
"session=abc123:2025-09-17T12:34:56Z:POST:payment" +
418+
":{\"id\":123,\"type\":\"payment\",\"amount\":100.5}",
418419
DEFAULT_ALGORITHM, codec
419420
);
420421
headers.put(SIGNATURE_HEADER, signature);
@@ -455,7 +456,8 @@ public void verifyAsyncSuccessRequestSignatureTemplateResolverHeaders() throws E
455456
Map<String, String> headers = new HashMap<>();
456457
String signature = computeSignature(
457458
SECRET_KEY,
458-
"session=abc123:2025-09-17T12:34:56Z:POST:x-signature-header-value:{\"id\":123,\"type\":\"payment\",\"amount\":100.5}",
459+
"session=abc123:2025-09-17T12:34:56Z:POST:x-signature-header-value" +
460+
":{\"id\":123,\"type\":\"payment\",\"amount\":100.5}",
459461
DEFAULT_ALGORITHM, codec
460462
);
461463
headers.put(SIGNATURE_HEADER, signature);
@@ -470,7 +472,8 @@ public void verifyAsyncSuccessRequestSignatureTemplateResolverHeaders() throws E
470472
}
471473
String cookie = request.getHeaders().asSimpleMap().get("Cookie");
472474
String timestamp = request.getHeaders().asSimpleMap().get("X-Timestamp");
473-
String resolvedBody = CoreHelper.resolveRequestPointer("$request.headers#/x-signature", request);
475+
String resolvedBody = CoreHelper.resolveRequestPointer(
476+
"$request.headers#/x-signature", request);
474477

475478
return String.join(
476479
":",

0 commit comments

Comments
 (0)