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