mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-12-22 19:08:00 +01:00
Pad long KeyIDs with zeros to 16 chars
This commit is contained in:
parent
9ac681d88c
commit
41dfe71994
2 changed files with 42 additions and 1 deletions
|
@ -32,6 +32,6 @@ public final class KeyIdUtil {
|
|||
}
|
||||
|
||||
public static String formatKeyId(long keyId) {
|
||||
return Long.toHexString(keyId).toUpperCase();
|
||||
return String.format("%016X", keyId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package org.pgpainless.key.util;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class KeyIdUtilTest {
|
||||
|
||||
@Test
|
||||
public void testParsing() {
|
||||
String longKeyId = "b1bd1f049ec87f3d"; // we parse from lowercase, but formatting will produce uppercase
|
||||
long asLong = KeyIdUtil.fromLongKeyId(longKeyId);
|
||||
assertEquals(-5639317053693722819L, asLong);
|
||||
assertEquals(longKeyId.toUpperCase(), KeyIdUtil.formatKeyId(-5639317053693722819L));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParsingLowerAndUppercase() {
|
||||
long fromLower = KeyIdUtil.fromLongKeyId("f5ffdf6d71dd5789");
|
||||
assertEquals(-720611754201229431L, fromLower);
|
||||
long fromUpper = KeyIdUtil.fromLongKeyId("F5FFDF6D71DD5789");
|
||||
assertEquals(-720611754201229431L, fromUpper);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void formatLowerAsUpper() {
|
||||
assertEquals("5F04ACF44FD822B1", KeyIdUtil.formatKeyId(KeyIdUtil.fromLongKeyId("5f04acf44fd822b1")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParsing0() {
|
||||
long asLong = 0L;
|
||||
String formatted = KeyIdUtil.formatKeyId(asLong);
|
||||
assertEquals("0000000000000000", formatted);
|
||||
assertEquals(asLong, KeyIdUtil.fromLongKeyId("0000000000000000"));
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue