Skip to content

Commit 5dba130

Browse files
committed
Add tests for PEM strings with CRLF line breaks
1 parent 7aa7ab1 commit 5dba130

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

CloudFrontMiddlewareTests/RSAUtilsTests.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,34 @@ struct RSAUtilsTests {
1515
#expect(keyData != nil)
1616
}
1717

18+
/// Tests that we can extract private key data from a PEM string containing an RSA PRIVATE KEY (PKCS#1)
19+
/// where the string line breaks are CRLF (typical Windows line breaks)
20+
@Test func getRSAPrivateKeyDataFromPEMwithCRLFendings() {
21+
// change the line endings to CRLFs
22+
let pemString = RSA_PRIVATE_KEY_STRING
23+
.split(separator: "\n")
24+
.joined(separator: "\r\n")
25+
let keyData = privateKeyDataFromPEM(pemString)
26+
#expect(keyData != nil)
27+
}
28+
1829
/// Tests that we can extract private key data from a PEM string containing a PRIVATE KEY (PKCS#8)
1930
@Test func getPKCS8PrivateKeyDataFromPEM() {
2031
let keyData = privateKeyDataFromPEM(PRIVATE_KEY_STRING)
2132
#expect(keyData != nil)
2233
}
2334

35+
/// Tests that we can extract private key data from a PEM string containing an PRIVATE KEY (PKCS#8)
36+
/// where the string line breaks are CRLF (typical Windows line breaks)
37+
@Test func getPKCS8PrivateKeyDataFromPEMwithCRLFendings() {
38+
// change the line endings to CRLFs
39+
let pemString = PRIVATE_KEY_STRING
40+
.split(separator: "\n")
41+
.joined(separator: "\r\n")
42+
let keyData = privateKeyDataFromPEM(pemString)
43+
#expect(keyData != nil)
44+
}
45+
2446
/// Tests that we can load a private key from RSA (PKCS#1) data
2547
@Test func privateKeyfromRSADataIsNotNil() throws {
2648
let keyData = privateKeyDataFromPEM(RSA_PRIVATE_KEY_STRING)

0 commit comments

Comments
 (0)