mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-12-25 04:17:59 +01:00
Rename buildV4 method
This commit is contained in:
parent
9b5754879a
commit
d6aa003008
4 changed files with 23 additions and 23 deletions
|
@ -30,7 +30,7 @@ class KeyRingTemplates {
|
||||||
length: RsaLength,
|
length: RsaLength,
|
||||||
passphrase: Passphrase = Passphrase.emptyPassphrase()
|
passphrase: Passphrase = Passphrase.emptyPassphrase()
|
||||||
): PGPSecretKeyRing =
|
): PGPSecretKeyRing =
|
||||||
OpenPgpKeyGenerator.buildV4()
|
OpenPgpKeyGenerator.buildV4Key()
|
||||||
.setPrimaryKey(KeyType.RSA(length), listOf(KeyFlag.CERTIFY_OTHER)) {
|
.setPrimaryKey(KeyType.RSA(length), listOf(KeyFlag.CERTIFY_OTHER)) {
|
||||||
if (userId != null) {
|
if (userId != null) {
|
||||||
addUserId(userId)
|
addUserId(userId)
|
||||||
|
@ -76,7 +76,7 @@ class KeyRingTemplates {
|
||||||
length: RsaLength,
|
length: RsaLength,
|
||||||
passphrase: Passphrase = Passphrase.emptyPassphrase()
|
passphrase: Passphrase = Passphrase.emptyPassphrase()
|
||||||
): PGPSecretKeyRing =
|
): PGPSecretKeyRing =
|
||||||
OpenPgpKeyGenerator.buildV4()
|
OpenPgpKeyGenerator.buildV4Key()
|
||||||
.setPrimaryKey(
|
.setPrimaryKey(
|
||||||
KeyType.RSA(length),
|
KeyType.RSA(length),
|
||||||
listOf(
|
listOf(
|
||||||
|
@ -124,7 +124,7 @@ class KeyRingTemplates {
|
||||||
userId: CharSequence?,
|
userId: CharSequence?,
|
||||||
passphrase: Passphrase = Passphrase.emptyPassphrase()
|
passphrase: Passphrase = Passphrase.emptyPassphrase()
|
||||||
): PGPSecretKeyRing =
|
): PGPSecretKeyRing =
|
||||||
OpenPgpKeyGenerator.buildV4()
|
OpenPgpKeyGenerator.buildV4Key()
|
||||||
.setPrimaryKey(
|
.setPrimaryKey(
|
||||||
KeyType.EDDSA(EdDSACurve._Ed25519),
|
KeyType.EDDSA(EdDSACurve._Ed25519),
|
||||||
listOf(KeyFlag.CERTIFY_OTHER, KeyFlag.SIGN_DATA)) {
|
listOf(KeyFlag.CERTIFY_OTHER, KeyFlag.SIGN_DATA)) {
|
||||||
|
@ -167,7 +167,7 @@ class KeyRingTemplates {
|
||||||
userId: CharSequence?,
|
userId: CharSequence?,
|
||||||
passphrase: Passphrase = Passphrase.emptyPassphrase()
|
passphrase: Passphrase = Passphrase.emptyPassphrase()
|
||||||
): PGPSecretKeyRing =
|
): PGPSecretKeyRing =
|
||||||
OpenPgpKeyGenerator.buildV4()
|
OpenPgpKeyGenerator.buildV4Key()
|
||||||
.setPrimaryKey(KeyType.EDDSA(EdDSACurve._Ed25519), listOf(KeyFlag.CERTIFY_OTHER)) {
|
.setPrimaryKey(KeyType.EDDSA(EdDSACurve._Ed25519), listOf(KeyFlag.CERTIFY_OTHER)) {
|
||||||
if (userId != null) {
|
if (userId != null) {
|
||||||
addUserId(userId)
|
addUserId(userId)
|
||||||
|
|
|
@ -58,7 +58,7 @@ class OpenPgpKeyGenerator internal constructor() {
|
||||||
* @param preferences suite of algorithm preferences and enabled features
|
* @param preferences suite of algorithm preferences and enabled features
|
||||||
*/
|
*/
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun buildV4(
|
fun buildV4Key(
|
||||||
policy: Policy = PGPainless.getPolicy(),
|
policy: Policy = PGPainless.getPolicy(),
|
||||||
creationTime: Date = Date(),
|
creationTime: Date = Date(),
|
||||||
preferences: AlgorithmSuite = policy.keyGenerationAlgorithmSuite
|
preferences: AlgorithmSuite = policy.keyGenerationAlgorithmSuite
|
||||||
|
@ -933,7 +933,7 @@ class OpenPgpKeyTemplates private constructor() {
|
||||||
vararg userId: CharSequence,
|
vararg userId: CharSequence,
|
||||||
creationTime: Date = Date()
|
creationTime: Date = Date()
|
||||||
): PGPSecretKeyRing =
|
): PGPSecretKeyRing =
|
||||||
OpenPgpKeyGenerator.buildV4(creationTime = creationTime)
|
OpenPgpKeyGenerator.buildV4Key(creationTime = creationTime)
|
||||||
.setPrimaryKey(KeyType.EDDSA(EdDSACurve._Ed25519)) {
|
.setPrimaryKey(KeyType.EDDSA(EdDSACurve._Ed25519)) {
|
||||||
// Add UserIDs
|
// Add UserIDs
|
||||||
userId.forEachIndexed { index, uid ->
|
userId.forEachIndexed { index, uid ->
|
||||||
|
@ -977,7 +977,7 @@ class OpenPgpKeyTemplates private constructor() {
|
||||||
creationTime: Date = Date(),
|
creationTime: Date = Date(),
|
||||||
length: RsaLength = RsaLength._4096
|
length: RsaLength = RsaLength._4096
|
||||||
): PGPSecretKeyRing =
|
): PGPSecretKeyRing =
|
||||||
OpenPgpKeyGenerator.buildV4(creationTime = creationTime)
|
OpenPgpKeyGenerator.buildV4Key(creationTime = creationTime)
|
||||||
.setPrimaryKey(KeyType.RSA(length)) {
|
.setPrimaryKey(KeyType.RSA(length)) {
|
||||||
// Add UserIDs
|
// Add UserIDs
|
||||||
userId.forEachIndexed { index, uid ->
|
userId.forEachIndexed { index, uid ->
|
||||||
|
@ -1020,7 +1020,7 @@ class OpenPgpKeyTemplates private constructor() {
|
||||||
creationTime: Date = Date(),
|
creationTime: Date = Date(),
|
||||||
length: RsaLength = RsaLength._4096
|
length: RsaLength = RsaLength._4096
|
||||||
): PGPSecretKeyRing =
|
): PGPSecretKeyRing =
|
||||||
OpenPgpKeyGenerator.buildV4(creationTime = creationTime)
|
OpenPgpKeyGenerator.buildV4Key(creationTime = creationTime)
|
||||||
.setPrimaryKey(KeyType.RSA(length)) {
|
.setPrimaryKey(KeyType.RSA(length)) {
|
||||||
userId.forEach { addUserId(it) }
|
userId.forEach { addUserId(it) }
|
||||||
addDirectKeySignature(
|
addDirectKeySignature(
|
||||||
|
|
|
@ -24,7 +24,7 @@ class MalformedKeyGenerationTest {
|
||||||
fun malformedPrimaryUserIdSubpacket() {
|
fun malformedPrimaryUserIdSubpacket() {
|
||||||
val userId = "Alice <alice@pgpainless.org>"
|
val userId = "Alice <alice@pgpainless.org>"
|
||||||
val key =
|
val key =
|
||||||
OpenPgpKeyGenerator.buildV4(Policy())
|
OpenPgpKeyGenerator.buildV4Key(Policy())
|
||||||
.setPrimaryKey(KeyType.EDDSA(EdDSACurve._Ed25519)) {
|
.setPrimaryKey(KeyType.EDDSA(EdDSACurve._Ed25519)) {
|
||||||
addUserId(
|
addUserId(
|
||||||
userId,
|
userId,
|
||||||
|
@ -43,7 +43,7 @@ class MalformedKeyGenerationTest {
|
||||||
@Test
|
@Test
|
||||||
fun malformedExportableSubpacket() {
|
fun malformedExportableSubpacket() {
|
||||||
val key =
|
val key =
|
||||||
OpenPgpKeyGenerator.buildV4(Policy())
|
OpenPgpKeyGenerator.buildV4Key(Policy())
|
||||||
.setPrimaryKey(KeyType.EDDSA(EdDSACurve._Ed25519)) {
|
.setPrimaryKey(KeyType.EDDSA(EdDSACurve._Ed25519)) {
|
||||||
addUserId(
|
addUserId(
|
||||||
"Alice <alice@pgpainless.org>",
|
"Alice <alice@pgpainless.org>",
|
||||||
|
@ -62,7 +62,7 @@ class MalformedKeyGenerationTest {
|
||||||
@Test
|
@Test
|
||||||
fun malformedRevocableSubpacket() {
|
fun malformedRevocableSubpacket() {
|
||||||
val key =
|
val key =
|
||||||
OpenPgpKeyGenerator.buildV4(Policy())
|
OpenPgpKeyGenerator.buildV4Key(Policy())
|
||||||
.setPrimaryKey(KeyType.EDDSA(EdDSACurve._Ed25519)) {
|
.setPrimaryKey(KeyType.EDDSA(EdDSACurve._Ed25519)) {
|
||||||
addUserId(
|
addUserId(
|
||||||
"Alice <alice@pgpainless.org>",
|
"Alice <alice@pgpainless.org>",
|
||||||
|
@ -82,7 +82,7 @@ class MalformedKeyGenerationTest {
|
||||||
fun primaryUserIdOnDirectKeySig() {
|
fun primaryUserIdOnDirectKeySig() {
|
||||||
val policy = Policy()
|
val policy = Policy()
|
||||||
val key =
|
val key =
|
||||||
OpenPgpKeyGenerator.buildV4(policy)
|
OpenPgpKeyGenerator.buildV4Key(policy)
|
||||||
.setPrimaryKey(
|
.setPrimaryKey(
|
||||||
KeyType.EDDSA(EdDSACurve._Ed25519),
|
KeyType.EDDSA(EdDSACurve._Ed25519),
|
||||||
listOf(KeyFlag.CERTIFY_OTHER, KeyFlag.SIGN_DATA)) {
|
listOf(KeyFlag.CERTIFY_OTHER, KeyFlag.SIGN_DATA)) {
|
||||||
|
|
|
@ -26,7 +26,7 @@ class OpenPgpKeyGeneratorTest {
|
||||||
@Test
|
@Test
|
||||||
fun `minimal call with opinionated builder adds a default DK sig but no user info`() {
|
fun `minimal call with opinionated builder adds a default DK sig but no user info`() {
|
||||||
val key =
|
val key =
|
||||||
OpenPgpKeyGenerator.buildV4().setPrimaryKey(KeyType.EDDSA(EdDSACurve._Ed25519)).build()
|
OpenPgpKeyGenerator.buildV4Key().setPrimaryKey(KeyType.EDDSA(EdDSACurve._Ed25519)).build()
|
||||||
|
|
||||||
assertFalse(key.publicKey.userIDs.hasNext(), "Key MUST NOT have a UserID")
|
assertFalse(key.publicKey.userIDs.hasNext(), "Key MUST NOT have a UserID")
|
||||||
assertFalse(key.publicKey.userAttributes.hasNext(), "Key MUST NOT have a UserAttribute")
|
assertFalse(key.publicKey.userAttributes.hasNext(), "Key MUST NOT have a UserAttribute")
|
||||||
|
@ -41,7 +41,7 @@ class OpenPgpKeyGeneratorTest {
|
||||||
@Test
|
@Test
|
||||||
fun `minimal call with unopinionated builder does not add a default DK sig`() {
|
fun `minimal call with unopinionated builder does not add a default DK sig`() {
|
||||||
val key =
|
val key =
|
||||||
OpenPgpKeyGenerator.buildV4()
|
OpenPgpKeyGenerator.buildV4Key()
|
||||||
.unopinionated()
|
.unopinionated()
|
||||||
.setPrimaryKey(KeyType.EDDSA(EdDSACurve._Ed25519))
|
.setPrimaryKey(KeyType.EDDSA(EdDSACurve._Ed25519))
|
||||||
.build()
|
.build()
|
||||||
|
@ -54,7 +54,7 @@ class OpenPgpKeyGeneratorTest {
|
||||||
@Test
|
@Test
|
||||||
fun `adding a direct-key signature with the opinionated builder omits the default DK sig`() {
|
fun `adding a direct-key signature with the opinionated builder omits the default DK sig`() {
|
||||||
val key =
|
val key =
|
||||||
OpenPgpKeyGenerator.buildV4()
|
OpenPgpKeyGenerator.buildV4Key()
|
||||||
.setPrimaryKey(KeyType.EDDSA(EdDSACurve._Ed25519)) {
|
.setPrimaryKey(KeyType.EDDSA(EdDSACurve._Ed25519)) {
|
||||||
addDirectKeySignature() // "overwrites" the default dk sig
|
addDirectKeySignature() // "overwrites" the default dk sig
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ class OpenPgpKeyGeneratorTest {
|
||||||
@Test
|
@Test
|
||||||
fun `adding two user-ids will mark the first one as primary`() {
|
fun `adding two user-ids will mark the first one as primary`() {
|
||||||
val key =
|
val key =
|
||||||
OpenPgpKeyGenerator.buildV4()
|
OpenPgpKeyGenerator.buildV4Key()
|
||||||
.setPrimaryKey(KeyType.EDDSA(EdDSACurve._Ed25519)) {
|
.setPrimaryKey(KeyType.EDDSA(EdDSACurve._Ed25519)) {
|
||||||
addUserId("Primary <primary@example.com>")
|
addUserId("Primary <primary@example.com>")
|
||||||
addUserId("Non Primary <non-primary@example.com>")
|
addUserId("Non Primary <non-primary@example.com>")
|
||||||
|
@ -82,7 +82,7 @@ class OpenPgpKeyGeneratorTest {
|
||||||
@Test
|
@Test
|
||||||
fun `adding two user-ids but mark the first as non-primary will mark the second one as primary`() {
|
fun `adding two user-ids but mark the first as non-primary will mark the second one as primary`() {
|
||||||
val key =
|
val key =
|
||||||
OpenPgpKeyGenerator.buildV4()
|
OpenPgpKeyGenerator.buildV4Key()
|
||||||
.setPrimaryKey(KeyType.EDDSA(EdDSACurve._Ed25519)) {
|
.setPrimaryKey(KeyType.EDDSA(EdDSACurve._Ed25519)) {
|
||||||
addUserId(
|
addUserId(
|
||||||
"Non Primary <non-primary@example.com>",
|
"Non Primary <non-primary@example.com>",
|
||||||
|
@ -101,7 +101,7 @@ class OpenPgpKeyGeneratorTest {
|
||||||
@Test
|
@Test
|
||||||
fun testUnopinionatedV4() {
|
fun testUnopinionatedV4() {
|
||||||
// Unopinionated
|
// Unopinionated
|
||||||
OpenPgpKeyGenerator.buildV4()
|
OpenPgpKeyGenerator.buildV4Key()
|
||||||
.unopinionated()
|
.unopinionated()
|
||||||
.setPrimaryKey(KeyType.EDDSA(EdDSACurve._Ed25519)) {
|
.setPrimaryKey(KeyType.EDDSA(EdDSACurve._Ed25519)) {
|
||||||
addDirectKeySignature()
|
addDirectKeySignature()
|
||||||
|
@ -116,7 +116,7 @@ class OpenPgpKeyGeneratorTest {
|
||||||
fun testOpinionatedV4() {
|
fun testOpinionatedV4() {
|
||||||
// Opinionated
|
// Opinionated
|
||||||
val time = DateUtil.parseUTCDate("2024-01-01 00:00:00 UTC")
|
val time = DateUtil.parseUTCDate("2024-01-01 00:00:00 UTC")
|
||||||
OpenPgpKeyGenerator.buildV4(creationTime = time)
|
OpenPgpKeyGenerator.buildV4Key(creationTime = time)
|
||||||
.setPrimaryKey(KeyType.EDDSA(EdDSACurve._Ed25519), listOf(KeyFlag.CERTIFY_OTHER)) {
|
.setPrimaryKey(KeyType.EDDSA(EdDSACurve._Ed25519), listOf(KeyFlag.CERTIFY_OTHER)) {
|
||||||
addUserId("Alice <alice@pgpainless.org>")
|
addUserId("Alice <alice@pgpainless.org>")
|
||||||
}
|
}
|
||||||
|
@ -149,7 +149,7 @@ class OpenPgpKeyGeneratorTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun test() {
|
fun test() {
|
||||||
OpenPgpKeyGenerator.buildV4()
|
OpenPgpKeyGenerator.buildV4Key()
|
||||||
.setPrimaryKey(KeyType.RSA(RsaLength._3072), keyFlags = listOf(KeyFlag.CERTIFY_OTHER))
|
.setPrimaryKey(KeyType.RSA(RsaLength._3072), keyFlags = listOf(KeyFlag.CERTIFY_OTHER))
|
||||||
.build()
|
.build()
|
||||||
.toAsciiArmor()
|
.toAsciiArmor()
|
||||||
|
@ -163,7 +163,7 @@ class OpenPgpKeyGeneratorTest {
|
||||||
Policy.PublicKeyAlgorithmPolicy(buildMap { put(PublicKeyAlgorithm.RSA_GENERAL, 3072) })
|
Policy.PublicKeyAlgorithmPolicy(buildMap { put(PublicKeyAlgorithm.RSA_GENERAL, 3072) })
|
||||||
|
|
||||||
assertThrows<IllegalArgumentException> {
|
assertThrows<IllegalArgumentException> {
|
||||||
OpenPgpKeyGenerator.buildV4(policy)
|
OpenPgpKeyGenerator.buildV4Key(policy)
|
||||||
// opinionated builder verifies PK parameters
|
// opinionated builder verifies PK parameters
|
||||||
.setPrimaryKey(KeyType.RSA(RsaLength._2048)) // too weak
|
.setPrimaryKey(KeyType.RSA(RsaLength._2048)) // too weak
|
||||||
}
|
}
|
||||||
|
@ -175,7 +175,7 @@ class OpenPgpKeyGeneratorTest {
|
||||||
policy.publicKeyAlgorithmPolicy =
|
policy.publicKeyAlgorithmPolicy =
|
||||||
Policy.PublicKeyAlgorithmPolicy(buildMap { put(PublicKeyAlgorithm.RSA_GENERAL, 3072) })
|
Policy.PublicKeyAlgorithmPolicy(buildMap { put(PublicKeyAlgorithm.RSA_GENERAL, 3072) })
|
||||||
|
|
||||||
OpenPgpKeyGenerator.buildV4(policy)
|
OpenPgpKeyGenerator.buildV4Key(policy)
|
||||||
.unopinionated() // unopinionated builder allows for non-compliant configurations
|
.unopinionated() // unopinionated builder allows for non-compliant configurations
|
||||||
.setPrimaryKey(KeyType.RSA(RsaLength._2048))
|
.setPrimaryKey(KeyType.RSA(RsaLength._2048))
|
||||||
}
|
}
|
||||||
|
@ -183,7 +183,7 @@ class OpenPgpKeyGeneratorTest {
|
||||||
@Test
|
@Test
|
||||||
fun `skip default DirectKey signature will not add one`() {
|
fun `skip default DirectKey signature will not add one`() {
|
||||||
val key =
|
val key =
|
||||||
OpenPgpKeyGenerator.buildV4()
|
OpenPgpKeyGenerator.buildV4Key()
|
||||||
.setPrimaryKey(KeyType.EDDSA(EdDSACurve._Ed25519)) { skipDefaultSignature() }
|
.setPrimaryKey(KeyType.EDDSA(EdDSACurve._Ed25519)) { skipDefaultSignature() }
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue