diff --git a/src/com/google/cose/OkpKey.java b/src/com/google/cose/OkpKey.java index c39ece1..f86927a 100644 --- a/src/com/google/cose/OkpKey.java +++ b/src/com/google/cose/OkpKey.java @@ -43,6 +43,7 @@ public byte[] getPublicKeyBytes() { } public BigInteger getPublicKeyBytesAsBigInteger() { + byte[] publicKeyBytes = getPublicKeyBytes(); // Reverse the bytes to get the correct big-endian representation. byte[] reversedBytes = new byte[publicKeyBytes.length]; for (int i = 0; i < publicKeyBytes.length; i++) { diff --git a/test/com/google/cose/OkpSigningKeyTest.java b/test/com/google/cose/OkpSigningKeyTest.java index c0e88ee..f23a90e 100644 --- a/test/com/google/cose/OkpSigningKeyTest.java +++ b/test/com/google/cose/OkpSigningKeyTest.java @@ -73,6 +73,8 @@ public void testRoundTrip() throws CborException, CoseException { Assert.assertArrayEquals(keyId, rebuiltKey.getKeyId()); Assert.assertArrayEquals(keyWithConstructor.serialize(), rebuiltKey.serialize()); + Assert.assertEquals(keyWithConstructor.getPublicKeyBytesAsBigInteger(), + rebuiltKey.getPublicKeyBytesAsBigInteger()); } @Test @@ -186,4 +188,12 @@ public void testOkpGeneratedKey_verificationWithSignature() throws CborException okpKey.verify(Algorithm.SIGNING_ALGORITHM_EDDSA, TestUtilities.CONTENT_BYTES, signature); } + + @Test + public void testPublicKeyAsBigInteger() throws CborException, CoseException { + OkpSigningKey key = OkpSigningKey.builder().withXCoordinate(X_BYTES).build(); + Assert.assertEquals( + "11903303657706407974989296177215005343713679411332034699907763981919547054807", + key.getPublicKeyBytesAsBigInteger().toString()); + } }