Skip to content

Commit eb8bc22

Browse files
authored
Fix PKCS#1/PKCS#8 line endings on Windows (#181)
The checked-in files use Unix-style line endings, so use `LineEnding::LF` in tests, rather than `Default::default` (which uses OS-specific line endings. Also adds a `.gitattributes` file which specifies these files should always be checked out with `eol=lf`.
1 parent 2ffd3ae commit eb8bc22

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
tests/examples/pkcs1/*.pem text eol=lf
2+
tests/examples/pkcs8/*.pem text eol=lf

tests/pkcs1.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ use rsa::{
66
PublicKeyParts, RsaPrivateKey, RsaPublicKey,
77
};
88

9+
#[cfg(feature = "pem")]
10+
use rsa::pkcs1::LineEnding;
11+
912
/// RSA-2048 PKCS#1 private key encoded as ASN.1 DER.
1013
///
1114
/// Note: this key is extracted from the corresponding `rsa2048-priv.der`
@@ -168,30 +171,30 @@ fn decode_rsa4096_pub_pem() {
168171
#[cfg(feature = "pem")]
169172
fn encode_rsa2048_priv_pem() {
170173
let key = RsaPrivateKey::from_pkcs1_pem(RSA_2048_PRIV_PEM).unwrap();
171-
let pem = key.to_pkcs1_pem(Default::default()).unwrap();
174+
let pem = key.to_pkcs1_pem(LineEnding::LF).unwrap();
172175
assert_eq!(&*pem, RSA_2048_PRIV_PEM)
173176
}
174177

175178
#[test]
176179
#[cfg(feature = "pem")]
177180
fn encode_rsa4096_priv_pem() {
178181
let key = RsaPrivateKey::from_pkcs1_pem(RSA_4096_PRIV_PEM).unwrap();
179-
let pem = key.to_pkcs1_pem(Default::default()).unwrap();
182+
let pem = key.to_pkcs1_pem(LineEnding::LF).unwrap();
180183
assert_eq!(&*pem, RSA_4096_PRIV_PEM)
181184
}
182185

183186
#[test]
184187
#[cfg(feature = "pem")]
185188
fn encode_rsa2048_pub_pem() {
186189
let key = RsaPublicKey::from_pkcs1_pem(RSA_2048_PUB_PEM).unwrap();
187-
let pem = key.to_pkcs1_pem(Default::default()).unwrap();
190+
let pem = key.to_pkcs1_pem(LineEnding::LF).unwrap();
188191
assert_eq!(&*pem, RSA_2048_PUB_PEM)
189192
}
190193

191194
#[test]
192195
#[cfg(feature = "pem")]
193196
fn encode_rsa4096_pub_pem() {
194197
let key = RsaPublicKey::from_pkcs1_pem(RSA_4096_PUB_PEM).unwrap();
195-
let pem = key.to_pkcs1_pem(Default::default()).unwrap();
198+
let pem = key.to_pkcs1_pem(LineEnding::LF).unwrap();
196199
assert_eq!(&*pem, RSA_4096_PUB_PEM)
197200
}

tests/pkcs8.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ use rsa::{
2020
PublicKeyParts, RsaPrivateKey, RsaPublicKey,
2121
};
2222

23+
#[cfg(feature = "pem")]
24+
use rsa::pkcs8::LineEnding;
25+
2326
#[test]
2427
fn decode_rsa2048_priv_der() {
2528
let key = RsaPrivateKey::from_pkcs8_der(RSA_2048_PRIV_DER).unwrap();
@@ -82,14 +85,14 @@ fn decode_rsa2048_pub_pem() {
8285
#[cfg(feature = "pem")]
8386
fn encode_rsa2048_priv_pem() {
8487
let key = RsaPrivateKey::from_pkcs8_pem(RSA_2048_PRIV_PEM).unwrap();
85-
let pem = key.to_pkcs8_pem(Default::default()).unwrap();
88+
let pem = key.to_pkcs8_pem(LineEnding::LF).unwrap();
8689
assert_eq!(&*pem, RSA_2048_PRIV_PEM)
8790
}
8891

8992
#[test]
9093
#[cfg(feature = "pem")]
9194
fn encode_rsa2048_pub_pem() {
9295
let key = RsaPublicKey::from_public_key_pem(RSA_2048_PUB_PEM).unwrap();
93-
let pem = key.to_public_key_pem(Default::default()).unwrap();
96+
let pem = key.to_public_key_pem(LineEnding::LF).unwrap();
9497
assert_eq!(&*pem, RSA_2048_PUB_PEM)
9598
}

0 commit comments

Comments
 (0)