Skip to content

Commit 4221a5e

Browse files
authored
Merge branch 'main' into dependabot/maven/org.apache.maven.plugins-maven-gpg-plugin-3.2.8
2 parents 49f2dfb + 3f1d47e commit 4221a5e

8 files changed

Lines changed: 997 additions & 6 deletions

File tree

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727

2828
- name: SonarQube Scan
2929
if: ${{ github.actor != 'dependabot[bot]' }}
30-
uses: SonarSource/sonarqube-scan-action@v5.2.0
30+
uses: SonarSource/sonarqube-scan-action@v6.0.0
3131
env:
3232
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
3333
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ Core lib's Maven group ID is `io.apimatic`, and its artifact ID is `core`.
7575
| [`TestHelper`](./src/main/java/io/apimatic/core/utilities/TestHelper.java) | Contains utility methods for comparing objects, arrays and files |
7676
| [`AdditionalProperties`](./src/main/java/io/apimatic/core/types/AdditionalProperties.java) | A generic class for managing additional properties in a model. |
7777
| [`ConversionHelper`](./src/main/java/io/apimatic/core/utilities/ConversionHelper.java) | A Helper class for the coversion of type (provided as function) for all structures (array, map, array of map, n-dimensional arrays etc) supported in the SDK. |
78+
| [`HmacSignatureVerifier`](./src/main/java/io/apimatic/core/security/HmacSignatureVerifier.java) | HMAC-based signature verifier for HTTP requests. |
79+
| [`DigestCodecFactory`](./src/main/java/io/apimatic/core/security/DigestCodecFactory.java) | Factory class for creating digest codecs based on encoding type (Hex, Base64, Base64Url). |
7880

7981
## Interfaces
8082

@@ -85,6 +87,7 @@ Core lib's Maven group ID is `io.apimatic`, and its artifact ID is `core`.
8587
| [`RequestSupplier`](./src/main/java/io/apimatic/core/request/async/RequestSupplier.java) | A Request Supplier that supplies the request |
8688
| [`TypeCombinator`](./src/main/java/io/apimatic/core/annotations/TypeCombinator.java) | This is a container of annotations for oneOf/anyOf cases |
8789
| [`PaginationStrategy`](./src/main/java/io/apimatic/core/types/pagination/PaginationStrategy.java) | Provides the functionality to apply pagination parameters and return new request |
90+
| [`DigestCodec`](./src/main/java/io/apimatic/core/security/DigestCodec.java) | Interface for encoding and decoding digest values |
8891

8992
## Links
9093

pom.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>io.apimatic</groupId>
77
<artifactId>core</artifactId>
8-
<version>0.6.14</version>
8+
<version>0.6.15</version>
99

