Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Ignore newline differences

  • Loading branch information...
commit cfa448de581fdf74e3365db134ea974906e1ce85 1 parent 64527de
@SLaks SLaks authored
Showing with 20 additions and 8 deletions.
  1. +1 −1  lib/ursa.js
  2. +9 −3 test/native.js
  3. +10 −4 test/test.js
View
2  lib/ursa.js
@@ -44,7 +44,7 @@ var MD5 = "md5";
/** regex that matches PEM files, capturing the file type */
var PEM_REGEX =
- /^(-----BEGIN (.*) KEY-----\n[\/+=a-zA-Z0-9\n]*\n-----END \2 KEY-----\n)/m;
+ /^(-----BEGIN (.*) KEY-----\r?\n[\/+=a-zA-Z0-9\r\n]*\r?\n-----END \2 KEY-----\r?\n)/m;
/** "unsealer" key object to authenticate objects */
var theUnsealer = [ "ursa unsealer" ];
View
12 test/native.js
@@ -17,6 +17,12 @@ var RsaWrap = fixture.RsaWrap;
var ursaNative = fixture.ursaNative;
var textToNid = ursaNative.textToNid;
+/**
+ * Asserts that two strings are equal, ignoring Windows newline differences
+ */
+function assertStringEqual(actual, expected, message) {
+ assert.equal(actual.replace(/\r\n/g, '\n'), expected.replace(/\r\n/g, '\n'), message);
+}
/*
* Test functions
@@ -156,7 +162,7 @@ function test_getPrivateKeyPem() {
rsa.setPrivateKeyPem(fixture.PRIVATE_KEY);
var pem = rsa.getPrivateKeyPem().toString(fixture.UTF8);
- assert.equal(pem, keyStr);
+ assertStringEqual(pem, keyStr);
}
function test_fail_getPrivateKeyPem() {
@@ -177,12 +183,12 @@ function test_getPublicKeyPem() {
var rsa = new RsaWrap();
rsa.setPublicKeyPem(fixture.PUBLIC_KEY);
var pem = rsa.getPublicKeyPem().toString(fixture.UTF8);
- assert.equal(pem, keyStr);
+ assertStringEqual(pem, keyStr);
rsa = new RsaWrap();
rsa.setPrivateKeyPem(fixture.PRIVATE_KEY);
pem = rsa.getPublicKeyPem().toString(fixture.UTF8);
- assert.equal(pem, keyStr);
+ assertStringEqual(pem, keyStr);
}
function test_fail_getPublicKeyPem() {
View
14 test/test.js
@@ -15,6 +15,12 @@ var assert = require("assert");
var fixture = require("./fixture");
var ursa = fixture.ursa;
+/**
+ * Asserts that two strings are equal, ignoring Windows newline differences
+ */
+function assertStringEqual(actual, expected, message) {
+ assert.equal(actual.replace(/\r\n/g, '\n'), expected.replace(/\r\n/g, '\n'), message);
+}
/*
* Helper functions
@@ -57,10 +63,10 @@ function test_getModulus(key) {
function test_toPublicPem(key) {
var keyString = fixture.PUBLIC_KEY.toString(fixture.UTF8);
var result = key.toPublicPem().toString(fixture.UTF8);
- assert.equal(result, keyString);
+ assertStringEqual(result, keyString);
result = key.toPublicPem(fixture.UTF8);
- assert.equal(result, keyString);
+ assertStringEqual(result, keyString);
}
function test_toPublicSsh(key) {
@@ -139,10 +145,10 @@ function testPublicKeyMethods(key) {
function test_toPrivatePem(key) {
var keyString = fixture.PRIVATE_KEY.toString(fixture.UTF8);
var result = key.toPrivatePem().toString(fixture.UTF8);
- assert.equal(result, keyString);
+ assertStringEqual(result, keyString);
result = key.toPrivatePem(fixture.UTF8);
- assert.equal(result, keyString);
+ assertStringEqual(result, keyString);
}
function test_decrypt(key) {
Please sign in to comment.
Something went wrong with that request. Please try again.