Skip to content

Commit 4f7aee2

Browse files
committed
fmt
1 parent 8f315f8 commit 4f7aee2

3 files changed

Lines changed: 8 additions & 12 deletions

File tree

‎src/main/java/com/coinbase/examples/apikey/RotateApiKey.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ public static void main(String[] args) {
4949
Utils.getObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(response));
5050

5151
String signingKey =
52-
Utils.getObjectMapper().readTree(System.getenv("COINBASE_PRIME_CREDENTIALS"))
52+
Utils.getObjectMapper()
53+
.readTree(System.getenv("COINBASE_PRIME_CREDENTIALS"))
5354
.get("signingKey")
5455
.asText();
5556
RotatedApiKeyCredentials rotated = ApiKeyRotation.decrypt(signingKey, response);

‎src/main/java/com/coinbase/prime/apikey/ApiKeyRotation.java‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
* Decrypts {@code encrypted_credentials} from {@link RotateApiKeyResponse} using only the JDK:
3434
* HKDF-SHA256 (RFC 5869) and AES-256-GCM.
3535
*
36-
* <p>Wire format after Base64 decode: {@code version(1) | salt(32) | nonce(12) |
37-
* ciphertext+tag}. Version must be {@code 0x01}. HKDF info is {@code api-key-rotation}. See <a
36+
* <p>Wire format after Base64 decode: {@code version(1) | salt(32) | nonce(12) | ciphertext+tag}.
37+
* Version must be {@code 0x01}. HKDF info is {@code api-key-rotation}. See <a
3838
* href="https://docs.cdp.coinbase.com/prime/rest-api/api-key-rotation">API Key Rotation</a>.
3939
*/
4040
public final class ApiKeyRotation {
@@ -116,9 +116,7 @@ public static RotatedApiKeyCredentials decrypt(String secretKey, String encrypte
116116
}
117117
}
118118

119-
/**
120-
* HKDF-SHA256 (RFC 5869) extract-then-expand. Package-visible for RFC test vectors.
121-
*/
119+
/** HKDF-SHA256 (RFC 5869) extract-then-expand. Package-visible for RFC test vectors. */
122120
static byte[] hkdfSha256(byte[] ikm, byte[] salt, byte[] info, int length)
123121
throws GeneralSecurityException {
124122
if (length <= 0 || length > 255 * HASH_LEN) {

‎src/test/java/com/coinbase/prime/apikey/ApiKeyRotationTest.java‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ public void hkdfSha256MatchesRfc5869TestCase1() throws Exception {
3636
byte[] ikm = hex("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b");
3737
byte[] salt = hex("000102030405060708090a0b0c");
3838
byte[] info = hex("f0f1f2f3f4f5f6f7f8f9");
39-
byte[] okm =
40-
ApiKeyRotation.hkdfSha256(ikm, salt, info, 42);
39+
byte[] okm = ApiKeyRotation.hkdfSha256(ikm, salt, info, 42);
4140
assertArrayEquals(
4241
hex("3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1a5a4c5db02d56ecc4c5bf34007208d5b887185865"),
4342
okm);
@@ -73,8 +72,7 @@ public void decryptRoundTrip() throws Exception {
7372
@Test
7473
public void decryptAcceptsMissingBase64Padding() throws Exception {
7574
String secretKey = "current-signing-key";
76-
String plaintext =
77-
"{\"access_key\":\"a\",\"secret_key\":\"s\",\"passphrase\":\"p\"}";
75+
String plaintext = "{\"access_key\":\"a\",\"secret_key\":\"s\",\"passphrase\":\"p\"}";
7876
String encrypted = encrypt(secretKey, plaintext);
7977
while (encrypted.endsWith("=")) {
8078
encrypted = encrypted.substring(0, encrypted.length() - 1);
@@ -101,8 +99,7 @@ public void decryptRejectsWrongVersion() {
10199
public void decryptRejectsWrongSecret() throws Exception {
102100
String encrypted =
103101
encrypt(
104-
"correct-secret",
105-
"{\"access_key\":\"a\",\"secret_key\":\"s\",\"passphrase\":\"p\"}");
102+
"correct-secret", "{\"access_key\":\"a\",\"secret_key\":\"s\",\"passphrase\":\"p\"}");
106103
assertThrows(
107104
CoinbaseClientException.class, () -> ApiKeyRotation.decrypt("wrong-secret", encrypted));
108105
}

0 commit comments

Comments
 (0)