Skip to content

Commit 1df4720

Browse files
committed
[PEM] Don't fail on PemDocument.decodeToSequence in case of no PEM documents found in the input
1 parent a4fa544 commit 1df4720

File tree

1 file changed

+0
-5
lines changed

1 file changed

+0
-5
lines changed

cryptography-serialization/pem/src/commonMain/kotlin/PemDocument.kt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ public class PemDocument(
6060
while (startIndex < text.length) {
6161
yield(tryDecodeFromString(text, startIndex) { startIndex = it } ?: break)
6262
}
63-
if (startIndex == 0) throwPemMissingBeginLabel()
6463
}
6564

6665
@OptIn(UnsafeByteStringApi::class)
@@ -82,20 +81,16 @@ public class PemDocument(
8281
while (startIndex < bytes.size) {
8382
yield(tryDecodeFromByteString(bytes, startIndex) { startIndex = it } ?: break)
8483
}
85-
if (startIndex == 0) throwPemMissingBeginLabel()
8684
}
8785

8886
public fun decode(source: Source): PemDocument {
8987
return tryDecodeFromSource(source) ?: throwPemMissingBeginLabel()
9088
}
9189

9290
public fun decodeToSequence(source: Source): Sequence<PemDocument> = sequence {
93-
var hasAtLeastOneBeginLabel = false
9491
while (!source.exhausted()) {
9592
yield(tryDecodeFromSource(source) ?: break)
96-
hasAtLeastOneBeginLabel = true
9793
}
98-
if (!hasAtLeastOneBeginLabel) throwPemMissingBeginLabel()
9994
}
10095
}
10196
}

0 commit comments

Comments
 (0)