mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-09-14 12:49:39 +02:00
Compare commits
16 commits
7daa3783bc
...
880b0720db
Author | SHA1 | Date | |
---|---|---|---|
880b0720db | |||
8f41fb0f27 | |||
5939b747b0 | |||
adf9fc4639 | |||
9df5060bab | |||
fef620d18b | |||
42e6bb483f | |||
1560980c7e | |||
cefdfa8eac | |||
ae9c702b29 | |||
4c2e60bb92 | |||
599c689c2e | |||
556766e0bf | |||
343fc6cf65 | |||
fa0d515c35 | |||
453b190f58 |
5 changed files with 15 additions and 22 deletions
|
@ -45,6 +45,9 @@ class KeyRingBuilder : KeyRingBuilderInterface<KeyRingBuilder> {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun addUserId(userId: CharSequence): KeyRingBuilder = apply {
|
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
|
userIds[userId.toString()] = null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -569,10 +569,11 @@ class SecretKeyRingEditor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun sanitizeUserId(userId: CharSequence): CharSequence =
|
private fun sanitizeUserId(userId: CharSequence): CharSequence =
|
||||||
// I'm not sure, what kind of sanitization is needed.
|
userId.toString().also {
|
||||||
// Newlines are allowed, they just need to be escaped when emitted in an ASCII armor header
|
require(!it.contains("\n") && !it.contains("\r")) {
|
||||||
// Trailing/Leading whitespace is also fine.
|
"UserId cannot contain newlines and/or carriage returns."
|
||||||
userId.toString()
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun callbackFromRevocationAttributes(attributes: RevocationAttributes?) =
|
private fun callbackFromRevocationAttributes(attributes: RevocationAttributes?) =
|
||||||
object : RevocationSignatureSubpackets.Callback {
|
object : RevocationSignatureSubpackets.Callback {
|
||||||
|
|
|
@ -247,8 +247,7 @@ class ArmorUtils {
|
||||||
.add(OpenPgpFingerprint.of(publicKey).prettyPrint())
|
.add(OpenPgpFingerprint.of(publicKey).prettyPrint())
|
||||||
// Primary / First User ID
|
// Primary / First User ID
|
||||||
(primary ?: first)?.let {
|
(primary ?: first)?.let {
|
||||||
headerMap.getOrPut(HEADER_COMMENT) { mutableSetOf() }
|
headerMap.getOrPut(HEADER_COMMENT) { mutableSetOf() }.add(it)
|
||||||
.add(it.replace("\n", "\\n").replace("\r", "\\r"))
|
|
||||||
}
|
}
|
||||||
// X-1 further identities
|
// X-1 further identities
|
||||||
when (userIds.size) {
|
when (userIds.size) {
|
||||||
|
|
|
@ -11,9 +11,14 @@ import org.bouncycastle.util.Arrays
|
||||||
*
|
*
|
||||||
* @param chars may be null for empty passwords.
|
* @param chars may be null for empty passwords.
|
||||||
*/
|
*/
|
||||||
class Passphrase(private val chars: CharArray?) {
|
class Passphrase(chars: CharArray?) {
|
||||||
private val lock = Any()
|
private val lock = Any()
|
||||||
private var valid = true
|
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
|
* Return a copy of the underlying char array. A return value of null represents an empty
|
||||||
|
@ -62,11 +67,6 @@ class Passphrase(private val chars: CharArray?) {
|
||||||
|
|
||||||
override fun hashCode(): Int = getChars()?.let { String(it) }.hashCode()
|
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))
|
fun withTrimmedWhitespace(): Passphrase = Passphrase(trimWhitespace(chars))
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
|
@ -100,14 +100,4 @@ public class GenerateKeyTest {
|
||||||
assertThrows(SOPGPException.UnsupportedProfile.class, () ->
|
assertThrows(SOPGPException.UnsupportedProfile.class, () ->
|
||||||
sop.generateKey().profile("invalid"));
|
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