1010
<name>core-library</name>
1111
<description>A library that contains core logic and utilities for consuming REST APIs using Java SDKs generated by APIMatic.</description>
@@ -79,7 +79,7 @@
7979
<dependency>
8080
<groupId>org.jacoco</groupId>
8181
<artifactId>jacoco-maven-plugin</artifactId>
82-
<version>0.8.10</version>
82+
<version>0.8.14</version>
8383
<scope>test</scope>
8484
</dependency>
8585
<dependency>
@@ -131,15 +131,15 @@
131131
<plugin>
132132
<groupId>org.codehaus.mojo</groupId>
133133
<artifactId>versions-maven-plugin</artifactId>
134-
<version>2.5</version>
134+
<version>2.20.1</version>
135135
<configuration>
136136
<rulesUri>file://${project.basedir}/version-rules.xml</rulesUri>
137137
</configuration>
138138
</plugin>
139139
<plugin>
140140
<groupId>org.jacoco</groupId>
141141
<artifactId>jacoco-maven-plugin</artifactId>
142-
<version>0.8.5</version>
142+
<version>0.8.14</version>
143143
<executions>
144144
<execution>
145145
<goals>
@@ -214,7 +214,7 @@
214214
<plugin>
215215
<groupId>org.apache.maven.plugins</groupId>
216216
<artifactId>maven-javadoc-plugin</artifactId>
217-
<version>2.9.1</version>
217+
<version>3.11.3</version>
218218
<configuration>
219219
<source>8</source>
220220
</configuration>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package io.apimatic.core.security;
2+
3+
/**
4+
* Interface for encoding and decoding digest values.
5+
*/
6+
public interface DigestCodec {
7+
/**
8+
* Encodes a byte array digest into a string representation.
9+
*
10+
* @param bytes The byte array to encode.
11+
* @return The encoded string representation.
12+
*/
13+
String encode(byte[] bytes);
14+
15+
/**
16+
* Decodes a string representation back into a byte array.
17+
*
18+
* @param encoded The encoded string to decode.
19+
* @return The decoded byte array.
20+
*/
21+
byte[] decode(String encoded);
22+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
package io.apimatic.core.security;
2+
3+
import java.util.Base64;
4+
5+
/**
6+
* Factory class for creating digest codecs based on encoding type.
7+
*/
8+
public final class DigestCodecFactory {
9+
10+
private DigestCodecFactory() { } // Prevent instantiation
11+
12+
/**
13+
* Creates a Hex codec.
14+
* @return a DigestCodec for Hex encoding/decoding
15+
*/
16+
public static DigestCodec hex() {
17+
return new HexDigestCodec();
18+
}
19+
20+
/**
21+
* Creates a Base64 codec.
22+
* @return a DigestCodec for Base64 encoding/decoding
23+
*/
24+
public static DigestCodec base64() {
25+
return new Base64DigestCodec();
26+
}
27+
28+
/**
29+
* Creates a Base64Url codec.
30+
* @return a DigestCodec for Base64Url encoding/decoding
31+
*/
32+
public static DigestCodec base64Url() {
33+
return new Base64UrlDigestCodec();
34+
}
35+
36+
private static final int HEX_RADIX = 16;
37+
private static final int HEX_BYTE_MASK = 0xff;
38+
private static final int HEX_BYTE_LENGTH = 2;
39+
private static final int HEX_SHIFT = 4;
40+
41+
/**
42+
* Codec for Hex encoding/decoding.
43+
*/
44+
private static class HexDigestCodec implements DigestCodec {
45+
@Override
46+
public String encode(byte[] bytes) {
47+
StringBuilder sb = new StringBuilder();
48+
for (byte b : bytes) {
49+
sb.append(String.format("%02x", b & HEX_BYTE_MASK));
50+
}
51+
return sb.toString();
52+
}
53+
54+
@Override
55+
public byte[] decode(String encoded) {
56+
int len = encoded.length();
57+
if (len % HEX_BYTE_LENGTH != 0) {
58+
throw new IllegalArgumentException("Invalid hex string length.");
59+
}
60+
byte[] result = new byte[len / HEX_BYTE_LENGTH];
61+
for (int i = 0; i < len; i += HEX_BYTE_LENGTH) {
62+
result[i / HEX_BYTE_LENGTH] = (byte) (
63+
(Character.digit(encoded.charAt(i), HEX_RADIX) << HEX_SHIFT)
64+
+ Character.digit(encoded.charAt(i + 1), HEX_RADIX));
65+
}
66+
return result;
67+
}
68+
}
69+
70+
/**
71+
* Codec for Base64 encoding/decoding.
72+
*/
73+
private static class Base64DigestCodec implements DigestCodec {
74+
@Override
75+
public String encode(byte[] bytes) {
76+
return Base64.getEncoder().encodeToString(bytes);
77+
}
78+
79+
@Override
80+
public byte[] decode(String encoded) {
81+
return Base64.getDecoder().decode(encoded);
82+
}
83+
}
84+
85+
/**
86+
* Codec for Base64Url encoding/decoding.
87+
*/
88+
private static class Base64UrlDigestCodec implements DigestCodec {
89+
@Override
90+
public String encode(byte[] bytes) {
91+
return Base64.getUrlEncoder().withoutPadding().encodeToString(bytes);
92+
}
93+
94+
@Override
95+
public byte[] decode(String encoded) {
96+
return Base64.getUrlDecoder().decode(encoded);
97+
}
98+
}
99+
}

0 commit comments

Comments
 (0)