mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-09-09 02:09:38 +02:00
Compare commits
20 commits
880b0720db
...
7daa3783bc
Author | SHA1 | Date | |
---|---|---|---|
7daa3783bc | |||
4d46edf3b6 | |||
7656bcd101 | |||
9f8ce475eb | |||
4f8c52d215 | |||
16a2bf27eb | |||
742f8fa1a3 | |||
916809ad60 | |||
002bd87136 | |||
05cea3e5a9 | |||
95eb73a8c7 | |||
06b3452c6c | |||
307b3ae40b | |||
0d8ce6a50b | |||
32dc1fa1a1 | |||
4a4f85767a | |||
d1826eb961 | |||
0d807cb6b8 | |||
9b0a3cd4c7 | |||
0ee31b232a |
5 changed files with 22 additions and 15 deletions
|
@ -45,9 +45,6 @@ class KeyRingBuilder : KeyRingBuilderInterface<KeyRingBuilder> {
|
|||
}
|
||||
|
||||
override fun addUserId(userId: CharSequence): KeyRingBuilder = apply {
|
||||
require(!userId.contains("\n") && !userId.contains("\r")) {
|
||||
"User-ID cannot contain newlines and/or carriage returns."
|
||||
}
|
||||
userIds[userId.toString()] = null
|
||||
}
|
||||
|
||||
|
|
|
@ -569,11 +569,10 @@ class SecretKeyRingEditor(
|
|||
}
|
||||
|
||||
private fun sanitizeUserId(userId: CharSequence): CharSequence =
|
||||
userId.toString().also {
|
||||
require(!it.contains("\n") && !it.contains("\r")) {
|
||||
"UserId cannot contain newlines and/or carriage returns."
|
||||
}
|
||||
}
|
||||
// I'm not sure, what kind of sanitization is needed.
|
||||
// Newlines are allowed, they just need to be escaped when emitted in an ASCII armor header
|
||||
// Trailing/Leading whitespace is also fine.
|
||||
userId.toString()
|
||||
|
||||
private fun callbackFromRevocationAttributes(attributes: RevocationAttributes?) =
|
||||
object : RevocationSignatureSubpackets.Callback {
|
||||
|
|
|
@ -247,7 +247,8 @@ class ArmorUtils {
|
|||
.add(OpenPgpFingerprint.of(publicKey).prettyPrint())
|
||||
// Primary / First User ID
|
||||
(primary ?: first)?.let {
|
||||
headerMap.getOrPut(HEADER_COMMENT) { mutableSetOf() }.add(it)
|
||||
headerMap.getOrPut(HEADER_COMMENT) { mutableSetOf() }
|
||||
.add(it.replace("\n", "\\n").replace("\r", "\\r"))
|
||||
}
|
||||
// X-1 further identities
|
||||
when (userIds.size) {
|
||||
|
|
|
@ -11,14 +11,9 @@ import org.bouncycastle.util.Arrays
|
|||
*
|
||||
* @param chars may be null for empty passwords.
|
||||
*/
|
||||
class Passphrase(chars: CharArray?) {
|
||||
class Passphrase(private val chars: CharArray?) {
|
||||
private val lock = Any()
|
||||
private var valid = true
|
||||
private val chars: CharArray?
|
||||
|
||||
init {
|
||||
this.chars = chars;//trimWhitespace(chars)
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a copy of the underlying char array. A return value of null represents an empty
|
||||
|
@ -67,6 +62,11 @@ class Passphrase(chars: CharArray?) {
|
|||
|
||||
override fun hashCode(): Int = getChars()?.let { String(it) }.hashCode()
|
||||
|
||||
/**
|
||||
* Return a copy of this [Passphrase], but with whitespace characters trimmed off.
|
||||
*
|
||||
* @return copy with trimmed whitespace
|
||||
*/
|
||||
fun withTrimmedWhitespace(): Passphrase = Passphrase(trimWhitespace(chars))
|
||||
|
||||
companion object {
|
||||
|
|
|
@ -100,4 +100,14 @@ public class GenerateKeyTest {
|
|||
assertThrows(SOPGPException.UnsupportedProfile.class, () ->
|
||||
sop.generateKey().profile("invalid"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generateKeyWithNewlinesInUserId() throws IOException {
|
||||
byte[] keyBytes = sop.generateKey()
|
||||
.userId("Foo\n\nBar")
|
||||
.generate()
|
||||
.getBytes();
|
||||
|
||||
assertTrue(new String(keyBytes).contains("Foo\\n\\nBar"));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue